Mudanças entre as edições de "Widget:Character.Background"
Ir para navegação
Ir para pesquisar
m |
m |
||
| Linha 4: | Linha 4: | ||
<script> | <script> | ||
(function () { | (function () { | ||
function buildBgURL(fileName) { | function buildBgURL(fileName) { | ||
if (!fileName) return ''; | if (!fileName) return ''; | ||
| Linha 20: | Linha 17: | ||
} | } | ||
function | function applyBg(el) { | ||
try { | try { | ||
var url = el.getAttribute('data-bg-url'); | var url = el.getAttribute('data-bg-url'); | ||
| Linha 30: | Linha 27: | ||
} | } | ||
} | } | ||
if ( | if (url) { | ||
el.style.backgroundImage = 'url("' + url + '")'; | el.style.backgroundImage = 'url("' + url + '")'; | ||
} | } | ||
} catch (e) { /* no-op */ } | } catch (e) { /* no-op */ } | ||
} | } | ||
// | // Aplicar backgrounds imediatamente | ||
document.querySelectorAll('[data-bg-url], [data-bg-file]').forEach(applyBg); | |||
document.querySelectorAll('[data-bg-url], [data-bg-file]').forEach( | |||
// Apply to future elements (AJAX) | // Apply to future elements (AJAX) | ||
| Linha 82: | Linha 43: | ||
if (n.nodeType === 1) { | if (n.nodeType === 1) { | ||
if (n.hasAttribute && (n.hasAttribute('data-bg-file') || n.hasAttribute('data-bg-url'))) { | if (n.hasAttribute && (n.hasAttribute('data-bg-file') || n.hasAttribute('data-bg-url'))) { | ||
applyBg(n); | |||
} | } | ||
if (n.querySelectorAll) { | if (n.querySelectorAll) { | ||
n.querySelectorAll('[data-bg-file], [data-bg-url]').forEach( | n.querySelectorAll('[data-bg-file], [data-bg-url]').forEach(applyBg); | ||
} | } | ||
} | } | ||
}); | }); | ||
} else if (m.type === 'attributes' && m.target) { | } else if (m.type === 'attributes' && m.target) { | ||
applyBg(m.target); | |||
} | } | ||
}); | }); | ||
Edição das 23h49min de 24 de novembro de 2025
<script>
(function () {
function buildBgURL(fileName) {
if (!fileName) return ;
var base = (window.mw && mw.util && typeof mw.util.wikiScript === 'function')
? mw.util.wikiScript()
: (window.mw && mw.config ? (mw.config.get('wgScript') || '/index.php') : '/index.php');
var path = 'Especial:FilePath/' + fileName.replace(/^Arquivo:|^File:/, );
if (window.mw && mw.util && typeof mw.util.wikiUrlencode === 'function') {
return base + '?title=' + mw.util.wikiUrlencode(path);
} else {
return base + '?title=' + encodeURIComponent(path).replace(/%2F/g, '/');
}
}
function applyBg(el) {
try {
var url = el.getAttribute('data-bg-url');
if (!url) {
var f = el.getAttribute('data-bg-file');
if (f) {
url = buildBgURL(f);
el.setAttribute('data-bg-url', url);
}
}
if (url) {
el.style.backgroundImage = 'url("' + url + '")';
}
} catch (e) { /* no-op */ }
}
// Aplicar backgrounds imediatamente
document.querySelectorAll('[data-bg-url], [data-bg-file]').forEach(applyBg);
// Apply to future elements (AJAX)
new MutationObserver(function (mutations) {
mutations.forEach(function (m) {
if (m.type === 'childList') {
m.addedNodes.forEach(function (n) {
if (n.nodeType === 1) {
if (n.hasAttribute && (n.hasAttribute('data-bg-file') || n.hasAttribute('data-bg-url'))) {
applyBg(n);
}
if (n.querySelectorAll) {
n.querySelectorAll('[data-bg-file], [data-bg-url]').forEach(applyBg);
}
}
});
} else if (m.type === 'attributes' && m.target) {
applyBg(m.target);
}
});
}).observe(document.body, {
attributes: true,
attributeFilter: ['data-bg-file', 'data-bg-url'],
childList: true,
subtree: true,
});
})();
</script>