MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
// | $(function () { | ||
// adiciona evento de clique em elementos com classe naviCopy | |||
document.querySelectorAll(".naviCopy").forEach(el => { | |||
el.addEventListener("click", function () { | |||
const mapa = el.getAttribute("data-mapa"); | |||
const x = el.getAttribute("data-x"); | |||
const y = el.getAttribute("data-y"); | |||
const text = "/navi " + mapa + "," + x + "," + y; | |||
// copiar para clipboard | |||
mw.notify("Copiado: " + text); | if (navigator.clipboard && window.isSecureContext) { | ||
navigator.clipboard.writeText(text).then(() => { | |||
mw.notify("Copiado: " + text); | |||
}); | |||
} else { | |||
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); | |||
} | |||
}); | }); | ||
} | }); | ||
}); | |||
Revision as of 14:55, 26 January 2026
$(function () {
// adiciona evento de clique em elementos com classe naviCopy
document.querySelectorAll(".naviCopy").forEach(el => {
el.addEventListener("click", function () {
const mapa = el.getAttribute("data-mapa");
const x = el.getAttribute("data-x");
const y = el.getAttribute("data-y");
const text = "/navi " + mapa + "," + x + "," + y;
// copiar para clipboard
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(() => {
mw.notify("Copiado: " + text);
});
} else {
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);
}
});
});
});