"bossSetDiff(this,'normal')">NORMAL</button>
<button onclick="bossSetDiff(this,'elite')">ELITE</button> <button onclick="bossSetDiff(this,'hard')">HARD</button>
(Criou página com '<div class="boss-component" data-json="{{{data}}}"> <div class="boss-diff"> <button onclick="bossSetDiff(this,'normal')">NORMAL</button> <button onclick="bossSetD...') |
|||
| (18 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
| Linha 1: | Linha 1: | ||
<tabber class="boss-diff"> | |||
<button onclick="bossSetDiff(this,'normal')">NORMAL</button> | |||
<button onclick="bossSetDiff(this,'elite')">ELITE</button> | |||
<button onclick="bossSetDiff(this,'hard')">HARD</button> | |||
</tabber> | |||
<div class="boss-content"> | |||
</div> | </div> | ||
<script> | |||
(function() { | |||
async function getImageUrlFromWiki(imageName) { | |||
const apiUrl = `https://wiki.gla.com.br/api.php?action=query&titles=${encodeURIComponent(imageName)}&prop=imageinfo&iiprop=url&format=json&origin=*`; | |||
try { | |||
const response = await fetch(apiUrl); | |||
const data = await response.json(); | |||
const pages = data.query.pages; | |||
const page = Object.values(pages)[0]; | |||
if (page.imageinfo && page.imageinfo[0]) { | |||
return page.imageinfo[0].url; | |||
} | |||
} catch(e) { | |||
console.error('Erro ao buscar imagem:', e); | |||
} | |||
return null; | |||
} | } | ||
async function bossRender(root, diff) { | |||
const data = JSON.parse(root.dataset.json); | |||
const d = data[diff]; | |||
const content = root.querySelector(".boss-content"); | |||
let html = ""; | |||
// Nome do boss (se existir) | |||
if (data.nome) { | |||
html += `<h2>${data.nome}</h2>`; | |||
} | |||
// Introdução (se existir) | |||
if (data.introducao) { | |||
html += `<p><em>${data.introducao}</em></p>`; | |||
} | |||
// Localização (se existir) | |||
if (data.localizacao && data.localizacao.caminho) { | |||
html += `<h3>Localização</h3>`; | |||
html += `<p>${data.localizacao.descricao}</p>`; | |||
const imageName = data.localizacao.caminho; | |||
const imageUrl = await getImageUrlFromWiki(imageName); | |||
if (imageUrl) { | |||
html += `<div style="text-align: center;"> | |||
<img src="${imageUrl}" style="max-width: 100%;"> | |||
<p><small>Caminho para o boss</small></p> | |||
</div>`; | |||
} | |||
} | |||
// Requisitos | |||
html += `<h3>Requisitos</h3><ul>`; | |||
d.requisitos.forEach(r => html += `<li>${r}</li>`); | |||
html += `</ul>`; | |||
// Recompensas | |||
html += `<h3>Recompensas</h3><ul>`; | |||
d.recompensas.forEach(r => html += `<li>${r}</li>`); | |||
html += `</ul>`; | |||
// Skills | |||
} | if (d.skills && d.skills.length > 0) { | ||
html += `<h3>Skills</h3><ul>`; | |||
d.skills.forEach(s => html += `<li><strong>${s.nome}</strong>: ${s.desc}</li>`); | |||
html += `</ul>`; | |||
} | |||
content.innerHTML = html; | |||
} | |||
function | function init() { | ||
document.querySelectorAll(".boss-component").forEach(root => { | |||
if (root.dataset.rendered === 'true') return; | |||
} | root.dataset.rendered = 'true'; | ||
bossRender(root, "normal"); | |||
}); | |||
} | |||
function | window.bossSetDiff = function(el, diff) { | ||
const root = el.closest(".boss-component"); | |||
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> | </script> | ||
<style> | |||
.boss-component .box { ... } | |||
</style> | |||
"bossSetDiff(this,'normal')">NORMAL</button>
<button onclick="bossSetDiff(this,'elite')">ELITE</button> <button onclick="bossSetDiff(this,'hard')">HARD</button>
<script>
(function() {
async function getImageUrlFromWiki(imageName) {
const apiUrl = `https://wiki.gla.com.br/api.php?action=query&titles=${encodeURIComponent(imageName)}&prop=imageinfo&iiprop=url&format=json&origin=*`;
try {
const response = await fetch(apiUrl);
const data = await response.json();
const pages = data.query.pages;
const page = Object.values(pages)[0];
if (page.imageinfo && page.imageinfo[0]) {
return page.imageinfo[0].url;
}
} catch(e) {
console.error('Erro ao buscar imagem:', e);
}
return null;
}
async function bossRender(root, diff) {
const data = JSON.parse(root.dataset.json);
const d = data[diff];
const content = root.querySelector(".boss-content");
let html = "";
// Nome do boss (se existir)
if (data.nome) {
html += `
`;
}
// Introdução (se existir)
if (data.introducao) {
html += `
${data.introducao}
`;
}
// Localização (se existir)
if (data.localizacao && data.localizacao.caminho) {
html += `
`; html += `
${data.localizacao.descricao}
`;
const imageName = data.localizacao.caminho;
const imageUrl = await getImageUrlFromWiki(imageName);
if (imageUrl) {
html += `
<img src="${imageUrl}" style="max-width: 100%;">
Caminho para o boss
`;
}
}
// Requisitos
html += `
`;
// Recompensas
html += `
`;
// Skills
if (d.skills && d.skills.length > 0) {
html += `
`;
}
content.innerHTML = html; }
function init() {
document.querySelectorAll(".boss-component").forEach(root => {
if (root.dataset.rendered === 'true') return;
root.dataset.rendered = 'true';
bossRender(root, "normal");
});
}
window.bossSetDiff = function(el, diff) {
const root = el.closest(".boss-component");
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>
<style> .boss-component .box { ... } </style>