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
Etiqueta: Reversão manual
 
(11 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
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;
        var map = el.getAttribute('data-map');
        var x  = el.getAttribute('data-x');
        var y  = el.getAttribute('data-y');
        var text = '/navi ' + map + ' ' + x + ' ' + y;


    function copiarTexto(text) {
         if (navigator.clipboard && navigator.clipboard.writeText) {
         if (navigator.clipboard && navigator.clipboard.writeText) {
             return navigator.clipboard.writeText(text);
             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);
         }
         }
        // fallback antigo
    });
        return new Promise(function (resolve, reject) {
});
            try {
 
                var temp = document.createElement('textarea');
// ------------------------------------------------------------
                temp.value = text;
// Ícone automático para links do ItemDB do site
                document.body.appendChild(temp);
// - Procura links que contenham /information/itemdb/{id}
                temp.select();
// - Injeta um ícone (24x24) antes do texto do link
                document.execCommand('copy');
// - Usa imagens locais do site: /img/item/{id}.png
                document.body.removeChild(temp);
//  (se não existir, cai no unknown.png)
                resolve();
// ------------------------------------------------------------
             } catch (e) {
mw.loader.using('mediawiki.util').then(function () {
                reject(e);
 
            }
    function applyItemIcons(root) {
        });
        root = root || document;
    }
 
        // Pega todos os links para o ItemDB do site
        var links = root.querySelectorAll('a[href*="/information/itemdb/"]:not(.aur-item-link)');
 
        links.forEach(function (a) {
            // evita duplicar
             if (a.getAttribute('data-aur-noicon') === '1') return;


    function montarNavi(div) {
            if (a.dataset && a.dataset.aurItemIconApplied) return;
        var spans = div.getElementsByTagName('span');
        if (spans.length < 3) return;


        var mapa = spans[0].textContent.trim();
            // tenta extrair o ID do item
        var x    = spans[1].textContent.trim();
            var m = a.href.match(/\/information\/itemdb\/(\d+)/);
        var y    = spans[2].textContent.trim();
            if (!m) return;


        // Limpa conteúdo original
             var id = m[1];
        while (div.firstChild) {
             div.removeChild(div.firstChild);
        }


        // Texto clicável
            // marca como aplicado
        var texto = document.createElement('div');
            if (a.dataset) a.dataset.aurItemIconApplied = "1";
        texto.className = 'navi-copy-text';
        texto.textContent = '(' + mapa + ' ' + x + ', ' + y + ')';


        // Mensagem "copiado"
            // NÃO força layout aqui — deixa o Common.css controlar o estilo do "pill"
        var aviso = document.createElement('div');
            // Só garantimos que o ícone exista antes do texto.
        aviso.className = 'navi-copied';
            var icon = document.createElement("span");
        aviso.textContent = 'Comando copiado!';
            icon.style.width = "24px";
        aviso.style.display = 'none';
            icon.style.height = "24px";
            icon.style.flex = "0 0 24px";
            icon.style.display = "inline-block";
            icon.style.backgroundSize = "contain";
            icon.style.backgroundRepeat = "no-repeat";
            icon.style.borderRadius = "6px";
            icon.style.backgroundColor = "rgba(0,0,0,.04)";


        div.appendChild(texto);
            // tenta imagem real do item
        div.appendChild(aviso);
            var url = "https://grimopedia.com.br/img/item/" + id + ".png";
            var fallback = "https://grimopedia.com.br/img/item/unknown.png";


        texto.addEventListener('click', function () {
            icon.style.backgroundImage = "url('" + url + "')";
            var cmd = '/navi ' + mapa + ' ' + x + ' ' + y;


             copiarTexto(cmd).then(function () {
             // fallback se a imagem não existir
                aviso.style.display = 'inline';
            var test = new Image();
                setTimeout(function () {
            test.onload = function () {};
                    aviso.style.display = 'none';
            test.onerror = function () {
                }, 1500);
                icon.style.backgroundImage = "url('" + fallback + "')";
            };
            test.src = url;


                if (mw && mw.notify) {
            // injeta antes do texto do link
                    mw.notify('Comando copiado: ' + cmd);
             a.prepend(icon);
                }
             }).catch(function () {
                alert('Comando: ' + cmd);
            });
         });
         });
     }
     }


     // Aplica em todos os .navi-copy da página
     // aplica no carregamento
     document.querySelectorAll('.navi-copy').forEach(montarNavi);
    document.addEventListener("DOMContentLoaded", function () {
        applyItemIcons(document);
    });
 
     // aplica também quando conteúdo é carregado via ajax/VE
    if (mw && mw.hook) {
        mw.hook('wikipage.content').add(function ($content) {
            applyItemIcons($content[0] || document);
        });
    }
});
});

Edição atual tal como às 15h27min de 15 de julho de 2026

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

// ------------------------------------------------------------
// Ícone automático para links do ItemDB do site
// - Procura links que contenham /information/itemdb/{id}
// - Injeta um ícone (24x24) antes do texto do link
// - Usa imagens locais do site: /img/item/{id}.png
//   (se não existir, cai no unknown.png)
// ------------------------------------------------------------
mw.loader.using('mediawiki.util').then(function () {

    function applyItemIcons(root) {
        root = root || document;

        // Pega todos os links para o ItemDB do site
        var links = root.querySelectorAll('a[href*="/information/itemdb/"]:not(.aur-item-link)');

        links.forEach(function (a) {
            // evita duplicar
            if (a.getAttribute('data-aur-noicon') === '1') return;

            if (a.dataset && a.dataset.aurItemIconApplied) return;

            // tenta extrair o ID do item
            var m = a.href.match(/\/information\/itemdb\/(\d+)/);
            if (!m) return;

            var id = m[1];

            // marca como aplicado
            if (a.dataset) a.dataset.aurItemIconApplied = "1";

            // NÃO força layout aqui — deixa o Common.css controlar o estilo do "pill"
            // Só garantimos que o ícone exista antes do texto.
            var icon = document.createElement("span");
            icon.style.width = "24px";
            icon.style.height = "24px";
            icon.style.flex = "0 0 24px";
            icon.style.display = "inline-block";
            icon.style.backgroundSize = "contain";
            icon.style.backgroundRepeat = "no-repeat";
            icon.style.borderRadius = "6px";
            icon.style.backgroundColor = "rgba(0,0,0,.04)";

            // tenta imagem real do item
            var url = "https://grimopedia.com.br/img/item/" + id + ".png";
            var fallback = "https://grimopedia.com.br/img/item/unknown.png";

            icon.style.backgroundImage = "url('" + url + "')";

            // fallback se a imagem não existir
            var test = new Image();
            test.onload = function () {};
            test.onerror = function () {
                icon.style.backgroundImage = "url('" + fallback + "')";
            };
            test.src = url;

            // injeta antes do texto do link
            a.prepend(icon);
        });
    }

    // aplica no carregamento
    document.addEventListener("DOMContentLoaded", function () {
        applyItemIcons(document);
    });

    // aplica também quando conteúdo é carregado via ajax/VE
    if (mw && mw.hook) {
        mw.hook('wikipage.content').add(function ($content) {
            applyItemIcons($content[0] || document);
        });
    }
});