MediaWiki:Gadget-MyCoolGadget.js: Unterschied zwischen den Versionen
Erscheinungsbild
Saya (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Saya (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
mw.loader.using(['mediawiki.util']).then(function () { | mw.loader.using(['mediawiki.util']).then(function () { | ||
function copyText(text, btn) { | |||
// Versuch modernes Clipboard API | |||
if (navigator.clipboard && window.isSecureContext) { | |||
navigator.clipboard.writeText(text).then(success); | |||
return; | |||
} | |||
// Fallback (funktioniert über HTTP / LAN) | |||
const textarea = document.createElement("textarea"); | |||
textarea.value = text; | |||
document.body.appendChild(textarea); | |||
textarea.select(); | |||
document.execCommand("copy"); | |||
document.body.removeChild(textarea); | |||
success(); | |||
function success() { | |||
btn.textContent = "✅ Kopiert!"; | |||
setTimeout(() => btn.textContent = "📋 Kopieren", 1500); | |||
} | |||
} | |||
function addCopyButtons() { | function addCopyButtons() { | ||
| Zeile 5: | Zeile 28: | ||
document.querySelectorAll('pre, .mw-highlight pre').forEach(function (block) { | document.querySelectorAll('pre, .mw-highlight pre').forEach(function (block) { | ||
if (block.dataset.copyButtonAdded) return; | if (block.dataset.copyButtonAdded) return; | ||
block.dataset.copyButtonAdded = "true"; | block.dataset.copyButtonAdded = "true"; | ||
| Zeile 18: | Zeile 40: | ||
btn.onclick = function () { | btn.onclick = function () { | ||
copyText(block.innerText, btn); | |||
}; | }; | ||
| Zeile 28: | Zeile 47: | ||
} | } | ||
addCopyButtons(); | addCopyButtons(); | ||
mw.hook('wikipage.content').add(addCopyButtons); | mw.hook('wikipage.content').add(addCopyButtons); | ||
}); | }); | ||
Aktuelle Version vom 14. Februar 2026, 10:44 Uhr
mw.loader.using(['mediawiki.util']).then(function () {
function copyText(text, btn) {
// Versuch modernes Clipboard API
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(success);
return;
}
// Fallback (funktioniert über HTTP / LAN)
const textarea = document.createElement("textarea");
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
success();
function success() {
btn.textContent = "✅ Kopiert!";
setTimeout(() => btn.textContent = "📋 Kopieren", 1500);
}
}
function addCopyButtons() {
document.querySelectorAll('pre, .mw-highlight pre').forEach(function (block) {
if (block.dataset.copyButtonAdded) return;
block.dataset.copyButtonAdded = "true";
const btn = document.createElement("button");
btn.textContent = "📋 Kopieren";
btn.style.float = "right";
btn.style.margin = "4px";
btn.style.padding = "4px 8px";
btn.style.fontSize = "12px";
btn.style.cursor = "pointer";
btn.onclick = function () {
copyText(block.innerText, btn);
};
block.parentNode.insertBefore(btn, block);
});
}
addCopyButtons();
mw.hook('wikipage.content').add(addCopyButtons);
});