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: | ||
} | } | ||
}); | }); | ||
}); | |||
// ------------------------------------------------------------ | |||
// Í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 endpoint: https://broaurora.com.br/wiki-item-icon/{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/"]'); | |||
links.forEach(function (a) { | |||
// evita duplicar | |||
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"; | |||
// estilo base para alinhar ícone + texto | |||
a.style.position = "relative"; | |||
a.style.paddingLeft = "30px"; | |||
a.style.display = "inline-block"; | |||
a.style.lineHeight = "24px"; | |||
// cria o span do ícone | |||
var icon = document.createElement("span"); | |||
icon.style.width = "24px"; | |||
icon.style.height = "24px"; | |||
icon.style.position = "absolute"; | |||
icon.style.left = "0"; | |||
icon.style.top = "50%"; | |||
icon.style.transform = "translateY(-50%)"; | |||
icon.style.backgroundSize = "contain"; | |||
icon.style.backgroundRepeat = "no-repeat"; | |||
icon.style.backgroundImage = "url('https://broaurora.com.br/wiki-item-icon/" + id + ".png')"; | |||
// fallback se a imagem não existir (via test img) | |||
var test = new Image(); | |||
test.onload = function () {}; | |||
test.onerror = function () { | |||
icon.style.backgroundImage = "url('https://broaurora.com.br/wiki-item-icon/unknown.png')"; | |||
}; | |||
test.src = "https://broaurora.com.br/wiki-item-icon/" + id + ".png"; | |||
// 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); | |||
}); | |||
} | |||
}); | }); | ||
Edição das 16h29min de 11 de fevereiro 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 endpoint: https://broaurora.com.br/wiki-item-icon/{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/"]');
links.forEach(function (a) {
// evita duplicar
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";
// estilo base para alinhar ícone + texto
a.style.position = "relative";
a.style.paddingLeft = "30px";
a.style.display = "inline-block";
a.style.lineHeight = "24px";
// cria o span do ícone
var icon = document.createElement("span");
icon.style.width = "24px";
icon.style.height = "24px";
icon.style.position = "absolute";
icon.style.left = "0";
icon.style.top = "50%";
icon.style.transform = "translateY(-50%)";
icon.style.backgroundSize = "contain";
icon.style.backgroundRepeat = "no-repeat";
icon.style.backgroundImage = "url('https://broaurora.com.br/wiki-item-icon/" + id + ".png')";
// fallback se a imagem não existir (via test img)
var test = new Image();
test.onload = function () {};
test.onerror = function () {
icon.style.backgroundImage = "url('https://broaurora.com.br/wiki-item-icon/unknown.png')";
};
test.src = "https://broaurora.com.br/wiki-item-icon/" + id + ".png";
// 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);
});
}
});