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:
alert('Common.js carregado!');
// /navi clicável para spans gerados por {{Navi|map|x|y}}
mw.loader.using('mediawiki.util').then(function () {
    document.addEventListener('click', function (e) {
        var el = e.target.closest('.navi-copy');
        if (!el) return;


document.addEventListener('click', function (e) {
        // pega dados do span
    var el = e.target.closest('.navi-copy');
        var map = el.getAttribute('data-map');
    if (!el) return;
        var x  = el.getAttribute('data-x');
        var y  = el.getAttribute('data-y');


    alert('Você clicou no Navi: ' + el.textContent);
        var text = '/navi ' + map + ' ' + x + ' ' + y;
 
        // tentativa moderna
        if (navigator.clipboard && navigator.clipboard.writeText) {
            navigator.clipboard.writeText(text).then(function () {
                mw.notify('Comando copiado: ' + text);
            }, function () {
                alert('Comando: ' + text);
            });
        } else {
            // fallback antigo
            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);
        }
    });
});
});

Edição das 11h24min de 6 de novembro de 2025

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

        // pega dados do span
        var map = el.getAttribute('data-map');
        var x   = el.getAttribute('data-x');
        var y   = el.getAttribute('data-y');

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

        // tentativa moderna
        if (navigator.clipboard && navigator.clipboard.writeText) {
            navigator.clipboard.writeText(text).then(function () {
                mw.notify('Comando copiado: ' + text);
            }, function () {
                alert('Comando: ' + text);
            });
        } else {
            // fallback antigo
            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);
        }
    });
});