Widget:Test2

De PokeXGames
Revisão de 14h56min de 27 de agosto de 2024 por Renee (discussão | contribs)
Ir para navegação Ir para pesquisar

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

<head>

   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Filtro de Mapas</title>
   <style>
       .hidden {
           display: none;
       }
       .image-container {
           display: flex;
           flex-wrap: wrap;
           gap: 10px;
       }
       .image-item {
           border: 1px solid #ccc;
           padding: 10px;
           width: 200px;
           text-align: center;
       }
       .image-info {
           margin-top: 10px;
           font-size: 14px;
       }
       .input-group {
           margin-bottom: 15px;
       }
       .maps__select {
           width: 100%;
           padding: 5px;
       }
       .maps__label {
           display: block;
           margin-bottom: 5px;
           font-weight: bold;
       }
       .filter-container {
           margin-top: 20px;
           margin-bottom: 10px;
       }
   </style>

</head>

<body>

   <form id="mapForm">
           <select id="mapType" class="maps__select">
               <option value="">Selecione um mapa</option>
               <option value="1">Mapa Vermelho</option>
               <option value="2">Mapa Verde</option>
               <option value="3">Mapa Roxo</option>
           </select>
           <label class="maps__label" for="mapType">Tipo de Mapa</label>
           <input type="checkbox" id="enableFilter">
           <label for="enableFilter" class="filter-label">Ativar filtro</label>
   </form>
   <script>
       const specificOptions = {
           1: { // Mapa Vermelho
               'Areia': [
                   { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', imageUrl: 'https://wiki.pokexgames.com/images/d/db/3780%2C_3326%2C_7.png', tag: 'Areia' },
               ],
               // Outras opções do Mapa Vermelho
           },
           2: { // Mapa Verde
               'Grama': [
                   { id: '102', local: 'Green Hills', coordinates: '3785, 3320, 7', imageUrl: 'https://wiki.pokexgames.com/images/1/12/Green_Hills.png', tag: 'Grama' },
               ],
               // Outras opções do Mapa Verde
           },
           3: { // Mapa Roxo
               'Pedra': [
                   { id: '103', local: 'Rocky Mountain', coordinates: '3790, 3315, 7', imageUrl: 'https://wiki.pokexgames.com/images/2/23/Rocky_Mountain.png', tag: 'Pedra' },
               ],
               // Outras opções do Mapa Roxo
           }
       };
       document.getElementById('enableFilter').addEventListener('change', function () {
           const filterSection = document.getElementById('filterSection');
           if (this.checked) {
               filterSection.classList.remove('hidden');
           } else {
               filterSection.classList.add('hidden');
           }
       });
       document.getElementById('searchIds').addEventListener('keypress', function (event) {
           if (event.key === 'Enter') {
               event.preventDefault();
               document.getElementById('filterButton').click();
           }
       });
       document.getElementById('mapType').addEventListener('change', function () {
           const selectedMapType = this.value;
           const specificOptionSelect = document.getElementById('specificOption');
           if (selectedMapType && specificOptions[selectedMapType]) {
               specificOptionSelect.innerHTML = '<option value="">Selecione uma opção</option>';
               const options = Object.keys(specificOptions[selectedMapType]);
               options.forEach(option => {
                   specificOptionSelect.innerHTML += `<option value="${option}">${option}</option>`;
               });
               document.getElementById('specificOptions').classList.remove('hidden');
           } else {
               document.getElementById('specificOptions').classList.add('hidden');
           }
       });
       document.getElementById('specificOption').addEventListener('change', function () {
           const selectedMapType = document.getElementById('mapType').value;
           const selectedOption = this.value;
           const imageContainer = document.getElementById('imageContainer');
           if (selectedMapType && selectedOption && specificOptions[selectedMapType][selectedOption]) {
               const images = specificOptions[selectedMapType][selectedOption];
               let imagesHtml = ;
               if (Array.isArray(images)) {
                   images.forEach(image => {
                       imagesHtml += `
                               <img src="${image.imageUrl}" alt="${selectedOption}">
                                   Número do Mapa: ${image.id} 
Local: ${image.local}
Coordenada: ${image.coordinates}
Tag(s): ${image.tag}
                       `;
                   });
               } else {
                   imagesHtml = `
                           <img src="${images.imageUrl}" alt="${selectedOption}">
                               Número do Mapa: ${images.id} 
Local: ${images.local}
Coordenada: ${images.coordinates}
                   `;
               }
               imageContainer.innerHTML = imagesHtml;
               imageContainer.classList.remove('hidden');
           } else {
               imageContainer.classList.add('hidden');
           }
       });
       document.getElementById('filterButton').addEventListener('click', function () {
           const searchIds = document.getElementById('searchIds').value.split(',').map(id => id.trim());
           const imageContainer = document.getElementById('imageContainer');
           if (searchIds.length > 0) {
               let imagesHtml = ;
               let allImages = [];
               // Recolhe todas as imagens que correspondem aos IDs
               Object.keys(specificOptions).forEach(mapType => {
                   const mapOptions = specificOptions[mapType];
                   Object.keys(mapOptions).forEach(option => {
                       const images = mapOptions[option].filter(image => searchIds.includes(image.id));
                       allImages = allImages.concat(images);
                   });
               });
               // Ordena as imagens pelo nome do local
               allImages.sort((a, b) => a.local.localeCompare(b.local));
               // Gera o HTML para exibir as imagens ordenadas
               allImages.forEach(image => {
                   imagesHtml += `
                           <img src="${image.imageUrl}" alt="Imagem ID ${image.id}">
                               Número do Mapa: ${image.id} 
Local: ${image.local}
Coordenada: ${image.coordinates}
Tag(s): ${image.tag}
                   `;
               });
               if (imagesHtml === ) {
                   imageContainer.innerHTML = 'Nenhum mapa encontrado com o(s) número(s) informado(s).';
               } else {
                   imageContainer.innerHTML = imagesHtml;
               }
               imageContainer.classList.remove('hidden');
           } else {
               imageContainer.classList.add('hidden');
           }
       });
   </script>

</body>

</html>