-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.html
More file actions
252 lines (213 loc) · 6.71 KB
/
start.html
File metadata and controls
252 lines (213 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SovereignSearch</title>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.6.2"></script>
<script>
const savedTheme = localStorage.getItem('appTheme') || 'system';
document.documentElement.dataset.theme = savedTheme;
window.addEventListener('storage', e => {
if (e.key === 'appTheme') {
document.documentElement.dataset.theme = e.newValue || 'system';
}
});
</script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="searchPage">
<h2>SovereignSearch</h2>
<input
id="searchBox"
type="text"
placeholder="Search SCID, dURL, name or description..."
disabled
/>
<div class="filters">
<label>Min rating:</label>
<input id="minRating" type="range" min="0" max="99" step="1" value="0">
<span id="minRatingVal">0</span>
<label>Sort:</label>
<select id="sortMode">
<option value="name_asc">Name A → Z</option>
<option value="name_desc">Name Z → A</option>
<option value="newest">Newest SCID</option>
<option value="oldest">Oldest SCID</option>
</select>
</div>
<div id="status">Fetching indexed SCIDs...</div>
<div id="results"></div>
</div>
<script>
const apiBase = "http://127.0.0.1:8099/api";
let allResults = [];
let fuse;
let minRating = 0;
/* -----------------------------
FETCH SCID DATA
----------------------------- */
async function fetchSCIDData(scid) {
try {
const resp = await fetch(`${apiBase}/scvarsbyheight?scid=${scid}`);
if (!resp.ok) return null;
const data = await resp.json();
if (!data.variables) return null;
let dURL = scid;
let nameHdr = scid;
let descrHdr = "";
let iconURL = "";
let createdHeight = Infinity;
const ratings = [];
data.variables.forEach(v => {
const key = v.Key;
const val = v.Value;
if (key === "dURL" && val) dURL = val;
else if (key === "nameHdr" && val) nameHdr = val;
else if (key === "descrHdr" && val) descrHdr = val;
else if (key === "iconURLHdr" && val) iconURL = val;
else if (typeof key === "string" && key.startsWith("dero1")) {
const [rating, height] = String(val).split("_");
const h = Number(height);
ratings.push({ rating: Number(rating), height: h });
if (h < createdHeight) createdHeight = h;
}
});
const likes = ratings.filter(r => r.rating >= 50).length;
const dislikes = ratings.filter(r => r.rating < 50).length;
const average = ratings.length
? Math.round(ratings.reduce((a, r) => a + r.rating, 0) / ratings.length)
: 0;
return {
scid,
dURL,
nameHdr,
descrHdr,
iconURL,
likes,
dislikes,
average,
createdHeight: createdHeight === Infinity ? 0 : createdHeight
};
} catch (err) {
console.error("SCID fetch error", err);
return null;
}
}
/* -----------------------------
FETCH INDEXED SCIDS
----------------------------- */
async function fetchAllSCIDs() {
const resp = await fetch(`${apiBase}/indexedscs`);
if (!resp.ok) throw new Error("Indexed SCID fetch failed");
const data = await resp.json();
return Object.keys(data.indexedscs || {});
}
/* -----------------------------
SORTING
----------------------------- */
function sortResults(list, mode) {
const arr = [...list];
switch (mode) {
case "name_asc":
return arr.sort((a, b) =>
a.nameHdr.localeCompare(b.nameHdr, undefined, { sensitivity: "base" })
);
case "name_desc":
return arr.sort((a, b) =>
b.nameHdr.localeCompare(a.nameHdr, undefined, { sensitivity: "base" })
);
case "newest":
return arr.sort((a, b) => b.createdHeight - a.createdHeight);
case "oldest":
return arr.sort((a, b) => a.createdHeight - b.createdHeight);
default:
return arr;
}
}
/* -----------------------------
RENDER RESULTS
----------------------------- */
function renderResults(results) {
const container = document.getElementById("results");
container.innerHTML = "";
const mode = document.getElementById("sortMode").value;
results = sortResults(results, mode);
results
.filter(r => r.average >= minRating)
.forEach(r => {
const div = document.createElement("div");
div.className = "result";
const iconHTML = `
<div class="icon-slot">
${r.iconURL ? `<img class="icon" src="${r.iconURL}" alt="">` : ''}
</div>
`;
div.innerHTML = `
${iconHTML}
<div class="content">
<div class="url">${r.dURL}</div>
<div class="nameHdr" onclick="handleSCIDClick('${r.scid}')">${r.nameHdr}</div>
<div class="scid" onclick="handleSCIDClick('${r.scid}')">${r.scid}</div>
<div class="descr">${r.descrHdr}</div>
<div class="rating">👍 ${r.likes} 👎 ${r.dislikes} ⭐ ${r.average}</div>
</div>
`;
container.appendChild(div);
});
}
/* -----------------------------
EVENTS
----------------------------- */
function handleSCIDClick(scid) {
if (!window.electronAPI?.selectSCID) return;
window.electronAPI.selectSCID(scid);
}
function filterResults(query) {
if (!query.trim()) return renderResults(allResults);
renderResults(fuse.search(query).map(r => r.item));
}
document.getElementById("searchBox").addEventListener("input", e => filterResults(e.target.value));
document.getElementById("minRating").addEventListener("input", e => {
minRating = Number(e.target.value);
document.getElementById("minRatingVal").textContent = minRating;
renderResults(allResults);
});
document.getElementById("sortMode").addEventListener("change", () => {
renderResults(allResults);
});
/* -----------------------------
BOOTSTRAP
----------------------------- */
(async () => {
const status = document.getElementById("status");
const searchBox = document.getElementById("searchBox");
try {
const scids = await fetchAllSCIDs();
let index = 0;
const concurrency = 5;
async function worker() {
while (index < scids.length) {
const scid = scids[index++];
const res = await fetchSCIDData(scid);
if (res) allResults.push(res);
status.textContent = `Loaded ${allResults.length} / ${scids.length} SCIDs...`;
}
}
await Promise.all(Array(concurrency).fill().map(worker));
fuse = new Fuse(allResults, {
keys: ["scid", "dURL", "nameHdr", "descrHdr", "average"],
threshold: 0.25,
ignoreLocation: true
});
status.textContent = `✅ Loaded ${allResults.length} SCIDs`;
searchBox.disabled = false;
renderResults(allResults);
} catch (err) {
console.error(err);
status.textContent = "❌ Failed loading SCIDs, turn the Gnomon indexer on..";
}
})();
</script>
</body>
</html>