Widget:Test3

De PokeXGames
Revisão de 22h56min de 3 de setembro 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; }
       .tag-button.selected { background-color: lightblue; }
       .image-item { margin-bottom: 10px; }
       .image-item img { max-width: 200px; }
       .filter-section, .tag-section { margin-bottom: 20px; }
   </style>

</head> <body>

       <label for="mapType">Tipo de Mapa:</label>
       <select id="mapType">
           <option value="">Selecione um Tipo de Mapa</option>
           <option value="1">Tipo 1</option>
       </select>
       
       <label for="specificOption">Local do X:</label>
       <select id="specificOption">
           <option value="">Selecione um Local do X</option>
       </select>
   <button id="filterButton" class="hidden">Filtrar</button>
   <script>
       const specificOptions = {
           1: {
               'Areia': [
                   { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', tags: ['Areia', 'Água', 'Grama', 'Árvore'], imageUrl: 'https://wiki.pokexgames.com/images/4/4c/Mapas_de_ADV_VERMELHO_-_3780%2C_3326%2C_7.webp' },
                   { id: '102', local: 'Wildwind Island', coordinates: '3969, 3300, 7', tags: ['Areia', 'Terra', 'Árvore'], imageUrl: 'https://wiki.pokexgames.com/images/5/58/Mapas_de_ADV_VERMELHO_-_3969%2C_3300%2C_7.webp' },
                   { id: '103', local: 'Wildwind Island', coordinates: '4002, 3320, 7', tags: ['Areia', 'Árvore', 'Pedra'], imageUrl: 'https://wiki.pokexgames.com/images/0/07/Mapas_de_ADV_VERMELHO_-_4002%2C_3320%2C_7.webp' },
                   { id: '104', local: 'Saffron', coordinates: '4009, 3601, 7', tags: ['Areia', 'Árvore', 'Terra', 'Água'], imageUrl: 'https://wiki.pokexgames.com/images/f/f5/Mapas_de_ADV_VERMELHO_-_4009%2C_3601%2C_7.webp' },
                   { id: '105', local: 'Hurricane Island', coordinates: '3750, 3450, 7', tags: ['Areia', 'Grama'], imageUrl: 'https://wiki.pokexgames.com/images/6/6b/Mapas_de_ADV_VERMELHO_-_3750%2C_3450%2C_7.webp' }
               ],
               'Gelo': [
                   { id: '201', local: 'Snowy Hill', coordinates: '3050, 3575, 7', tags: ['Gelo', 'Árvore'], imageUrl: 'https://wiki.pokexgames.com/images/a/aa/Mapas_de_ADV_VERMELHO_-_3050%2C_3575%2C_7.webp' },
                   { id: '202', local: 'Frozen Lake', coordinates: '2900, 3400, 7', tags: ['Gelo', 'Água'], imageUrl: 'https://wiki.pokexgames.com/images/2/2a/Mapas_de_ADV_VERMELHO_-_2900%2C_3400%2C_7.webp' }
               ],
               // Adicione outros tipos de mapas e locais aqui
           }
       };
       // Atualiza o dropdown de opções baseado no Tipo de Mapa selecionado
       function updateSpecificOptions() {
           const mapType = document.getElementById('mapType').value;
           const specificOptionSelect = document.getElementById('specificOption');
           specificOptionSelect.innerHTML = '<option value="">Selecione um Local do X</option>'; // Limpa e define opção padrão
           if (mapType) {
               const options = Object.keys(specificOptions[mapType]);
               options.forEach(option => {
                   const opt = document.createElement('option');
                   opt.value = option;
                   opt.textContent = option;
                   specificOptionSelect.appendChild(opt);
               });
           }
           document.getElementById('tagSection').classList.add('hidden');
           document.getElementById('imageContainer').classList.add('hidden');
       }
       // Atualiza o dropdown de tags baseado no Tipo de Mapa e Local do X selecionados
       function updateTagButtons() {
           const mapType = document.getElementById('mapType').value;
           const specificOption = document.getElementById('specificOption').value;
           const tagButtonsContainer = document.getElementById('tagButtons');
           tagButtonsContainer.innerHTML = ;
           if (mapType && specificOption) {
               const tags = specificOptions[mapType][specificOption].map(option => option.tags).flat();
               const uniqueTags = [...new Set(tags)];
               uniqueTags.forEach(tag => {
                   const button = document.createElement('button');
                   button.classList.add('tag-button');
                   button.textContent = tag;
                   tagButtonsContainer.appendChild(button);
               });
               document.getElementById('tagSection').classList.remove('hidden');
               document.getElementById('filterButton').classList.remove('hidden');
           } else {
               document.getElementById('tagSection').classList.add('hidden');
               document.getElementById('filterButton').classList.add('hidden');
           }
       }
       // Atualiza o estado dos botões de tags ao selecionar uma tag
       function toggleTagButton(e) {
           if (e.target.classList.contains('tag-button')) {
               e.target.classList.toggle('selected');
               filterImages();
           }
       }
       // Filtra as imagens baseadas no Tipo de Mapa, Local do X e Tags selecionadas
       function filterImages() {
           const mapType = document.getElementById('mapType').value;
           const specificOption = document.getElementById('specificOption').value;
           const selectedTags = Array.from(document.querySelectorAll('.tag-button.selected')).map(button => button.textContent);
           const imageContainer = document.getElementById('imageContainer');
           imageContainer.innerHTML = ;
           if (mapType && specificOption) {
               const images = specificOptions[mapType][specificOption] || [];
               const filteredImages = images.filter(image => {
                   if (selectedTags.length > 0) {
                       return selectedTags.some(tag => image.tags.includes(tag));
                   }
                   return true; 
               });
               filteredImages.forEach(image => {
                   const div = document.createElement('div');
                   div.classList.add('image-item');
                   div.innerHTML = `
                       <img src="${image.imageUrl}" alt="Imagem do Mapa">
                           Número do Mapa: ${image.id} 
Local: ${image.local}
Coordenada: ${image.coordinates}
Tag(s): ${image.tags.join(', ') || 'Nenhuma'}
                   `;
                   imageContainer.appendChild(div);
               });
               imageContainer.classList.remove('hidden');
           } else {
               imageContainer.classList.add('hidden');
           }
       }
       // Inicializa os eventos
       document.getElementById('mapType').addEventListener('change', () => {
           updateSpecificOptions();
           updateTagButtons();
       });
       document.getElementById('specificOption').addEventListener('change', updateTagButtons);
       document.getElementById('filterButton').addEventListener('click', filterImages);
       document.getElementById('tagButtons').addEventListener('click', toggleTagButton);
   </script>

</body> </html>