Zum Inhalt springen

MediaWiki:Gadget-MyCoolGadget.js: Unterschied zwischen den Versionen

Aus Home Wiki
Der Seiteninhalt wurde durch einen anderen Text ersetzt: „alert("Gadget läuft!");“
Markierung: Ersetzt
Keine Bearbeitungszusammenfassung
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 1: Zeile 1:
alert("Gadget läuft!");
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);
});

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);
});