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
 
(8 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
document.addEventListener("mouseover", function(e) {
mw.hook("wikipage.content").add(function () {
    if (!e.target.classList.contains("itemdef")) return;


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


     var db = {
     function roColorToHtml(text) {
         601: {
        var html = "";
             name: "Pokebola",
        var colorStack = false;
            desc: "Uma espada forjada pelos deuses."
 
        var parts = text.split(/\^([0-9A-Fa-f]{6})/);
 
         for (var i = 0; i < parts.length; i++) {
             if (i % 2 === 1) {
                if (colorStack) html += "</span>";
                html += '<span style="color:#' + parts[i] + '">';
                colorStack = true;
            } else {
                html += parts[i];
            }
         }
         }
    };


     var item = db[id];
        if (colorStack) html += "</span>";
    if (!item) return;
 
        return html
            .replace(/\\n/g, "<br>")
            .replace(/\n/g, "<br>");
    }
 
 
     document.querySelectorAll(".mw-item").forEach(function (el) {
 
        if (el.dataset.loaded) return; // evita duplicar
        el.dataset.loaded = "1";
 
        var id = el.dataset.id;
 
        fetch(API + "/item/" + id)
            .then(function (r) { return r.json(); })
            .then(function (item) {
 
                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 class="row">' +
                        '<img class="icon" src="' + API + item.icon + '">' +
                        '<div class="title">' + item.name + '</div>' +
                        '</div>' +
                        '<div class="text">' +
                        roColorToHtml(item.description) +
                        '</div>';
 
                    document.body.appendChild(tip);
 
                    var move = function (ev) {
                        var x = ev.clientX + 20;
                        var y = ev.clientY + 20;
 
                        if (x + 280 > window.innerWidth)
                            x = ev.clientX - 300;
 
                        if (y + 120 > window.innerHeight)
                            y = ev.clientY - 140;
 
                        tip.style.left = x + "px";
                        tip.style.top = y + "px";
                    };
 
 
                    document.addEventListener("mousemove", move);


    var tooltip = document.createElement("div");
                    el.addEventListener("mouseleave", function () {
    tooltip.className = "item-tooltip";
                        tip.remove();
    tooltip.innerHTML =
                        document.removeEventListener("mousemove", move);
        "<b>" + item.name + "</b><br>" +
                    }, { once: true });
        item.desc;


    document.body.appendChild(tooltip);
                });


    var move = function(ev) {
            })
        tooltip.style.left = (ev.pageX + 15) + "px";
            .catch(function (err) {
        tooltip.style.top = (ev.pageY + 15) + "px";
                console.error("Item API erro:", err);
    };
                el.innerHTML = "[erro]";
            });


     document.addEventListener("mousemove", move);
     });


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

Edição atual tal como às 22h44min de 2 de fevereiro de 2026

mw.hook("wikipage.content").add(function () {

    var API = "https://api.pkro.com.br";

    function roColorToHtml(text) {
        var html = "";
        var colorStack = false;

        var parts = text.split(/\^([0-9A-Fa-f]{6})/);

        for (var i = 0; i < parts.length; i++) {
            if (i % 2 === 1) {
                if (colorStack) html += "</span>";
                html += '<span style="color:#' + parts[i] + '">';
                colorStack = true;
            } else {
                html += parts[i];
            }
        }

        if (colorStack) html += "</span>";

        return html
            .replace(/\\n/g, "<br>")
            .replace(/\n/g, "<br>");
    }


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

        if (el.dataset.loaded) return; // evita duplicar
        el.dataset.loaded = "1";

        var id = el.dataset.id;

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

                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 class="row">' +
                        '<img class="icon" src="' + API + item.icon + '">' +
                        '<div class="title">' + item.name + '</div>' +
                        '</div>' +
                        '<div class="text">' +
                        roColorToHtml(item.description) +
                        '</div>';

                    document.body.appendChild(tip);

                    var move = function (ev) {
                        var x = ev.clientX + 20;
                        var y = ev.clientY + 20;

                        if (x + 280 > window.innerWidth)
                            x = ev.clientX - 300;

                        if (y + 120 > window.innerHeight)
                            y = ev.clientY - 140;

                        tip.style.left = x + "px";
                        tip.style.top = y + "px";
                    };


                    document.addEventListener("mousemove", move);

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

                });

            })
            .catch(function (err) {
                console.error("Item API erro:", err);
                el.innerHTML = "[erro]";
            });

    });

});