|
|
| Linha 11: |
Linha 11: |
| </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
| |
| if (data.nome) {
| |
| console.log("Nome achado");
| |
| html += `<h2>${data.nome}</h2>`;
| |
| }
| |
|
| |
| // Introdução
| |
| if (data.introducao) {
| |
| html += `<p><em>${data.introducao}</em></p>`;
| |
| }
| |
|
| |
| // Localização
| |
| if (data.localizacao && data.localizacao.caminho) {
| |
| html += `<h3>Localizaçãoooo</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>`;
| |
| console.log("Requisitos antes");
| |
| if (d.requisitos && d.requisitos.length) {
| |
| d.requisitos.forEach(r => html += `<li>${r}</li>`);
| |
| }
| |
| html += `</ul>`;
| |
| console.log("Requisitos depois");
| |
|
| |
| // Recompensas
| |
| html += `<h3>Recompensas</h3><ul>`;
| |
| if (d.recompensas && d.recompensas.length) {
| |
| d.recompensas.forEach(r => html += `<li>${r}</li>`);
| |
| }
| |
| html += `</ul>`;
| |
|
| |
| 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> | | <style> |
| .boss-component .box { ... } | | .boss-component .box { ... } |
| </style> | | </style> |