MediaWiki:Gadget-MyCoolGadget.js: Unterschied zwischen den Versionen
Erscheinungsbild
Saya (Diskussion | Beiträge) Der Seiteninhalt wurde durch einen anderen Text ersetzt: „alert("Gadget läuft!");“ Markierung: Ersetzt |
Saya (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
mw.loader.using(['mediawiki.util']).then(function () { | |||
function addCopyButtons() { | |||
document.querySelectorAll('pre, .mw-highlight pre').forEach(function (block) { | |||
// Nicht doppelt hinzufügen | |||
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 () { | |||
navigator.clipboard.writeText(block.innerText).then(() => { | |||
btn.textContent = "✅ Kopiert!"; | |||
setTimeout(() => btn.textContent = "📋 Kopieren", 1500); | |||
}); | |||
}; | |||
block.parentNode.insertBefore(btn, block); | |||
}); | |||
} | |||
// Beim Laden | |||
addCopyButtons(); | |||
// Auch nach AJAX / Seitenwechsel (Vector 2022 wichtig!) | |||
mw.hook('wikipage.content').add(addCopyButtons); | |||
}); | |||
Version vom 14. Februar 2026, 10:41 Uhr
mw.loader.using(['mediawiki.util']).then(function () {
function addCopyButtons() {
document.querySelectorAll('pre, .mw-highlight pre').forEach(function (block) {
// Nicht doppelt hinzufügen
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 () {
navigator.clipboard.writeText(block.innerText).then(() => {
btn.textContent = "✅ Kopiert!";
setTimeout(() => btn.textContent = "📋 Kopieren", 1500);
});
};
block.parentNode.insertBefore(btn, block);
});
}
// Beim Laden
addCopyButtons();
// Auch nach AJAX / Seitenwechsel (Vector 2022 wichtig!)
mw.hook('wikipage.content').add(addCopyButtons);
});