Mudanças entre as edições de "Widget:TesteBossYawnv3"
Ir para navegação
Ir para pesquisar
${escapeHtml(r)} `);
} else {
html += `Nenhum requisito `;
}
html += `${escapeHtml(r)} `);
} else {
html += `Nenhuma recompensa garantida `;
}
html += `${escapeHtml(r)} `);
} else {
html += `Nenhuma recompensa possível `;
}
html += `
Etiqueta: Reversão manual |
|||
| Linha 3: | Linha 3: | ||
<button class="boss-diff-btn" data-diff="elite">ELITE</button> | <button class="boss-diff-btn" data-diff="elite">ELITE</button> | ||
<button class="boss-diff-btn" data-diff="hard">HARD</button> | <button class="boss-diff-btn" data-diff="hard">HARD</button> | ||
<h2>Teste</h2> | |||
</div> | </div> | ||
| Linha 8: | Linha 9: | ||
<script> | <script> | ||
(function() { | |||
function escapeHtml(str) { | |||
if (!str) return ''; | |||
return str.replace(/[&<>]/g, function(m) { | |||
if (m === '&') return '&'; | |||
if (m === '<') return '<'; | |||
if (m === '>') return '>'; | |||
return m; | |||
}); | |||
} | |||
async function bossRender(root, diff) { | |||
const data = JSON.parse(root.dataset.json); | |||
const d = data[diff]; | |||
const content = root.querySelector(".boss-content"); | |||
if (!content) return; | |||
let html = ''; | |||
// Nome do boss | |||
if (data.nome) { | |||
html += `<h2>${escapeHtml(data.nome)}</h2>`; | |||
} | |||
data = | // Introdução | ||
if (data.introducao) { | |||
html += `<p><em>${escapeHtml(data.introducao)}</em></p>`; | |||
} | |||
// Localização | |||
if (data.localizacao) { | |||
html += `<h3>Localização</h3>`; | |||
html += `<p>${escapeHtml(data.localizacao.descricao)}</p>`; | |||
} | |||
// Requisitos | |||
html += `<h3>Requisitos</h3><ul>`; | |||
if (d.requisitos && d.requisitos.length) { | |||
d.requisitos.forEach(r => html += `<li>${escapeHtml(r)}</li>`); | |||
} else { | |||
html += `<li>Nenhum requisito</li>`; | |||
} | |||
html += `</ul>`; | |||
// Recompensas Garantidas | |||
html += `<h3>Recompensas Garantidas</h3><ul>`; | |||
if (d.recompensas && d.recompensas.length) { | |||
d.recompensas.forEach(r => html += `<li>${escapeHtml(r)}</li>`); | |||
} else { | |||
html += `<li>Nenhuma recompensa garantida</li>`; | |||
} | |||
html += `</ul>`; | |||
// Possíveis Recompensas | |||
html += `<h3>Possíveis Recompensas</h3><ul>`; | |||
if (d.recompensasPossiveis && d.recompensasPossiveis.length) { | |||
d.recompensasPossiveis.forEach(r => html += `<li>${escapeHtml(r)}</li>`); | |||
} else { | |||
html += `<li>Nenhuma recompensa possível</li>`; | |||
} | |||
html += `</ul>`; | |||
content.innerHTML = html; | |||
// Atualiza botão ativo | |||
root.querySelectorAll('.boss-diff-btn').forEach(btn => { | |||
const diffBtn = btn.dataset.diff; | |||
if (diffBtn === diff) { | |||
btn.classList.add('active'); | |||
} else { | |||
btn.classList.remove('active'); | |||
} | |||
}); | |||
} | } | ||
function init() { | |||
document.querySelectorAll('.boss-component').forEach(root => { | |||
if (root.dataset.initialized === 'true') return; | |||
root.dataset.initialized = 'true'; | |||
// Adiciona event listeners nos botões | |||
const buttons = root.querySelectorAll('.boss-diff-btn'); | |||
buttons.forEach(btn => { | |||
btn.removeEventListener('click', handleClick); | |||
btn.addEventListener('click', handleClick); | |||
}); | |||
// Renderiza dificuldade normal | |||
bossRender(root, 'normal'); | |||
}); | |||
} | } | ||
function handleClick(e) { | |||
const btn = e.currentTarget; | |||
const root = btn.closest('.boss-component'); | |||
const diff = btn.dataset.diff; | |||
if (root && diff) { | |||
bossRender(root, diff); | |||
} | |||
} | } | ||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', init); | |||
} else { | |||
init(); | |||
} | |||
} | |||
if ( | if (typeof mw !== 'undefined' && mw.hook) { | ||
mw.hook('wikipage.content').add(init); | |||
} | } | ||
})(); | |||
</script> | </script> | ||
Edição das 17h29min de 9 de abril de 2026
<script> (function() {
function escapeHtml(str) {
if (!str) return ;
return str.replace(/[&<>]/g, function(m) {
if (m === '&') return '&';
if (m === '<') return '<';
if (m === '>') return '>';
return m;
});
}
async function bossRender(root, diff) {
const data = JSON.parse(root.dataset.json);
const d = data[diff];
const content = root.querySelector(".boss-content");
if (!content) return;
let html = ;
// Nome do boss
if (data.nome) {
html += `
${escapeHtml(data.nome)}
`;
}
// Introdução
if (data.introducao) {
html += `
${escapeHtml(data.introducao)}
`;
}
// Localização
if (data.localizacao) {
html += `
Localização
`; html += `
${escapeHtml(data.localizacao.descricao)}
`;
}
// Requisitos
html += `
Requisitos
- `;
if (d.requisitos && d.requisitos.length) {
d.requisitos.forEach(r => html += ``;
// Recompensas Garantidas
html += `
Recompensas Garantidas
- `;
if (d.recompensas && d.recompensas.length) {
d.recompensas.forEach(r => html += ``;
// Possíveis Recompensas
html += `
Possíveis Recompensas
- `;
if (d.recompensasPossiveis && d.recompensasPossiveis.length) {
d.recompensasPossiveis.forEach(r => html += ``;
content.innerHTML = html;
// Atualiza botão ativo
root.querySelectorAll('.boss-diff-btn').forEach(btn => {
const diffBtn = btn.dataset.diff;
if (diffBtn === diff) {
btn.classList.add('active');
} else {
btn.classList.remove('active');
}
});
}
function init() {
document.querySelectorAll('.boss-component').forEach(root => {
if (root.dataset.initialized === 'true') return;
root.dataset.initialized = 'true';
// Adiciona event listeners nos botões
const buttons = root.querySelectorAll('.boss-diff-btn');
buttons.forEach(btn => {
btn.removeEventListener('click', handleClick);
btn.addEventListener('click', handleClick);
});
// Renderiza dificuldade normal
bossRender(root, 'normal');
});
}
function handleClick(e) {
const btn = e.currentTarget;
const root = btn.closest('.boss-component');
const diff = btn.dataset.diff;
if (root && diff) {
bossRender(root, diff);
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
if (typeof mw !== 'undefined' && mw.hook) {
mw.hook('wikipage.content').add(init);
}
})(); </script>