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

De PokeRO Revive
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
Linha 1: Linha 1:
document.addEventListener("mouseover", function(e) {
document.addEventListener("DOMContentLoaded", function () {
    if (!e.target.classList.contains("itemdef")) return;


     var id = e.target.getAttribute("data-item");
     var API = "http://game.pkro.com.br:3232";


     var db = {
     function roColorToHtml(text) {
         601: {
         return text
             name: "Pokebola",
             .replace(/\^([0-9A-Fa-f]{6})/g, '<span style="color:#$1">')
             desc: "Pokebola de usar"
             .replace(/\n/g, "<br>") + "</span>";
        }
     }
     };


     var item = db[id];
     document.querySelectorAll(".mw-item").forEach(function (el) {
    if (!item) return;


    var tooltip = document.createElement("div");
        var id = el.dataset.id;
    tooltip.className = "item-tooltip";
    tooltip.innerHTML =
        "<b>" + item.name + "</b><br>" +
        item.desc;


    document.body.appendChild(tooltip);
        fetch(API + "/item/" + id)
            .then(function (r) { return r.json(); })
            .then(function (item) {


    var move = function(ev) {
                // troca texto por ícone
        tooltip.style.left = (ev.pageX + 15) + "px";
                el.innerHTML = '<img src="' + API + item.icon + '" width="32">';
        tooltip.style.top = (ev.pageY + 15) + "px";
    };


    document.addEventListener("mousemove", move);
                el.addEventListener("mouseenter", function () {
 
                    var tip = document.createElement("div");
                    tip.className = "item-tooltip";
 
                    tip.innerHTML =
                        '<div style="display:flex; gap:10px;">' +
                        '<img src="' + API + item.icon + '" width="42">' +
                        '<div>' +
                        '<b>' + item.name + '</b><br>' +
                        roColorToHtml(item.description) +
                        '</div>' +
                        '</div>';
 
                    document.body.appendChild(tip);
 
                    var move = function (ev) {
                        tip.style.left = (ev.pageX + 15) + "px";
                        tip.style.top = (ev.pageY + 15) + "px";
                    };
 
                    document.addEventListener("mousemove", move);
 
                    el.addEventListener("mouseleave", function () {
                        tip.remove();
                        document.removeEventListener("mousemove", move);
                    }, { once: true });
 
                });
 
            })
            .catch(function () {
                el.innerHTML = "[item erro]";
            });
 
    });


    e.target.addEventListener("mouseout", function() {
        tooltip.remove();
        document.removeEventListener("mousemove", move);
    }, { once: true });
});
});

Edição das 21h31min de 2 de fevereiro de 2026

document.addEventListener("DOMContentLoaded", function () {

    var API = "http://game.pkro.com.br:3232";

    function roColorToHtml(text) {
        return text
            .replace(/\^([0-9A-Fa-f]{6})/g, '<span style="color:#$1">')
            .replace(/\n/g, "<br>") + "</span>";
    }

    document.querySelectorAll(".mw-item").forEach(function (el) {

        var id = el.dataset.id;

        fetch(API + "/item/" + id)
            .then(function (r) { return r.json(); })
            .then(function (item) {

                // troca texto por ícone
                el.innerHTML = '<img src="' + API + item.icon + '" width="32">';

                el.addEventListener("mouseenter", function () {

                    var tip = document.createElement("div");
                    tip.className = "item-tooltip";

                    tip.innerHTML =
                        '<div style="display:flex; gap:10px;">' +
                        '<img src="' + API + item.icon + '" width="42">' +
                        '<div>' +
                        '<b>' + item.name + '</b><br>' +
                        roColorToHtml(item.description) +
                        '</div>' +
                        '</div>';

                    document.body.appendChild(tip);

                    var move = function (ev) {
                        tip.style.left = (ev.pageX + 15) + "px";
                        tip.style.top = (ev.pageY + 15) + "px";
                    };

                    document.addEventListener("mousemove", move);

                    el.addEventListener("mouseleave", function () {
                        tip.remove();
                        document.removeEventListener("mousemove", move);
                    }, { once: true });

                });

            })
            .catch(function () {
                el.innerHTML = "[item erro]";
            });

    });

});