Widget:Test: mudanças entre as edições
Ir para navegação
Ir para pesquisar
`).join("")}
`).join("")}
Sem resumo de edição |
Sem resumo de edição |
||
Linha 1: | Linha 1: | ||
/ | <!DOCTYPE html> | ||
<html lang="pt-BR"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |||
<title>Item Search</title> | |||
<style> | |||
.suggest-icon { | |||
max-width: 20px; | |||
max-height: 20px; | |||
} | |||
#suggest { | |||
max-height: 300px; | |||
max-width: 300px; | |||
overflow-y: scroll; | |||
overflow-x: hidden; | |||
} | |||
.item-name { | |||
display: flex; | |||
align-items: center; | |||
} | |||
.item-name-icon { | |||
max-width: 30px; | |||
margin-right: 8px; | |||
} | |||
.craft p { | |||
margin: 0; | |||
} | |||
.materials { | |||
display: flex; | |||
align-items: center; | |||
flex-wrap: wrap; | |||
gap: 8px; | |||
} | |||
.item-from-craft { | |||
display: flex; | |||
align-items: center; | |||
padding: 8px 12px; | |||
border: 1px solid #ccc; | |||
border-radius: 8px; | |||
} | |||
.material-icon-container { | |||
display: flex; | |||
align-items: center; | |||
justify-content: center; | |||
width: 30px; | |||
height: 30px; | |||
} | |||
</style> | |||
</head> | |||
<body> | |||
<input type="text" id="search" placeholder="Busque um item..." /> | |||
<div id="suggest"></div> | |||
<div id="content"></div> | |||
<script> | |||
// Base de dados local | |||
const allData = [ | const allData = [ | ||
{ | { | ||
Linha 8: | Linha 70: | ||
"link": "https://wiki.pokexgames.com/index.php/Bag_Of_Pollem", | "link": "https://wiki.pokexgames.com/index.php/Bag_Of_Pollem", | ||
"isNightmare": false, | "isNightmare": false, | ||
"whoDrops":[ | "whoDrops": [ | ||
{ | |||
"id": 1, | |||
"icon": "https://wiki.pokexgames.com/images/5/5c/001-Bulbasaur.png", | |||
"link": "https://wiki.pokexgames.com/index.php/Bulbasaur", | |||
"name": "Bulbasaur" | |||
}, | |||
// outros dados omitidos para simplicidade... | |||
] | |||
}, | |||
{ | { | ||
"id": 1884, | "id": 1884, | ||
Linha 199: | Linha 100: | ||
"id": 532 | "id": 532 | ||
}, | }, | ||
// | // outros materiais omitidos para simplicidade... | ||
] | ] | ||
} | } | ||
Linha 212: | Linha 113: | ||
]; | ]; | ||
const search = document.getElementById("search"); | const search = document.getElementById("search"); | ||
const suggest = document.getElementById("suggest"); | const suggest = document.getElementById("suggest"); | ||
const content = document.getElementById("content"); | const content = document.getElementById("content"); | ||
const clearSuggestions = () => { | const clearSuggestions = () => { | ||
suggest.innerHTML = ""; | |||
}; | }; | ||
const setItem = (id) => { | const setItem = (id) => { | ||
const data = allData.find((data) => data.id == id); | |||
if (!data) return; | |||
clearSuggestions(); | |||
content.innerHTML = ` | |||
<div class="item-name"> | |||
<img class="item-name-icon" src="${data.icon}" /> | |||
<span>${data.name}</span> | |||
</div>`; | |||
if (data.craft) { | |||
content.innerHTML += ` | |||
<h3>Craft</h3> | |||
<div class="craft"> | |||
<p><b>Quantidade:</b> ${data.craft.quantity}</p> | |||
<p><b>Skill:</b> ${data.craft.skill} - Rank ${data.craft.rank}</p> | |||
<p><b>Tempo de Craft:</b> ${data.craft.cooldownText}</p> | |||
<p><b>Profissão:</b> ${data.craft.profession}</p> | |||
<p><b>Materiais:</b></p> | |||
<div class="materials"> | |||
${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>`; | |||
</div>` | } | ||
const materialTo = allData.filter((item) => { | |||
if (!item.craft?.materials) return false; | |||
return item.craft.materials.some((m) => m.id == id); | |||
}); | |||
if (materialTo.length) { | |||
content.innerHTML += ` | |||
<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) => { | document.addEventListener("click", (e) => { | ||
if (e.target.classList.contains("suggest-item")) { | |||
e.preventDefault(); | |||
setItem(e.target.dataset.itemId); | |||
} | |||
}); | }); | ||
search.addEventListener("input", () => { | search.addEventListener("input", () => { | ||
const value = search.value?.toLowerCase(); | |||
suggest.innerHTML = ""; | |||
allData.forEach((data) => { | |||
if (data.name.toLowerCase().includes(value)) { | |||
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 das 02h23min de 23 de agosto 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>Item Search</title> <style> .suggest-icon { max-width: 20px; max-height: 20px; }
#suggest { max-height: 300px; max-width: 300px; overflow-y: scroll; overflow-x: hidden; }
.item-name { display: flex; align-items: center; }
.item-name-icon { max-width: 30px; margin-right: 8px; }
.craft p { margin: 0; }
.materials { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.item-from-craft { display: flex; align-items: center; padding: 8px 12px; border: 1px solid #ccc; border-radius: 8px; }
.material-icon-container { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; } </style>
</head> <body>
<input type="text" id="search" placeholder="Busque um item..." />
<script> // Base de dados local const allData = [ { "id": 18, "name": "Bag of Pollen", "icon": "https://wiki.pokexgames.com/images/b/bc/BagOfPollem.png", "link": "https://wiki.pokexgames.com/index.php/Bag_Of_Pollem", "isNightmare": false, "whoDrops": [ { "id": 1, "icon": "https://wiki.pokexgames.com/images/5/5c/001-Bulbasaur.png", "link": "https://wiki.pokexgames.com/index.php/Bulbasaur", "name": "Bulbasaur" }, // outros dados omitidos para simplicidade... ] }, { "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 omitidos para simplicidade... ] } }, { "id": 1912, "name": "Catcher Token", "icon": "https://wiki.pokexgames.com/images/f/fd/Catcher_Token.png", "link": "https://wiki.pokexgames.com/index.php/Tokens", "isNightmare": false } ];
const search = document.getElementById("search"); const suggest = document.getElementById("suggest"); const content = document.getElementById("content");
const clearSuggestions = () => { suggest.innerHTML = ""; };
const setItem = (id) => { const data = allData.find((data) => data.id == id); if (!data) return; clearSuggestions();
content.innerHTML = `
<img class="item-name-icon" src="${data.icon}" />
${data.name}
`;
if (data.craft) { content.innerHTML += `
Craft
Quantidade: ${data.craft.quantity}
Skill: ${data.craft.skill} - Rank ${data.craft.rank}
Tempo de Craft: ${data.craft.cooldownText}
Profissão: ${data.craft.profession}
Materiais:
${data.craft.materials.map((material) => `
${material.quantity}x ${material.name}
`;
}
const materialTo = allData.filter((item) => { if (!item.craft?.materials) return false; return item.craft.materials.some((m) => m.id == id); });
if (materialTo.length) { content.innerHTML += `
Usado para craftar
${materialTo.map((material) => `
${material.name}
`;
} };
document.addEventListener("click", (e) => { if (e.target.classList.contains("suggest-item")) { e.preventDefault(); setItem(e.target.dataset.itemId); } });
search.addEventListener("input", () => { const value = search.value?.toLowerCase(); suggest.innerHTML = ""; allData.forEach((data) => { if (data.name.toLowerCase().includes(value)) { 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>