MediaWiki:Iso2709.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
Linha 3: | Linha 3: | ||
// Função que gera o arquivo ISO |
// Função que gera o arquivo ISO |
||
function download(filename, content) { |
function download(filename, content) { |
||
const element = document.createElement('a'); |
|||
element.setAttribute( |
element.setAttribute( |
||
'href', |
|||
`data:application/marc;charset=utf-8,${encodeURIComponent(content)}`, |
|||
⚫ | |||
); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
document.body.appendChild(element); |
document.body.appendChild(element); |
||
element.click(); |
element.click(); |
||
Linha 14: | Linha 16: | ||
// Se tiver uma div "isoFormat" na página/documento, |
// Se tiver uma div "isoFormat" na página/documento, |
||
// substititua os caracteres abaixo |
// substititua os caracteres abaixo |
||
const isoFormat = document.getElementById('isoFormat'); |
|||
if (isoFormat) { |
if (isoFormat) { |
||
isoFormat.innerHTML = |
isoFormat.innerHTML = isoFormat.innerHTML.replace( |
||
/\u241D/g, |
|||
String.fromCharCode(29), |
|||
⚫ | |||
); // GS |
|||
isoFormat.innerHTML.replace(/\u241E/g, String.fromCharCode(30)); // RS |
|||
isoFormat.innerHTML = |
isoFormat.innerHTML = isoFormat.innerHTML.replace( |
||
/\u241E/g, |
|||
isoFormat.innerHTML.replace(/\u241F/g, String.fromCharCode(31)); // US |
|||
String.fromCharCode(30), |
|||
⚫ | |||
); // RS |
|||
isoFormat.innerHTML.replace(/ /g, String.fromCharCode(32)); // &NonBreakingSpace |
|||
⚫ | |||
/\u241F/g, |
|||
String.fromCharCode(31), |
|||
); // US |
|||
⚫ | |||
/ /g, |
|||
String.fromCharCode(32), |
|||
); // &NonBreakingSpace |
|||
const content = isoFormat.textContent; |
const content = isoFormat.textContent; |
||
const filename = document.URL.slice(-7) |
const filename = `${document.URL.slice(-7)}.mrc`; |
||
// Ao clicar no botão "downloadButton", chama a função download() abaixo |
// Ao clicar no botão "downloadButton", chama a função download() abaixo |
||
document |
|||
.getElementById('downloadButton') |
|||
() => download(filename, content), false); |
.addEventListener('click', () => download(filename, content), false); |
||
} |
} |
||
})(); |
})(); |
Edição atual tal como às 13h25min de 18 de março de 2024
/* jshint esversion: 10 */
(function () {
// Função que gera o arquivo ISO
function download(filename, content) {
const element = document.createElement('a');
element.setAttribute(
'href',
`data:application/marc;charset=utf-8,${encodeURIComponent(content)}`,
);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// Se tiver uma div "isoFormat" na página/documento,
// substititua os caracteres abaixo
const isoFormat = document.getElementById('isoFormat');
if (isoFormat) {
isoFormat.innerHTML = isoFormat.innerHTML.replace(
/\u241D/g,
String.fromCharCode(29),
); // GS
isoFormat.innerHTML = isoFormat.innerHTML.replace(
/\u241E/g,
String.fromCharCode(30),
); // RS
isoFormat.innerHTML = isoFormat.innerHTML.replace(
/\u241F/g,
String.fromCharCode(31),
); // US
isoFormat.innerHTML = isoFormat.innerHTML.replace(
/ /g,
String.fromCharCode(32),
); // &NonBreakingSpace
const content = isoFormat.textContent;
const filename = `${document.URL.slice(-7)}.mrc`;
// Ao clicar no botão "downloadButton", chama a função download() abaixo
document
.getElementById('downloadButton')
.addEventListener('click', () => download(filename, content), false);
}
})();