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 1: | Linha 1: | ||
mw.hook("wikipage.content").add(function () { | |||
var API = "https://api.pkro.com.br"; | var API = "https://api.pkro.com.br"; | ||
| Linha 10: | Linha 10: | ||
document.querySelectorAll(".mw-item").forEach(function (el) { | document.querySelectorAll(".mw-item").forEach(function (el) { | ||
if (el.dataset.loaded) return; // evita duplicar | |||
el.dataset.loaded = "1"; | |||
var id = el.dataset.id; | var id = el.dataset.id; | ||
| Linha 17: | Linha 20: | ||
.then(function (item) { | .then(function (item) { | ||
el.innerHTML = '<img src="' + API + item.icon + '" width="32">'; | el.innerHTML = '<img src="' + API + item.icon + '" width="32">'; | ||
| Linha 51: | Linha 53: | ||
}) | }) | ||
.catch(function () { | .catch(function (err) { | ||
el.innerHTML = "[ | console.error("Item API erro:", err); | ||
el.innerHTML = "[erro]"; | |||
}); | }); | ||
Edição das 22h16min 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 =
'<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 (err) {
console.error("Item API erro:", err);
el.innerHTML = "[erro]";
});
});
});