MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
| Linha 27: | Linha 27: | ||
tip.className = "item-tooltip"; | tip.className = "item-tooltip"; | ||
tip.innerHTML = | |||
'<img class="icon" src="' + API + item.icon + '">' + | |||
'<div class="text">' + | |||
'<b>' + item.name + '</b><br>' + | |||
roColorToHtml(item.description) + | |||
'</div>'; | |||
document.body.appendChild(tip); | document.body.appendChild(tip); | ||
var move = function (ev) { | var move = function (ev) { | ||
var x = ev.clientX + | var x = ev.clientX + 20; | ||
var y = ev.clientY + | var y = ev.clientY + 20; | ||
if (x + 280 > window.innerWidth) | |||
if (x + | x = ev.clientX - 300; | ||
x = ev.clientX - | |||
if (y + | if (y + 120 > window.innerHeight) | ||
y = ev.clientY - | y = ev.clientY - 140; | ||
tip.style.left = x + "px"; | tip.style.left = x + "px"; | ||
Edição das 22h27min de 2 de fevereiro de 2026
mw.hook("wikipage.content").add(function () {
var API = "https://api.pkro.com.br";
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) {
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 =
'<img class="icon" src="' + API + item.icon + '">' +
'<div class="text">' +
'<b>' + item.name + '</b><br>' +
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]";
});
});
});