MediaWiki:Iso2709.js
Nota: Após publicar, você pode ter que limpar o "cache" do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Internet Explorer/Edge: PressioneCtrl enquanto clica Recarregar, ou Pressione Ctrl-F5
- Opera: Pressione Ctrl-F5.
/* jshint esversion: 10 */
(function () {
// Função que gera o arquivo ISO
function download(filename, content) {
let 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
let 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);
}
})();