Skip to content

Commit e8d38ce

Browse files
committed
Add search feature
Adds a search feature
1 parent a45d6b4 commit e8d38ce

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

factory_builder/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,13 @@ function render_recipe(end_item)
265265
recipes_rendered[end_item] = div;
266266
}
267267

268-
render_recipe(window.location.search.substring(1));
268+
const item = window.location.search.substring(1);
269+
if (!item) {
270+
window.location.href = "./search.html";
271+
} else {
272+
render_recipe(item);
273+
}
274+
269275

270276
const max = (a,b) => (a > b) ? a : b;
271277
const min = (a,b) => (a < b) ? a : b;

factory_builder/search.html

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Search Recipes</title>
6+
<style>
7+
body {
8+
font-family: sans-serif;
9+
margin: 2rem;
10+
background: #121212;
11+
color: white;
12+
}
13+
14+
input {
15+
width: 100%;
16+
font-size: 1.2rem;
17+
padding: 0.5rem;
18+
border-radius: 5px;
19+
border: none;
20+
margin-bottom: 1rem;
21+
}
22+
23+
.results {
24+
display: flex;
25+
flex-wrap: wrap;
26+
gap: 1rem;
27+
}
28+
29+
.item {
30+
display: flex;
31+
flex-direction: column;
32+
align-items: center;
33+
text-align: center;
34+
width: 110px;
35+
padding: 0.5rem;
36+
background: #1e1e1e;
37+
border-radius: 8px;
38+
text-decoration: none;
39+
color: white;
40+
transition: transform 0.2s;
41+
}
42+
43+
.item:hover {
44+
transform: scale(1.05);
45+
background: #2e2e2e;
46+
}
47+
48+
.item img {
49+
width: 64px;
50+
height: 64px;
51+
margin-bottom: 0.5rem;
52+
}
53+
</style>
54+
</head>
55+
<body>
56+
<h1>Search Recipes</h1>
57+
<input type="text" id="search" placeholder="Type an item name...">
58+
<div class="results" id="results"></div>
59+
60+
<script src="data.js"></script>
61+
<script>
62+
const searchInput = document.getElementById('search');
63+
const resultsDiv = document.getElementById('results');
64+
65+
const seenItems = new Set();
66+
67+
for (const type in RECIPES) {
68+
for (const recipe of RECIPES[type]) {
69+
if (recipe.output) seenItems.add(recipe.output);
70+
if (recipe.out) seenItems.add(recipe.out);
71+
}
72+
}
73+
74+
const allItems = Array.from(seenItems).sort((a, b) => {
75+
const nameA = ITEM_TRANSLATE[a] || a;
76+
const nameB = ITEM_TRANSLATE[b] || b;
77+
return nameA.localeCompare(nameB);
78+
});
79+
80+
function displayResults(items) {
81+
resultsDiv.innerHTML = '';
82+
for (const item of items) {
83+
const link = document.createElement('a');
84+
link.href = `./?${item}`;
85+
link.className = 'item';
86+
87+
const img = document.createElement('img');
88+
img.src = `cdn/minecraft_${item}.png`;
89+
img.alt = item;
90+
91+
const label = document.createElement('div');
92+
label.textContent = ITEM_TRANSLATE[item] || item.replaceAll('_', ' ');
93+
94+
link.appendChild(img);
95+
link.appendChild(label);
96+
resultsDiv.appendChild(link);
97+
}
98+
}
99+
100+
searchInput.addEventListener('input', () => {
101+
const q = searchInput.value.trim().toLowerCase();
102+
const filtered = allItems.filter(id => {
103+
const name = (ITEM_TRANSLATE[id] || id).toLowerCase();
104+
return name.includes(q);
105+
});
106+
displayResults(filtered);
107+
});
108+
109+
displayResults(allItems);
110+
</script>
111+
</body>
112+
</html>

0 commit comments

Comments
 (0)