-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlist.html
More file actions
437 lines (385 loc) · 14.9 KB
/
list.html
File metadata and controls
437 lines (385 loc) · 14.9 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Click Sounds Index</title>
<link rel="icon" href="./.images/favicon.png" type="image/png"/>
<meta property="og:title" content="Click Sounds: List"/>
<meta property="og:description" content="A list of sounds from the Click Sounds Index"/>
<meta property="og:image" content="https://raw.githubusercontent.com/clicksounds/clicks/refs/heads/main/.images/fullres-logo.png"/>
<meta property="og:url" content="https://clicksounds.xyz/list.html"/>
<meta property="og:type" content="website"/>
<script src="/.navbar/navbarFetch.js"></script>
<style>
/* Reset and base styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Body and background styles */
body {
font-family: Arial, sans-serif;
color: #fff;
background-color: #1e1e2f;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
overflow: hidden;
}
/* Navbar styles */
nav {
width: 100%;
background-color: rgba(0, 0, 0, 0.8);
padding: 10px 20px;
position: absolute;
top: 0;
left: 0;
z-index: 10;
box-sizing: border-box;
}
/* Navigation links */
nav a {
color: #00aaff;
text-decoration: none;
font-size: 1.2em;
margin-right: 20px;
display: inline-block;
transition: all 0.3s ease;
}
nav a:hover {
background: #00aaff;
color: #fff;
padding: 5px 10px;
border-radius: 5px;
}
/* Main content styles */
h1 {
font-size: 2.5em;
margin-top: 100px;
}
/* Filter form styles */
.filter-container {
margin: 20px 0;
padding: 20px;
background-color: rgba(0, 0, 0, 0.7);
border-radius: 10px;
}
.filter-container input,
.filter-container select {
padding: 10px;
font-size: 1em;
margin: 10px 5px;
border-radius: 5px;
border: 1px solid #00aaff;
background-color: rgba(255, 255, 255, 0.2);
color: #fff;
}
.filter-container button {
padding: 10px 20px;
font-size: 1.2em;
background-color: #00aaff;
border: none;
color: #fff;
cursor: pointer;
border-radius: 5px;
}
.filter-container button:hover {
background-color: #0088cc;
}
/* Sound list container */
.sound-list {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 30px;
max-height: 400px;
overflow-y: auto;
padding: 10px;
}
::-webkit-scrollbar {
display: none;
}
/* changed sound-item from div to button */
.sound-item {
margin: 10px;
padding: 15px;
background-color: rgba(0, 0, 0, 0.7);
color: #fff;
border-radius: 5px;
width: 80%;
text-align: center;
transition: background-color 0.3s;
border: none;
cursor: pointer;
font-size: 1.1em;
}
.sound-item:disabled {
opacity: 0.5;
cursor: not-allowed;
background-color: rgba(0, 0, 0, 0.4);
color: #888;
}
.sound-item:hover {
background-color: #00aaff;
}
.sound-item:disabled:hover {
background-color: rgba(0, 0, 0, 0.4);
color: #888;
}
/* No results message */
.no-results {
color: #ff6347;
font-size: 1.5em;
margin-top: 20px;
}
#typeSelect {
border-radius: 5px;
border: 1px solid #00aaff;
background-color: rgba(255, 255, 255, 0.2);
color: rgb(255, 255, 255);
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
#typeSelect option {
border-radius: 5px;
border: 1px solid #00aaff;
background-color: rgba(0, 0, 0, 0.1);
color: black;
}
#typeSelect:focus option {
background-color: rgba(0, 0, 0, 0.2);
}
#categorySelect {
border-radius: 5px;
border: 1px solid #00aaff;
background-color: rgba(255, 255, 255, 0.2);
color: rgb(255, 255, 255);
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
#categorySelect option {
border-radius: 5px;
border: 1px solid #00aaff;
background-color: rgba(0, 0, 0, 0.1);
color: black;
}
#categorySelect:focus option {
background-color: rgba(0, 0, 0, 0.2);
}
</style>
</head>
<body>
<div id="navbar"></div>
<h1>Click Sounds Index</h1>
<!-- Filter Options -->
<div class="filter-container">
<input
type="text"
id="searchBar"
placeholder="Search for sounds..."
onkeyup="filterSounds()"
/>
<select id="categorySelect" onchange="filterSounds()">
<option value="">Select Category</option>
<option value="Meme">Meme</option>
<option value="Useful">Useful</option>
</select>
<script>
document.addEventListener("DOMContentLoaded", function () {
const selectElement = document.getElementById("categorySelect");
const defaultOption = selectElement.querySelector('option[value=""]');
selectElement.addEventListener("change", function () {
if (selectElement.value === "") {
selectElement.selectedIndex = 1;
}
});
defaultOption.style.display = "none";
});
</script>
<select id="typeSelect" onchange="filterSounds()">
<option value="">Select Type</option>
<option value="Clicks">Clicks</option>
<option value="Releases">Releases</option>
<option value="Both">Both</option>
</select>
<script>
document.addEventListener("DOMContentLoaded", function () {
const selectElement = document.getElementById("typeSelect");
const defaultOption = selectElement.querySelector('option[value=""]');
selectElement.addEventListener("change", function () {
if (selectElement.value === "") {
selectElement.selectedIndex = 1;
}
});
defaultOption.style.display = "none";
});
</script>
<button onclick="filterSounds()">Apply Filters</button>
</div>
<!-- Sounds List -->
<div class="sound-list" id="soundList"></div>
<div class="no-results" id="noResults" style="display: none;">
No sounds found matching your criteria.
</div>
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js"></script>
<script>
const indexListDataPath = "./index_list.json";
async function loadSoundsData() {
const response = await fetch(indexListDataPath);
return await response.json();
}
async function downloadPack(category, id) {
const zip = new JSZip();
async function addFilesToZip(path) {
const apiUrl = `https://api.github.com/repos/clicksounds/clicks/contents/${category}/${id}/${path}?ref=main`;
const res = await fetch(apiUrl);
if (!res.ok) throw new Error(`Failed to fetch ${apiUrl}.`);
const entries = await res.json();
for (const entry of entries) {
if (entry.type === "file") {
const fileRes = await fetch(entry.download_url);
const blob = await fileRes.blob();
const relPath = entry.path.replace(`${category}/${id}/`, "");
zip.file(relPath, blob);
} else if (entry.type === "dir") {
await addFilesToZip(entry.path.replace(`${category}/${id}/`, ""));
}
}
}
try {
await addFilesToZip("");
const content = await zip.generateAsync({ type: "blob" });
const a = document.createElement("a");
a.href = URL.createObjectURL(content);
a.download = `${id}.packgen.zip`;
a.click();
} catch (err) {
console.error(err);
alert("Failed to download pack: " + err.message + "\n\nThis is not your fault. Please report this issue in the Click Sounds Discord server so it can be fixed.");
}
}
function displaySounds(filteredSounds) {
const soundList = document.getElementById("soundList");
soundList.innerHTML = "";
if (filteredSounds.length === 0) {
document.getElementById("noResults").style.display = "block";
} else {
document.getElementById("noResults").style.display = "none";
filteredSounds.forEach((sound) => {
const btn = document.createElement("button");
btn.classList.add("sound-item");
btn.textContent = sound.name;
btn.onclick = async () => {
btn.disabled = true;
const originalText = btn.textContent;
btn.textContent = "Downloading...";
try {
await downloadPack(sound.type, sound.id);
} finally {
setTimeout(() => {
btn.disabled = false;
btn.textContent = originalText;
}, 5000);
}
};
soundList.appendChild(btn);
});
}
}
// Function to filter sounds based on user input
let cachedSoundsData = null;
async function getCachedSoundsData() {
if (!cachedSoundsData) {
const response = await fetch(indexListDataPath);
cachedSoundsData = await response.json();
}
return cachedSoundsData;
}
async function filterSounds() {
const searchQuery = document
.getElementById("searchBar")
.value.toLowerCase();
const categoryFilter = document.getElementById("categorySelect").value;
const typeFilter = document.getElementById("typeSelect").value;
const soundsData = await getCachedSoundsData();
let filteredSounds = [];
for (let category in soundsData) {
if (categoryFilter && category !== categoryFilter) continue;
soundsData[category].forEach((sound) => {
const matchesSearch = sound.name.toLowerCase().includes(searchQuery);
const matchesType =
typeFilter === "Both" ||
sound.folders.includes(typeFilter) ||
(typeFilter === "" && sound.folders.length > 0);
if (matchesSearch && matchesType) {
filteredSounds.push({ ...sound, category });
}
});
}
displaySounds(filteredSounds);
}
// New: allow direct download via query string:
// Examples:
// list.html?useful=author.packid
// list.html?meme=author.packid
async function handleDirectDownloadFromQuery() {
try {
const params = new URLSearchParams(window.location.search);
// check for keys 'useful' or 'meme' (case-insensitive)
let foundKey = null;
let rawId = null;
for (const key of params.keys()) {
const lk = key.toLowerCase();
if (lk === "useful" || lk === "meme") {
foundKey = lk; // 'useful' or 'meme'
rawId = params.get(key);
break;
}
}
if (!foundKey || !rawId) return; // nothing to do
const category = foundKey === "useful" ? "Useful" : "Meme";
const id = rawId.trim();
if (!id) return;
// Ensure index data is loaded
const soundsData = await getCachedSoundsData();
// Check for the requested pack in the specified category
const categoryList = soundsData[category];
if (!categoryList) {
alert(`Category "${category}" not found.`);
return;
}
const match = categoryList.find((s) => s.id === id || (s.fully_qualified_id && s.fully_qualified_id === id));
if (!match) {
// If there's no exact id match, try a fallback: find by name or author.packid formed differently
const fuzzy = categoryList.find((s) => s.id === id || s.name === id || `${s.author}.${s.id}` === id || `${s.author}.${s.packid}` === id);
if (fuzzy) {
await downloadPack(category, fuzzy.id);
return;
}
alert(`Pack "${id}" not found in category "${category}".`);
console.warn("Direct download failed: pack not found", { category, id });
return;
}
// Trigger the download
await downloadPack(category, match.id);
} catch (err) {
console.error("Error handling direct download from query:", err);
}
}
// Run initial UI population and then check for direct-download query params.
window.onload = async () => {
await filterSounds();
// If the user navigated here with ?useful=... or ?meme=..., attempt direct download.
handleDirectDownloadFromQuery();
};
</script>
</body>
</html>