Jump to content

MediaWiki:Common.js: Difference between revisions

From EthernalRO Wiki
Created page with "Any JavaScript here will be loaded for all users on every page load.: function copiarNavi(mapa, y, x) { const texto = `/navi ${mapa},${y},${x}`; if (navigator.clipboard) { navigator.clipboard.writeText(texto).then(() => { mw.notify(`Copiado: ${texto}`); }); } else { // fallback antigo const temp = document.createElement("textarea"); temp.value = texto; document.body.appendChild(temp); t..."
 
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
// Copiar /navi mapa,x,y pro clipboard
function copiarNavi(mapa, y, x) {
function naviCopy(map, x, y) {
     const texto = `/navi ${mapa},${y},${x}`;
     const text = "/navi " + map + "," + x + "," + y;


     if (navigator.clipboard) {
    // tenta API Clipboard
         navigator.clipboard.writeText(texto).then(() => {
     if (navigator.clipboard && window.isSecureContext) {
             mw.notify(`Copiado: ${texto}`);
         navigator.clipboard.writeText(text).then(function() {
             mw.notify("Copiado: " + text);
         });
         });
     } else {
     } else {
         // fallback antigo
         // fallback
         const temp = document.createElement("textarea");
         const ta = document.createElement("textarea");
         temp.value = texto;
         ta.value = text;
         document.body.appendChild(temp);
         document.body.appendChild(ta);
         temp.select();
         ta.select();
         document.execCommand("copy");
         document.execCommand("copy");
         document.body.removeChild(temp);
         document.body.removeChild(ta);
         mw.notify(`Copiado: ${texto}`);
         mw.notify("Copiado: " + text);
     }
     }
}
}

Revision as of 14:52, 26 January 2026

// Copiar /navi mapa,x,y pro clipboard
function naviCopy(map, x, y) {
    const text = "/navi " + map + "," + x + "," + y;

    // tenta API Clipboard
    if (navigator.clipboard && window.isSecureContext) {
        navigator.clipboard.writeText(text).then(function() {
            mw.notify("Copiado: " + text);
        });
    } else {
        // fallback
        const ta = document.createElement("textarea");
        ta.value = text;
        document.body.appendChild(ta);
        ta.select();
        document.execCommand("copy");
        document.body.removeChild(ta);
        mw.notify("Copiado: " + text);
    }
}