MediaWiki:Common.js
Nota: Após publicar, você pode ter que limpar o "cache" do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5.
- Opera: Pressione Ctrl-F5.
// 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);
}
});
});
// Catalog integration: editorial labels are preserved; canonical data comes from the Database.
mw.loader.using('mediawiki.util').then(function () {
var pending = new Map();
var scheduled = false;
function flush() {
scheduled = false;
var batch = Array.from(pending.entries());
pending.clear();
var chunks = [];
for (var n = 0; n < batch.length; n += 100) chunks.push(batch.slice(n, n + 100));
// Sequential batches bound the load on the catalog endpoint.
chunks.reduce(function (chain, chunk) {
return chain.then(function () {
var controller = new AbortController();
var timer = setTimeout(function () { controller.abort(); }, 12000);
return fetch('/information/catalog/items?ids=' + chunk.map(function (e) { return e[0]; }).join(','), {
credentials: 'same-origin', cache: 'no-store', signal: controller.signal
}).then(function (r) {
if (!r.ok) throw new Error('Catalog HTTP ' + r.status);
return r.json();
}).then(function (data) {
chunk.forEach(function (entry) {
var item = data.items[entry[0]];
entry[1].forEach(function (a) {
a.dataset.aurCatalogVersion = data.version;
if (!item) { a.dataset.aurCatalogStatus = 'unavailable'; return; }
var label = a.textContent.trim();
if (label === 'Item ' + item.id || label === 'Item #' + item.id || (item.previous_name && label === item.previous_name && label !== item.name)) a.textContent = item.name;
else if (label !== item.name) a.dataset.aurEditorialLabel = 'preserved';
a.dataset.aurCatalogName = item.name;
a.dataset.aurCatalogOrigin = item.origin || 'legacy';
a.title = item.name + (item.origin === 'client_only' ? ' — documentado no cliente; disponibilidade no servidor não confirmada' : '');
// Preserve the deployed Wiki convention: collection artwork scaled to 24px.
var image = item.image;
if (!image) { a.dataset.aurCatalogStatus = 'no-proven-icon'; return; }
var icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.className = 'aur-catalog-icon';
Object.assign(icon.style, {width:'24px',height:'24px',flex:'0 0 24px',display:'inline-block',backgroundSize:'contain',backgroundRepeat:'no-repeat',backgroundPosition:'center',borderRadius:'6px',backgroundColor:'rgba(0,0,0,.04)'});
icon.style.backgroundImage = 'url("' + image + '")';
a.prepend(icon);
var test = new Image();
test.onerror = function () { icon.remove(); a.dataset.aurCatalogStatus = 'image-unavailable'; };
test.onload = function () { a.dataset.aurCatalogStatus = 'verified-image-loaded'; };
test.src = image;
});
});
}).catch(function () {
chunk.forEach(function (entry) { entry[1].forEach(function (a) { a.dataset.aurCatalogStatus = 'request-failed'; delete a.dataset.aurItemIconApplied; }); });
}).finally(function () { clearTimeout(timer); });
});
}, Promise.resolve());
}
function applyItemIcons(root) {
(root || document).querySelectorAll('a[href*="/information/itemdb/"]:not(.aur-item-link)').forEach(function (a) {
if (a.getAttribute('data-aur-noicon') === '1' || a.dataset.aurItemIconApplied) return;
var url = new URL(a.href, location.href);
if (url.origin !== location.origin) return;
var m = url.pathname.match(/^\/information\/itemdb\/(\d+)\/?$/);
if (!m) return;
a.dataset.aurItemIconApplied = '1';
if (!pending.has(m[1])) pending.set(m[1], []);
pending.get(m[1]).push(a);
});
if (pending.size && !scheduled) { scheduled = true; setTimeout(flush, 0); }
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', function () { applyItemIcons(document); });
else applyItemIcons(document);
mw.hook('wikipage.content').add(function ($content) { applyItemIcons($content[0] || document); });
});