Zum Inhalt springen

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

Aus Home Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
// Copy-Button für <pre> Blöcke
mw.loader.using(['mediawiki.util']).then(function () {
mw.loader.using(['mediawiki.util']).then(function () {


     document.querySelectorAll('pre').forEach(function (block) {
     document.querySelectorAll('pre, .mw-highlight pre').forEach(function (block) {


         var button = document.createElement('button');
         var button = document.createElement('button');
         button.textContent = 'Kopieren';
         button.textContent = 'Kopieren';
         button.style.marginBottom = '5px';
         button.style.float = 'right';
        button.style.margin = '4px';
         button.style.cursor = 'pointer';
         button.style.cursor = 'pointer';


         button.addEventListener('click', function () {
         button.addEventListener('click', function () {
             navigator.clipboard.writeText(block.innerText).then(function () {
             navigator.clipboard.writeText(block.innerText).then(function () {
                 button.textContent = '✓ Kopiert!';
                 button.textContent = '✓';
                 setTimeout(function () {
                 setTimeout(function () {
                     button.textContent = 'Kopieren';
                     button.textContent = 'Kopieren';
Zeile 18: Zeile 18:
         });
         });


        block.style.position = 'relative';
         block.parentNode.insertBefore(button, block);
         block.parentNode.insertBefore(button, block);
     });
     });


});
});

Version vom 13. Februar 2026, 22:23 Uhr

mw.loader.using(['mediawiki.util']).then(function () {

    document.querySelectorAll('pre, .mw-highlight pre').forEach(function (block) {

        var button = document.createElement('button');
        button.textContent = 'Kopieren';
        button.style.float = 'right';
        button.style.margin = '4px';
        button.style.cursor = 'pointer';

        button.addEventListener('click', function () {
            navigator.clipboard.writeText(block.innerText).then(function () {
                button.textContent = '✓';
                setTimeout(function () {
                    button.textContent = 'Kopieren';
                }, 2000);
            });
        });

        block.style.position = 'relative';
        block.parentNode.insertBefore(button, block);
    });

});