Widget:Test: mudanças entre as edições

De PokeXGames
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
 
(197 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
// Base de dados local
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Busca de Imagens por Nome</title>
    <style>
        .input-group { margin-bottom: 1em; position: relative; }
        .dropdown {
            border: 1px solid #ccc;
            display: none;
            position: absolute;
            background-color: #fff;
            z-index: 1000;
            max-height: 150px;
            overflow-y: auto;
            width: 100%;
        }
        .dropdown-item {
            padding: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
        }
        .dropdown-item img {
            margin-right: 10px;
        }
        .dropdown-item:hover {
            background-color: #f0f0f0;
        }
        .image-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }
        .image-item {
            margin-bottom: 1em;
            text-align: center;
        }
        .image-item img {
            display: block;
            margin: 0 auto;
        }


         const allData = [
         .variations-container {
             {
             display: flex;
                "id": 18,
            flex-wrap: wrap;
                "name": "Bag of Pollen",
            justify-content: center;
                "icon": "https://wiki.pokexgames.com/images/b/bc/BagOfPollem.png",
            margin-top: 1em;
                "link": "https://wiki.pokexgames.com/index.php/Bag_Of_Pollem",
         }
                "isNightmare": false,
 
                "whoDrops":[
         .variation-item {
      {
            width: 35%;
        "id": 1,
            box-sizing: border-box;
        "icon": "https://wiki.pokexgames.com/images/5/5c/001-Bulbasaur.png",
            margin: 5px;
        "link": "https://wiki.pokexgames.com/index.php/Bulbasaur",
            text-align: center;
         "name": "Bulbasaur"
            border: 1px solid ;
      },
            padding: 10px;
      {
         }
        "id": 2,
 
         "icon": "https://wiki.pokexgames.com/images/c/c6/003-Venusaur.png",
         .variation-item img {
        "link": "https://wiki.pokexgames.com/index.php/Venusaur",
            display: block;
        "name": "Venusaur"
            margin: 0 auto 10px;
      },
         }
      {
 
        "id": 3,
         .swap-button {  
        "icon": "https://wiki.pokexgames.com/images/f/f0/003-MegaVenusaur.png",
            margin-top: 10px;
        "link": "https://wiki.pokexgames.com/index.php/Mega_Venusaur",
            cursor: pointer;
        "name": "Mega Venusaur"
            width: 15px;
      },
            height: 15px;
      {
            background: url('https://wiki.pokexgames.com/images/f/fb/SwapButtonAddons.png') no-repeat center;
        "id": 4,
            background-size: contain;
        "icon": "https://wiki.pokexgames.com/images/2/2a/Sh_venu.png",
            display: block;
         "link": "https://wiki.pokexgames.com/index.php/Shiny_Venusaur",
            margin: 0 auto;
        "name": "Shiny Venusaur"
         }
      },
    </style>
      {
</head>
        "id": 5,
<body>
         "icon": "https://wiki.pokexgames.com/images/4/4e/012-Butterfree.png",
    <form id="imageForm">
        "link": "https://wiki.pokexgames.com/index.php/Butterfree",
         <div class="input-group">
        "name": "Butterfree"
            <input type="text" id="imageSearch" placeholder="Digite o nome da imagem" autocomplete="off">
      },
            <div id="dropdown" class="dropdown"></div>
      {
         </div>
        "id": 6,
 
        "icon": "https://wiki.pokexgames.com/images/2/27/012-Sh_Butterfree.png",
         <div id="imageContainer" class="image-container hidden">
         "link": "https://wiki.pokexgames.com/index.php/Shiny_Butterfree",
            <!-- As imagens e suas informações serão exibidas aqui -->
        "name": "Shiny Butterfree"
         </div>
      },
    </form>
      {
 
        "id": 7,
    <script>
         "icon": "https://wiki.pokexgames.com/images/a/ad/015-Beedrill.png",
         const imageList = {
        "link": "https://wiki.pokexgames.com/index.php/Beedrill",
            'Squirtle': {  
        "name": "Beedrill"
                imageUrl: 'https://wiki.pokexgames.com/images/7/7a/007-Squirtle.png',  
      },
                variations: [
      {
                    {  
        "id": 8,
                        description: 'Squirtle Purple Ninja Pack',
        "icon": "https://wiki.pokexgames.com/images/b/ba/015-Sh_Beedrill.png",
                        descriptionIMG: 'https://wiki.pokexgames.com/images/c/c1/Purple_Stripe.png',
        "link": "https://wiki.pokexgames.com/index.php/Shiny_Beedrill",
                        obtain: {
        "name": "Shiny Beedrill"
                            url: 'https://wiki.pokexgames.com/index.php/Craft_Profissões_-_Estilista#Rank_E',
      },
                            text: 'Estilista'
      {
                        },
        "id": 9,
                        additionalImages: [
        "icon": "https://wiki.pokexgames.com/images/1/1a/043-Oddish.png",
                            { url: 'https://wiki.pokexgames.com/images/d/dd/Squirtle_Purple_Ninja_Pack_Frente.png'}, // Frente
        "link": "https://wiki.pokexgames.com/index.php/Oddish",
                            { url: 'https://wiki.pokexgames.com/images/5/50/Squirtle_Purple_Ninja_Pack_Esquerda.png'}, // Lado Esquerdo
        "name": "Oddish"
                            { url: 'https://wiki.pokexgames.com/images/a/af/Squirtle_Purple_Ninja_Pack_Direita.png'}, // Costas
      },
                            { url: 'https://wiki.pokexgames.com/images/5/5d/Squirtle_Purple_Ninja_Pack_Costas.png'}  // Lado Direito
      {
                        ]
        "id": 10,
                    },
         "icon": "https://wiki.pokexgames.com/images/c/cc/043-Sh_Oddish.png",
                    {
        "link": "https://wiki.pokexgames.com/index.php/Shiny_Oddish",
                        description: 'Squirtle Red Ninja Pack',
        "name": "Shiny Oddish"
                        descriptionIMG: 'https://wiki.pokexgames.com/images/c/c1/Purple_Stripe.png',
      },
                        obtain: {
      {
                             url: 'https://wiki.pokexgames.com/index.php/Craft_Profissões_-_Estilista#Rank_E',
        "id": 11,
                             text: 'Estilista'
        "icon": "https://wiki.pokexgames.com/images/9/92/044-Gloom.png",
        "link": "https://wiki.pokexgames.com/index.php/Gloom",
        "name": "Gloom"
      },
      {
        "id": 12,
         "icon": "https://wiki.pokexgames.com/images/a/ab/045-Vileplume.png",
        "link": "https://wiki.pokexgames.com/index.php/Vileplume",
        "name": "Vileplume"
      },
      {
        "id": 13,
        "icon": "https://wiki.pokexgames.com/images/8/8e/Shinyvil.png",
         "link": "https://wiki.pokexgames.com/index.php/Shiny_Vileplume",
        "name": "Shiny Vileplume"
      },
      {
         "id": 14,
        "icon": "https://wiki.pokexgames.com/images/e/e7/046-Paras.png",
        "link": "https://wiki.pokexgames.com/index.php/Paras",
        "name": "Paras"
      },
      {
        "id": 15,
        "icon": "https://wiki.pokexgames.com/images/5/56/047-Parasect.png",
        "link": "https://wiki.pokexgames.com/index.php/Parasect",
        "name": "Parasect"
      },
      {
        "id": 16,
        "icon": "https://wiki.pokexgames.com/images/a/ab/048-Venonat.png",
        "link": "https://wiki.pokexgames.com/index.php/Venonat",
        "name": "Venonat"
      },
      {
        "id": 17,
        "icon": "https://wiki.pokexgames.com/images/e/ec/049-Venomoth.png",
        "link": "https://wiki.pokexgames.com/index.php/Venomoth",
        "name": "Venomoth"
      },
      {
        "id": 18,
        "icon": "https://wiki.pokexgames.com/images/0/03/049-Sh_Venomoth.png",
         "link": "https://wiki.pokexgames.com/index.php/Shiny_Venomoth",
        "name": "Shiny Venomoth"
      },
      {
        "id": 19,
        "icon": "https://wiki.pokexgames.com/images/b/bf/152-Chikorita.png",
        "link": "https://wiki.pokexgames.com/index.php/Chikorita",
        "name": "Chikorita"
      },
      {
         "id": 20,
        "icon": "https://wiki.pokexgames.com/images/f/fc/153-Bayleef.png",
        "link": "https://wiki.pokexgames.com/index.php/Bayleef",
        "name": "Bayleef"
      },
      {
        "id": 21,
        "icon": "https://wiki.pokexgames.com/images/2/2f/154-Meganium.png",
        "link": "https://wiki.pokexgames.com/index.php/Meganium",
        "name": "Meganium"
      },
      {
        "id": 22,
        "icon": "https://wiki.pokexgames.com/images/1/1b/154-Sh_Meganium.png",
        "link": "https://wiki.pokexgames.com/index.php/Shiny_Meganium",
        "name": "Shiny Meganium"
      },
      {
        "id": 23,
        "icon": "https://wiki.pokexgames.com/images/c/c7/187-Hoppip.png",
        "link": "https://wiki.pokexgames.com/index.php/Hoppip",
        "name": "Hoppip"
      },
      {
        "id": 24,
        "icon": "https://wiki.pokexgames.com/images/1/14/188-Skiploom.png",
        "link": "https://wiki.pokexgames.com/index.php/Skiploom",
        "name": "Skiploom"
      },
      {
        "id": 25,
        "icon": "https://wiki.pokexgames.com/images/e/ee/189-Jumpluff.png",
        "link": "https://wiki.pokexgames.com/index.php/Jumpluff",
        "name": "Jumpluff"
      },
      {
        "id": 26,
        "icon": "https://wiki.pokexgames.com/images/5/52/407-Roserade.png",
        "link": "https://wiki.pokexgames.com/index.php/Roserade",
        "name": "Roserade"
      },
      {
        "id": 27,
        "icon": "https://wiki.pokexgames.com/images/d/dc/412-Burmy.png",
        "link": "https://wiki.pokexgames.com/index.php/Burmy",
        "name": "Burmy"
      },
      {
        "id": 28,
        "icon": "https://wiki.pokexgames.com/images/c/cf/616-Shelmet.png",
        "link": "https://wiki.pokexgames.com/index.php/Shelmet",
        "name": "Shelmet"
      }
    ]
  },
            {
                "id": 1884,
                "name": "Anya Outfit (female)",
                "icon": "https://wiki.pokexgames.com/images/8/8a/Anya_Outfit_Designer.png",
                "link": null,
                "isNightmare": false,
                "craft": {
                    "quantity": 1,
                    "skill": "100",
                    "cooldownText": "5 dias",
                    "rank": "S",
                    "profession": "Stylist",
                    "materials": [
                        {
                             "name": "Lovely Topknot",
                            "icon": "https://wiki.pokexgames.com/images/e/e9/Lovely_Topknot.png",
                            "isNightmare": true,
                            "quantity": 10,
                             "id": 532
                         },
                         },
                         // Outros materiais...
                         additionalImages: [
                     ]
                            { url: 'https://wiki.pokexgames.com/images/1/13/Squirtle_Red_Ninja_Pack_Frente.png'}, // Frente
                 }
                            { url: 'https://wiki.pokexgames.com/images/1/1e/Squirtle_Red_Ninja_Pack_Esquerda.png'}, // Lado Esquerdo
                            { url: 'https://wiki.pokexgames.com/images/0/01/Squirtle_Red_Ninja_Pack_Costas.png'}, // Costas
                            { url: 'https://wiki.pokexgames.com/images/f/fd/Squirtle_Red_Ninja_Pack_Direita.png'}  // Lado Direito
                        ]
                     }
                 ]
             },
             },
            {
        };
                "id": 1912,
 
                "name": "Catcher Token",
        const imageSearch = document.getElementById('imageSearch');
                "icon": "https://wiki.pokexgames.com/images/f/fd/Catcher_Token.png",
        const dropdown = document.getElementById('dropdown');
                "link": "https://wiki.pokexgames.com/index.php/Tokens",
        const imageContainer = document.getElementById('imageContainer');
                "isNightmare": false
 
             }
        imageSearch.addEventListener('input', function() {
        ];
            const searchValue = this.value.trim().toLowerCase();
             dropdown.innerHTML = '';


const search = document.getElementById("search");
            if (searchValue) {
const suggest = document.getElementById("suggest");
                Object.keys(imageList).forEach(imageName => {
const content = document.getElementById("content");
                    if (imageName.toLowerCase().includes(searchValue)) {
                        const dropdownItem = document.createElement('div');
                        dropdownItem.classList.add('dropdown-item');
                       
                        const imgElement = document.createElement('img');
                        imgElement.src = imageList[imageName].imageUrl;
                        imgElement.alt = imageName;
                       
                        dropdownItem.appendChild(imgElement);
                        dropdownItem.appendChild(document.createTextNode(imageName));
                       
                        dropdownItem.addEventListener('click', function() {
                            showImageInfo(imageName);
                            dropdown.style.display = 'none';
                        });
                        dropdown.appendChild(dropdownItem);
                    }
                });


const clearSuggestions = () => {
                dropdown.style.display = dropdown.childNodes.length ? 'block' : 'none';
    suggest.innerHTML = "";
            } else {
};
                dropdown.style.display = 'none';
            }
        });


const setItem = (id) => {
        document.addEventListener('click', function(event) {
    const data = allData.find((data) => data.id == id);
            if (!imageSearch.contains(event.target) && !dropdown.contains(event.target)) {
    if (!data) return;
                dropdown.style.display = 'none';
    clearSuggestions();
            }
        });


     content.innerHTML = `
function showImageInfo(imageName) {
    <div class="item-name">
    const imageInfo = imageList[imageName];
        <img class="item-name-icon" src="${data.icon}" />
     let imagesHtml = `
         <span>${data.name}</span>
        <div class="image-item">
    </div>`;
            <img src="${imageInfo.imageUrl}" alt="${imageName}">
         </div>
        <div class="variations-container">
    `;


     if (data.craft) {
     imageInfo.variations.forEach((variation, index) => {
         content.innerHTML += `
         imagesHtml += `
        <h3>Craft</h3>
            <div class="variation-item">
        <div class="craft">
                <img src="${variation.additionalImages[0].url}" alt="Variation Image" class="variation-image" data-variation-index="${index}" style="width: ${variation.additionalImages[0].width}px;">
            <p><b>Quantidade:</b> ${data.craft.quantity}</p>
                <div class="swap-button" data-variation-index="${index}"></div><br>
            <p><b>Skill:</b> ${data.craft.skill} - Rank ${data.craft.rank}</p>
                <div class="image-info">
            <p><b>Tempo de Craft:</b> ${data.craft.cooldownText}</p>
                    <img src="${variation.descriptionIMG}" alt="Description Image" style="margin-right: 5px; display: inline-block;"> <!-- Exibe a imagem antes da descrição -->
            <p><b>Profissão:</b> ${data.craft.profession}</p>
                    <br> ${variation.description} <br> <!-- Descrição após a imagem -->
            <p><b>Materiais:</b></p>
                     <b>Como Obter</b>: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
            <div class="materials">
                 </div>
                ${data.craft.materials.map((material) => `
                <div class="item-from-craft">
                    <div class="material-icon-container">
                        <img class="item-name-icon" src="${material.icon}" />
                     </div>
                    ${material.quantity}x ${material.name}
                 </div>`).join("")}
             </div>
             </div>
         </div>`;
         `;
    }
    });
 
    imagesHtml += '</div>';


     const materialTo = allData.filter((item) => {
     imageContainer.innerHTML = imagesHtml;
        if (!item.craft?.materials) return false;
    imageContainer.classList.remove('hidden');
        return item.craft.materials.some((m) => m.id == id);
    });


     if (materialTo.length) {
     // Alternar imagens ao clicar no botão de troca
        content.innerHTML += `
    const swapButtons = document.querySelectorAll('.swap-button');
        <h3>Usado para craftar</h3>
        <div class="materials">
            ${materialTo.map((material) => `
            <div class="item-from-craft">
                <div class="material-icon-container">
                    <img class="item-name-icon" src="${material.icon}" />
                </div>
                ${material.name}
            </div>`).join("")}
        </div>`;
    }
};


document.addEventListener("click", (e) => {
    swapButtons.forEach(button => {
    if (e.target.classList.contains("suggest-item")) {
        const index = button.getAttribute('data-variation-index');
         e.preventDefault();
         const variation = imageInfo.variations[index];
         setItem(e.target.dataset.itemId);
         let currentImageIndex = 0;
    }
});


search.addEventListener("input", () => {
        button.addEventListener('click', () => {
    const value = search.value?.toLowerCase();
            currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length;
    suggest.innerHTML = "";
             const variationImage = button.previousElementSibling; // Atualiza a imagem da variação
    allData.forEach((data) => {
             variationImage.src = variation.additionalImages[currentImageIndex].url;
        if (data.name.toLowerCase().includes(value)) {
             variationImage.style.width = `${variation.additionalImages[currentImageIndex].width}px`;
             const div = document.createElement("div");
        });
             div.innerHTML = `
            <img src="${data.icon}" class="suggest-icon" lazy />
             <a class="suggest-item" href="#" data-item-id="${data.id}">${data.name}</a>`;
            suggest.appendChild(div);
        }
     });
     });
});
}
 
    </script>
</body>
</html>

Edição atual tal como às 23h45min de 16 de outubro de 2024

<!DOCTYPE html> <html lang="pt-BR"> <head>

   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Busca de Imagens por Nome</title>
   <style>
       .input-group { margin-bottom: 1em; position: relative; }
       .dropdown {
           border: 1px solid #ccc;
           display: none;
           position: absolute;
           background-color: #fff;
           z-index: 1000;
           max-height: 150px;
           overflow-y: auto;
           width: 100%;
       }
       .dropdown-item {
           padding: 8px;
           cursor: pointer;
           display: flex;
           align-items: center;
       }
       .dropdown-item img {
           margin-right: 10px;
       }
       .dropdown-item:hover {
           background-color: #f0f0f0;
       }
       .image-container {
           display: flex;
           flex-direction: column;
           align-items: center;
           justify-content: center;
       }
       .image-item { 
           margin-bottom: 1em; 
           text-align: center;
       }
       .image-item img {
           display: block;
           margin: 0 auto;
       }
       .variations-container {
           display: flex;
           flex-wrap: wrap;
           justify-content: center;
           margin-top: 1em;
       }
       .variation-item {
           width: 35%;
           box-sizing: border-box;
           margin: 5px;
           text-align: center;
           border: 1px solid ;
           padding: 10px;
       }
       .variation-item img {
           display: block;
           margin: 0 auto 10px;
       }
       .swap-button { 
           margin-top: 10px;
           cursor: pointer;
           width: 15px;
           height: 15px;
           background: url('https://wiki.pokexgames.com/images/f/fb/SwapButtonAddons.png') no-repeat center;
           background-size: contain;
           display: block;
           margin: 0 auto;
       }
   </style>

</head> <body>

   <form id="imageForm">
           <input type="text" id="imageSearch" placeholder="Digite o nome da imagem" autocomplete="off">
   </form>
   <script>
       const imageList = {
           'Squirtle': { 
               imageUrl: 'https://wiki.pokexgames.com/images/7/7a/007-Squirtle.png', 
               variations: [
                   { 
                       description: 'Squirtle Purple Ninja Pack',
                       descriptionIMG: 'https://wiki.pokexgames.com/images/c/c1/Purple_Stripe.png',
                       obtain: {
                           url: 'https://wiki.pokexgames.com/index.php/Craft_Profissões_-_Estilista#Rank_E',
                           text: 'Estilista'
                       },
                       additionalImages: [
                           { url: 'https://wiki.pokexgames.com/images/d/dd/Squirtle_Purple_Ninja_Pack_Frente.png'}, // Frente
                           { url: 'https://wiki.pokexgames.com/images/5/50/Squirtle_Purple_Ninja_Pack_Esquerda.png'}, // Lado Esquerdo
                           { url: 'https://wiki.pokexgames.com/images/a/af/Squirtle_Purple_Ninja_Pack_Direita.png'}, // Costas
                           { url: 'https://wiki.pokexgames.com/images/5/5d/Squirtle_Purple_Ninja_Pack_Costas.png'}  // Lado Direito
                       ]
                   },
                   {  
                       description: 'Squirtle Red Ninja Pack',
                       descriptionIMG: 'https://wiki.pokexgames.com/images/c/c1/Purple_Stripe.png',
                       obtain: {
                           url: 'https://wiki.pokexgames.com/index.php/Craft_Profissões_-_Estilista#Rank_E',
                           text: 'Estilista'
                       },
                       additionalImages: [
                           { url: 'https://wiki.pokexgames.com/images/1/13/Squirtle_Red_Ninja_Pack_Frente.png'}, // Frente
                           { url: 'https://wiki.pokexgames.com/images/1/1e/Squirtle_Red_Ninja_Pack_Esquerda.png'}, // Lado Esquerdo
                           { url: 'https://wiki.pokexgames.com/images/0/01/Squirtle_Red_Ninja_Pack_Costas.png'}, // Costas
                           { url: 'https://wiki.pokexgames.com/images/f/fd/Squirtle_Red_Ninja_Pack_Direita.png'}  // Lado Direito
                       ]
                   }
               ]
           },
       };
       const imageSearch = document.getElementById('imageSearch');
       const dropdown = document.getElementById('dropdown');
       const imageContainer = document.getElementById('imageContainer');
       imageSearch.addEventListener('input', function() {
           const searchValue = this.value.trim().toLowerCase();
           dropdown.innerHTML = ;
           if (searchValue) {
               Object.keys(imageList).forEach(imageName => {
                   if (imageName.toLowerCase().includes(searchValue)) {
                       const dropdownItem = document.createElement('div');
                       dropdownItem.classList.add('dropdown-item');
                       
                       const imgElement = document.createElement('img');
                       imgElement.src = imageList[imageName].imageUrl;
                       imgElement.alt = imageName;
                       
                       dropdownItem.appendChild(imgElement);
                       dropdownItem.appendChild(document.createTextNode(imageName));
                       
                       dropdownItem.addEventListener('click', function() {
                           showImageInfo(imageName);
                           dropdown.style.display = 'none';
                       });
                       dropdown.appendChild(dropdownItem);
                   }
               });
               dropdown.style.display = dropdown.childNodes.length ? 'block' : 'none';
           } else {
               dropdown.style.display = 'none';
           }
       });
       document.addEventListener('click', function(event) {
           if (!imageSearch.contains(event.target) && !dropdown.contains(event.target)) {
               dropdown.style.display = 'none';
           }
       });

function showImageInfo(imageName) {

   const imageInfo = imageList[imageName];
   let imagesHtml = `
           <img src="${imageInfo.imageUrl}" alt="${imageName}">
   `;
   imageInfo.variations.forEach((variation, index) => {
       imagesHtml += `
                <img src="${variation.additionalImages[0].url}" alt="Variation Image" class="variation-image" data-variation-index="${index}" style="width: ${variation.additionalImages[0].width}px;">

                   <img src="${variation.descriptionIMG}" alt="Description Image" style="margin-right: 5px; display: inline-block;"> 
                   
${variation.description}
Como Obter: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
       `;
   });
imagesHtml += '

';

   imageContainer.innerHTML = imagesHtml;
   imageContainer.classList.remove('hidden');
   // Alternar imagens ao clicar no botão de troca
   const swapButtons = document.querySelectorAll('.swap-button');
   swapButtons.forEach(button => {
       const index = button.getAttribute('data-variation-index');
       const variation = imageInfo.variations[index];
       let currentImageIndex = 0;
       button.addEventListener('click', () => {
           currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length;
           const variationImage = button.previousElementSibling; // Atualiza a imagem da variação
           variationImage.src = variation.additionalImages[currentImageIndex].url;
           variationImage.style.width = `${variation.additionalImages[currentImageIndex].width}px`;
       });
   });

}

   </script>

</body> </html>