Mudanças entre as edições de "Widget:TesteBossYawnv2"

De Wiki Gla
Ir para navegação Ir para pesquisar
Linha 1: Linha 1:


<tabber class="boss-diff">
<tabber class="boss-diff">
  <h1>Teste</h1>
   <button onclick="bossSetDiff(this,'normal')">NORMAL</button>
   <button onclick="bossSetDiff(this,'normal')">NORMAL</button>
   <button onclick="bossSetDiff(this,'elite')">ELITE</button>
   <button onclick="bossSetDiff(this,'elite')">ELITE</button>

Edição das 17h02min de 9 de abril de 2026

"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
   if (data.nome) {
     console.log("Nome achado");

html += `

${data.nome}

`;

   }
   // Introdução
   if (data.introducao) {

html += `

${data.introducao}

`;

   }
   // Localização
   if (data.localizacao && data.localizacao.caminho) {

html += `

Localizaçãoooo

`; 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 += `

Requisitos

    `;
       console.log("Requisitos antes");
       if (d.requisitos && d.requisitos.length) {
    
    d.requisitos.forEach(r => html += `
  • ${r}
  • `); } html += `

`;

   console.log("Requisitos depois");
   // Recompensas

html += `

Recompensas

    `;
       if (d.recompensas && d.recompensas.length) {
    
    d.recompensas.forEach(r => html += `
  • ${r}
  • `); } 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>