MediaWiki:Common.js: mudanças entre as edições

De Grimopedia
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
Linha 1: Linha 1:
// Navi clicável - formato igual ao bROWiki: <div class="navi-copy"><span>mapa</span><span>x</span><span>y</span></div>
// Navi clicável: {{Navi|mapa|x|y}} -> copia /navi mapa x y
mw.loader.using('mediawiki.util').then(function () {
mw.loader.using('mediawiki.util').then(function () {
    document.addEventListener('click', function (e) {
        var el = e.target.closest('.navi-copy');
        if (!el) return;


    function copiarTexto(text) {
         var map = el.getAttribute('data-map');
         if (navigator.clipboard && navigator.clipboard.writeText) {
         var = el.getAttribute('data-x');
            return navigator.clipboard.writeText(text);
        var y  = el.getAttribute('data-y');
         }
        // fallback antigo
        return new Promise(function (resolve, reject) {
            try {
                var temp = document.createElement('textarea');
                temp.value = text;
                document.body.appendChild(temp);
                temp.select();
                document.execCommand('copy');
                document.body.removeChild(temp);
                resolve();
            } catch (e) {
                reject(e);
            }
        });
    }


    function montarNavi(div) {
         var text = '/navi ' + map + ' ' + x + ' ' + y;
         var spans = div.getElementsByTagName('span');
        if (spans.length < 3) return;


         var mapa = spans[0].textContent.trim();
         if (navigator.clipboard && navigator.clipboard.writeText) {
         var x    = spans[1].textContent.trim();
            navigator.clipboard.writeText(text).then(function () {
        var y    = spans[2].textContent.trim();
                mw.notify('Comando copiado: ' + text);
 
            }, function () {
        // Limpa conteúdo original
                alert('Comando: ' + text);
        while (div.firstChild) {
            });
             div.removeChild(div.firstChild);
         } else {
            var temp = document.createElement('textarea');
            temp.value = text;
            document.body.appendChild(temp);
            temp.select();
            document.execCommand('copy');
             document.body.removeChild(temp);
            mw.notify('Comando copiado: ' + text);
         }
         }
 
     });
        // Texto clicável
        var texto = document.createElement('div');
        texto.className = 'navi-copy-text';
        texto.textContent = '(' + mapa + ' ' + x + ', ' + y + ')';
 
        // Mensagem "copiado"
        var aviso = document.createElement('div');
        aviso.className = 'navi-copied';
        aviso.textContent = 'Comando copiado!';
        aviso.style.display = 'none';
 
        div.appendChild(texto);
        div.appendChild(aviso);
 
        texto.addEventListener('click', function () {
            var cmd = '/navi ' + mapa + ' ' + x + ' ' + y;
 
            copiarTexto(cmd).then(function () {
                aviso.style.display = 'inline';
                setTimeout(function () {
                    aviso.style.display = 'none';
                }, 1500);
 
                if (mw && mw.notify) {
                    mw.notify('Comando copiado: ' + cmd);
                }
            }).catch(function () {
                alert('Comando: ' + cmd);
            });
        });
     }
 
    // Aplica em todos os .navi-copy da página
    document.querySelectorAll('.navi-copy').forEach(montarNavi);
});
});

Edição das 13h39min de 6 de novembro de 2025

// Navi clicável: {{Navi|mapa|x|y}} -> copia /navi mapa x y
mw.loader.using('mediawiki.util').then(function () {
    document.addEventListener('click', function (e) {
        var el = e.target.closest('.navi-copy');
        if (!el) return;

        var map = el.getAttribute('data-map');
        var x   = el.getAttribute('data-x');
        var y   = el.getAttribute('data-y');

        var text = '/navi ' + map + ' ' + x + ' ' + y;

        if (navigator.clipboard && navigator.clipboard.writeText) {
            navigator.clipboard.writeText(text).then(function () {
                mw.notify('Comando copiado: ' + text);
            }, function () {
                alert('Comando: ' + text);
            });
        } else {
            var temp = document.createElement('textarea');
            temp.value = text;
            document.body.appendChild(temp);
            temp.select();
            document.execCommand('copy');
            document.body.removeChild(temp);
            mw.notify('Comando copiado: ' + text);
        }
    });
});