-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1202 lines (991 loc) · 38.3 KB
/
Copy pathscript.js
File metadata and controls
1202 lines (991 loc) · 38.3 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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// script.js
let puzzleData = [];
let filteredData = [];
let selectedPuzzles = [];
let exportMode = false;
let discordId = localStorage.getItem("discordId") || "";
let clearData = [];
let currentTab = "search";
let lists = JSON.parse(localStorage.getItem("puzzleLists") || "{}");
let searchDebounceTimer = null;
let devModeEnabled = false;
function init() {
updateDiscordIdDisplay();
fetch("sh-dump/puzzles.json")
.then((response) => response.json())
.then((data) => {
puzzleData = data.filter((puzzle) => puzzle.ID !== "00000" && puzzle.Datacenter !== "-" && puzzle.Datacenter !== "");
filteredData = filterData();
displayData(filteredData);
createDatacenterToggles();
createDistrictToggles();
createTagToggles();
updatePuzzlesFound();
// Initialize hub mode dropdowns
populateHubWorlds();
// Display lists
displayLists();
})
.catch((error) => {
console.error("Error fetching data:", error);
});
fetchClearData();
// Add dev mode listener to exclude input
const excludeInput = document.getElementById("excludeInput");
excludeInput.addEventListener("keydown", handleExcludeInputKeydown);
}
function switchTab(tabName) {
currentTab = tabName;
// Update tab buttons
document.querySelectorAll(".tab-button").forEach((btn) => {
btn.classList.remove("active");
});
event.target.classList.add("active");
// Hide all tabs
document.getElementById("searchTab").style.display = "none";
document.getElementById("hubModeTab").style.display = "none";
document.getElementById("listsTab").style.display = "none";
// Show selected tab
if (tabName === "search") {
document.getElementById("searchTab").style.display = "block";
} else if (tabName === "hub") {
document.getElementById("hubModeTab").style.display = "block";
} else if (tabName === "lists") {
document.getElementById("listsTab").style.display = "block";
displayLists();
}
}
function fetchClearData() {
if (discordId) {
fetch("sh-dump/clears.json")
.then((response) => response.json())
.then((data) => {
clearData = data.filter((clear) => clear.jumper === discordId);
displayData(filteredData);
})
.catch((error) => {
console.error("Error fetching clear data:", error);
});
}
}
function filterData() {
const minRating = document.getElementById("minRating").value;
const maxRating = document.getElementById("maxRating").value;
const searchQuery = document.getElementById("searchInput").value.toLowerCase();
const excludeQuery = document.getElementById("excludeInput").value.toLowerCase();
const selectedDatacenters = Array.from(document.querySelectorAll("#toggleContainer input:checked")).map((checkbox) => checkbox.dataset.datacenter);
const selectedDistricts = Array.from(document.querySelectorAll("#districtToggleContainer input:checked")).map((checkbox) => checkbox.dataset.district);
const selectedTags = Array.from(document.querySelectorAll("#tagToggleContainer input:checked")).map((checkbox) => checkbox.dataset.tag);
return puzzleData.filter((puzzle) => {
const rating = isNaN(parseInt(puzzle.Rating)) ? 1 : parseInt(puzzle.Rating);
const builderMatch = puzzle.Builder.toLowerCase().includes(searchQuery);
const puzzleNameMatch = puzzle.PuzzleName.toLowerCase().includes(searchQuery);
const idMatch = puzzle.ID.includes(searchQuery);
const excludeMatch = !excludeQuery || !puzzle.Builder.toLowerCase().includes(excludeQuery);
const datacenterMatch = selectedDatacenters.length === 0 || selectedDatacenters.includes(puzzle.Datacenter);
const districtMatch = selectedDistricts.length === 0 || selectedDistricts.includes(puzzle.District);
const ratingMatch = rating >= minRating && rating <= maxRating;
const tagMatch = selectedTags.length === 0 || selectedTags.every((tag) => puzzle[tag] || puzzle[tag] === "+");
return puzzle.Status === "Active" && ratingMatch && (builderMatch || puzzleNameMatch || idMatch) && excludeMatch && datacenterMatch && districtMatch && tagMatch;
});
}
function sortData() {
const sortBy = document.getElementById("sortBy").value;
const sortOrder = document.getElementById("sortOrder").value;
filteredData.sort((a, b) => {
if (sortBy === "name") {
return sortOrder === "asc" ? a.PuzzleName.localeCompare(b.PuzzleName) : b.PuzzleName.localeCompare(a.PuzzleName);
} else if (sortBy === "rating") {
const ratingA = isNaN(parseInt(a.Rating)) ? 1 : parseInt(a.Rating);
const ratingB = isNaN(parseInt(b.Rating)) ? 1 : parseInt(b.Rating);
return sortOrder === "asc" ? ratingA - ratingB : ratingB - ratingA;
} else if (sortBy === "id") {
return sortOrder === "asc" ? a.ID.localeCompare(b.ID) : b.ID.localeCompare(a.ID);
}
});
displayData(filteredData);
}
function isPuzzleCleared(puzzleId) {
return clearData.some((clear) => clear.puzzleId === puzzleId);
}
function createPuzzleCard(puzzle) {
const infoCard = document.createElement("div");
infoCard.className = "info-card";
if (isPuzzleCleared(puzzle.ID)) {
infoCard.classList.add("cleared");
}
infoCard.innerHTML = `
<h3>${puzzle.PuzzleName} by ${puzzle.Builder} ${getStarRating(puzzle.Rating)} [${getTags(puzzle)}]</h3>
${puzzle.GoalsRules && puzzle.GoalsRules !== "-" ? `<p><strong>Goals/Rules:</strong> ${puzzle.GoalsRules}</p>` : ""}
<p>${puzzle.Datacenter}, ${puzzle.World} - ${puzzle.Address}</p>
<div class="card-footer">
<span class="puzzle-id">${puzzle.ID}</span>
<div class="action-buttons">
<div class="action-button copy-button" data-puzzle="${JSON.stringify(puzzle).replace(/"/g, """)}" data-tooltip="Copy formatted text"></div>
<div class="action-button jump-button" data-puzzle-id="${puzzle.ID}" data-tooltip="Copy clear command"></div>
<div class="action-button sprint-button" data-puzzle-id="${puzzle.ID}" data-world="${puzzle.World}" data-district="${puzzle.District}" data-ward="${puzzle.Ward}" data-plot="${puzzle.Plot}" data-room="${puzzle.Room}" data-tooltip="Copy lifestream command"></div>
</div>
</div>
${exportMode ? `<div class="checkbox-container"><input type="checkbox" data-puzzle-id="${puzzle.ID}" ${selectedPuzzles.includes(puzzle.ID) ? "checked" : ""}></div>` : ""}
`;
if (selectedPuzzles.includes(puzzle.ID)) {
infoCard.classList.add("selected");
}
return infoCard;
}
function createPuzzleListItem(puzzle, listName = null) {
const listItem = document.createElement("div");
listItem.className = "list-item";
if (isPuzzleCleared(puzzle.ID)) {
listItem.classList.add("cleared");
}
const tags = getTags(puzzle);
const tagsDisplay = tags ? ` [${tags}]` : "";
const deleteButton = listName ? `<button class="list-item-delete" onclick="removePuzzleFromList('${listName}', '${puzzle.ID}')" data-tooltip="Remove from list">×</button>` : "";
listItem.innerHTML = `
<div class="list-item-info">
${getStarRating(puzzle.Rating)} ${puzzle.PuzzleName} by ${puzzle.Builder}${tagsDisplay} (${puzzle.Datacenter}, ${puzzle.World} - ${puzzle.Address})
</div>
<div class="list-item-actions">
<div class="action-button copy-button" data-puzzle="${JSON.stringify(puzzle).replace(/"/g, """)}" data-tooltip="Copy formatted text"></div>
<div class="action-button jump-button" data-puzzle-id="${puzzle.ID}" data-tooltip="Copy clear command"></div>
<div class="action-button sprint-button" data-puzzle-id="${puzzle.ID}" data-world="${puzzle.World}" data-district="${puzzle.District}" data-ward="${puzzle.Ward}" data-plot="${puzzle.Plot}" data-room="${puzzle.Room}" data-tooltip="Copy lifestream command"></div>
${deleteButton}
</div>
`;
return listItem;
}
function attachActionButtonListeners(container) {
const jumpButtons = container.querySelectorAll(".jump-button");
const sprintButtons = container.querySelectorAll(".sprint-button");
const copyButtons = container.querySelectorAll(".copy-button");
jumpButtons.forEach((button) => {
button.addEventListener("click", handleJumpButtonClick);
button.addEventListener("mouseenter", showTooltip);
button.addEventListener("mouseleave", hideTooltip);
});
sprintButtons.forEach((button) => {
button.addEventListener("click", handleSprintButtonClick);
button.addEventListener("mouseenter", showTooltip);
button.addEventListener("mouseleave", hideTooltip);
});
copyButtons.forEach((button) => {
button.addEventListener("click", handleCopyButtonClick);
button.addEventListener("mouseenter", showTooltip);
button.addEventListener("mouseleave", hideTooltip);
});
}
function displayData(data) {
const container = document.getElementById("puzzleContainer");
container.innerHTML = "";
data.forEach((puzzle) => {
const infoCard = createPuzzleCard(puzzle);
container.appendChild(infoCard);
});
updatePuzzlesFound();
if (exportMode) {
const checkboxes = document.querySelectorAll('#puzzleContainer .checkbox-container input[type="checkbox"]');
checkboxes.forEach((checkbox) => {
checkbox.addEventListener("change", handlePuzzleSelection);
});
}
attachActionButtonListeners(container);
// Add dev mode buttons if enabled
if (devModeEnabled) {
addDevModeButtonsToExistingCards();
}
}
function openDiscordIdModal() {
const modal = document.getElementById("discordIdModal");
modal.style.display = "block";
}
function closeDiscordIdModal() {
const modal = document.getElementById("discordIdModal");
modal.style.display = "none";
}
function saveDiscordId() {
const input = document.getElementById("discordIdInput");
discordId = input.value.trim();
localStorage.setItem("discordId", discordId);
updateDiscordIdDisplay();
closeDiscordIdModal();
fetchClearData();
}
function updateDiscordIdDisplay() {
const discordIdDisplay = document.getElementById("discordIdDisplay");
if (discordId) {
discordIdDisplay.textContent = `Discord ID: ${discordId}`;
} else {
discordIdDisplay.textContent = "";
}
}
function getStarRating(rating) {
if (isNaN(parseInt(rating))) {
return `☆ ${rating}`;
} else {
return "★".repeat(parseInt(rating));
}
}
function getTags(puzzle) {
const tags = ["M", "E", "S", "P", "V", "J", "G", "L", "X"];
return tags
.filter((tag) => puzzle[tag])
.map((tag) => (puzzle[tag].includes("+") ? `${tag}+` : tag))
.join("");
}
function createDatacenterToggles() {
const datacenters = [...new Set(puzzleData.map((puzzle) => puzzle.Datacenter))];
const toggleContainer = document.getElementById("toggleContainer");
const toggleGroup = document.createElement("div");
toggleGroup.className = "toggle-group";
datacenters.forEach((datacenter) => {
const toggle = document.createElement("div");
toggle.innerHTML = `
<label>
<input type="checkbox" checked data-datacenter="${datacenter}" onchange="applyFilters()">
${datacenter}
</label>
`;
toggleGroup.appendChild(toggle);
});
toggleContainer.appendChild(toggleGroup);
}
function createDistrictToggles() {
const districts = [...new Set(puzzleData.map((puzzle) => puzzle.District))];
const toggleContainer = document.getElementById("districtToggleContainer");
const toggleGroup = document.createElement("div");
toggleGroup.className = "toggle-group";
districts.forEach((district) => {
const toggle = document.createElement("div");
toggle.innerHTML = `
<label>
<input type="checkbox" checked data-district="${district}" onchange="applyFilters()">
${district}
</label>
`;
toggleGroup.appendChild(toggle);
});
toggleContainer.appendChild(toggleGroup);
}
function createTagToggles() {
const tags = ["M", "E", "S", "P", "V", "J", "G", "L", "X"];
const toggleContainer = document.getElementById("tagToggleContainer");
const toggleGroup = document.createElement("div");
toggleGroup.className = "toggle-group";
tags.forEach((tag) => {
const toggle = document.createElement("div");
toggle.innerHTML = `
<label>
<input type="checkbox" data-tag="${tag}" onchange="applyFilters()">
${tag}
</label>
`;
toggleGroup.appendChild(toggle);
});
toggleContainer.appendChild(toggleGroup);
}
function applyFilters() {
filteredData = filterData();
sortData();
}
function debouncedApplyFilters() {
clearTimeout(searchDebounceTimer);
searchDebounceTimer = setTimeout(() => {
applyFilters();
}, 300);
}
function handleExcludeInputKeydown(event) {
if (event.key === "Enter" && event.target.value.toLowerCase() === "/devmode") {
event.preventDefault();
devModeEnabled = !devModeEnabled;
event.target.value = "";
toggleDevModeButton();
}
}
function toggleDevModeButton() {
if (devModeEnabled) {
// Add dev mode buttons to all existing cards
addDevModeButtonsToExistingCards();
} else {
// Remove all dev mode buttons
const devButtons = document.querySelectorAll(".copy-db-button");
devButtons.forEach((button) => button.remove());
}
}
function addDevModeButtonsToExistingCards() {
const actionButtons = document.querySelectorAll(".action-buttons");
actionButtons.forEach((buttonContainer) => {
// Check if dev button already exists
if (buttonContainer.querySelector(".copy-db-button")) {
return;
}
const devButton = document.createElement("div");
devButton.className = "action-button copy-db-button";
devButton.dataset.tooltip = "Copy DB Name";
// Get puzzle data from the parent card
const infoCard = buttonContainer.closest(".info-card");
const puzzleIdElement = infoCard.querySelector(".puzzle-id");
const puzzleId = puzzleIdElement.textContent;
// Find the puzzle data
const puzzle = puzzleData.find((p) => p.ID === puzzleId);
if (puzzle) {
devButton.dataset.puzzle = JSON.stringify(puzzle);
}
devButton.addEventListener("click", handleCopyDBClick);
devButton.addEventListener("mouseenter", showTooltip);
devButton.addEventListener("mouseleave", hideTooltip);
buttonContainer.appendChild(devButton);
});
}
function updatePuzzlesFound() {
const puzzlesFoundElement = document.getElementById("puzzlesFound");
puzzlesFoundElement.textContent = `Puzzles Found: ${filteredData.length}`;
}
function generateDailyRoulette() {
const minRating = parseInt(document.getElementById("minRating").value);
const maxRating = parseInt(document.getElementById("maxRating").value);
const minRatingPuzzles = filteredData.filter((puzzle) => {
const rating = isNaN(parseInt(puzzle.Rating)) ? 1 : parseInt(puzzle.Rating);
return rating === minRating;
});
const maxRatingPuzzles = filteredData.filter((puzzle) => {
const rating = isNaN(parseInt(puzzle.Rating)) ? 1 : parseInt(puzzle.Rating);
return rating === maxRating;
});
const remainingPuzzles = filteredData.filter((puzzle) => {
const rating = isNaN(parseInt(puzzle.Rating)) ? 1 : parseInt(puzzle.Rating);
return rating !== minRating && rating !== maxRating;
});
const roulettePuzzles = [];
if (minRatingPuzzles.length > 0) {
const randomIndex = Math.floor(Math.random() * minRatingPuzzles.length);
roulettePuzzles.push(minRatingPuzzles[randomIndex]);
}
if (maxRatingPuzzles.length > 0) {
const randomIndex = Math.floor(Math.random() * maxRatingPuzzles.length);
roulettePuzzles.push(maxRatingPuzzles[randomIndex]);
}
while (roulettePuzzles.length < 5 && remainingPuzzles.length > 0) {
const randomIndex = Math.floor(Math.random() * remainingPuzzles.length);
roulettePuzzles.push(remainingPuzzles[randomIndex]);
remainingPuzzles.splice(randomIndex, 1);
}
displayRouletteModal(roulettePuzzles);
}
function displayRouletteModal(puzzles) {
const modalContent = document.getElementById("modalContent");
modalContent.innerHTML = "";
puzzles.forEach((puzzle) => {
const listItem = createPuzzleListItem(puzzle);
modalContent.appendChild(listItem);
});
attachActionButtonListeners(modalContent);
const modal = document.getElementById("rouletteModal");
modal.style.display = "block";
}
function closeModal() {
const modal = document.getElementById("rouletteModal");
modal.style.display = "none";
}
function copyToClipboard() {
const modalContent = document.getElementById("modalContent");
const listItems = modalContent.querySelectorAll(".list-item");
let markdownText = "**Duty Roulette**\n\n";
listItems.forEach((item) => {
const infoText = item.querySelector(".list-item-info").textContent;
markdownText += "```prolog\n";
markdownText += infoText + "\n";
markdownText += "```\n";
});
const tempElement = document.createElement("textarea");
tempElement.value = markdownText;
document.body.appendChild(tempElement);
tempElement.select();
document.execCommand("copy");
document.body.removeChild(tempElement);
//alert("Daily Roulette copied to clipboard as Discord markdown!");
}
function toggleExportMode() {
exportMode = !exportMode;
// Update all export mode buttons and button containers
const searchExportButton = document.getElementById("exportModeButton");
const searchExportButtons = document.getElementById("exportButtons");
const hubExportButton = document.getElementById("hubExportModeButton");
const hubExportButtons = document.getElementById("hubExportButtons");
const addToListButton = document.getElementById("addToListButton");
const hubAddToListButton = document.getElementById("hubAddToListButton");
const buttonText = exportMode ? "Disable Selection Mode" : "Enable Selection Mode";
const buttonsDisplay = exportMode ? "inline-block" : "none";
const hasLists = Object.keys(lists).length > 0;
const addToListDisplay = exportMode && hasLists ? "inline-block" : "none";
searchExportButton.textContent = buttonText;
searchExportButtons.style.display = buttonsDisplay;
hubExportButton.textContent = buttonText;
hubExportButtons.style.display = buttonsDisplay;
addToListButton.style.display = addToListDisplay;
hubAddToListButton.style.display = addToListDisplay;
// Refresh current tab display
if (currentTab === "search") {
displayData(filteredData);
} else if (currentTab === "hub") {
filterByHub();
}
}
function handlePuzzleSelection(event) {
const puzzleId = event.target.dataset.puzzleId;
const infoCard = event.target.closest(".info-card");
if (event.target.checked) {
selectedPuzzles.push(puzzleId);
infoCard.classList.add("selected");
} else {
const index = selectedPuzzles.indexOf(puzzleId);
if (index !== -1) {
selectedPuzzles.splice(index, 1);
}
infoCard.classList.remove("selected");
}
}
function clearSelection() {
selectedPuzzles = [];
displayData(filteredData);
}
function copySelectedPuzzleIds() {
const puzzleIds = selectedPuzzles.join(" ");
const tempElement = document.createElement("textarea");
tempElement.value = puzzleIds;
document.body.appendChild(tempElement);
tempElement.select();
document.execCommand("copy");
document.body.removeChild(tempElement);
//alert("Selected puzzle IDs copied to clipboard!");
}
function handleJumpButtonClick(event) {
const puzzleId = event.target.dataset.puzzleId;
const clearCommand = `/clear puzzleids: ${puzzleId}`;
copyToClipboard(clearCommand);
}
function handleSprintButtonClick(event) {
const world = event.target.dataset.world;
const district = event.target.dataset.district;
const ward = event.target.dataset.ward;
const plot = event.target.dataset.plot;
const room = event.target.dataset.room;
let lifeStreamCommand = "";
if (plot === "A1" || plot === "A2") {
// This is an apartment
const isSubdivision = plot === "A2";
lifeStreamCommand = `/li ${world} ${district} w${ward}${isSubdivision ? " s" : ""} a${room}`;
} else if (plot && plot !== "-") {
// This is a house plot
lifeStreamCommand = `/li ${world} ${district} w${ward} p${plot}`;
}
copyToClipboard(lifeStreamCommand);
}
function handleCopyButtonClick(event) {
const puzzle = JSON.parse(event.target.dataset.puzzle);
const tags = getTags(puzzle);
const tagsDisplay = tags ? ` [${tags}]` : "";
const formattedText = `${puzzle.ID}: ${getStarRating(puzzle.Rating)} ${puzzle.PuzzleName} by ${puzzle.Builder}${tagsDisplay} (${puzzle.Address})`;
copyToClipboard(formattedText);
}
function sanitizeFilename(str) {
// Remove or replace characters that aren't allowed in filenames
return str
.replace(/[<>:"/\\|?*]/g, "") // Remove forbidden characters
.replace(/\s+/g, "_") // Replace spaces with underscores
.replace(/[^\w\-_.]/g, "") // Keep only word characters, hyphens, underscores, and dots
.replace(/_+/g, "_") // Replace multiple underscores with single underscore
.replace(/^_|_$/g, ""); // Remove leading/trailing underscores
}
function handleCopyDBClick(event) {
const puzzle = JSON.parse(event.target.dataset.puzzle);
const sanitizedPuzzleName = sanitizeFilename(puzzle.PuzzleName);
const sanitizedBuilder = sanitizeFilename(puzzle.Builder);
const dbName = `${puzzle.ID}_${sanitizedPuzzleName}_by_${sanitizedBuilder}`;
copyToClipboard(dbName);
}
function copyToClipboard(text) {
const tempElement = document.createElement("textarea");
tempElement.value = text;
document.body.appendChild(tempElement);
tempElement.select();
document.execCommand("copy");
document.body.removeChild(tempElement);
}
function showTooltip(event) {
const tooltip = document.getElementById("tooltip");
tooltip.textContent = event.target.dataset.tooltip;
tooltip.style.left = `${event.pageX + 10}px`;
tooltip.style.top = `${event.pageY + 10}px`;
tooltip.style.opacity = 1;
}
function hideTooltip() {
const tooltip = document.getElementById("tooltip");
tooltip.style.opacity = 0;
}
window.onclick = function (event) {
const rouletteModal = document.getElementById("rouletteModal");
const listCreationModal = document.getElementById("listCreationModal");
const addToListModal = document.getElementById("addToListModal");
if (event.target === rouletteModal) {
closeModal();
} else if (event.target === listCreationModal) {
closeListCreationModal();
} else if (event.target === addToListModal) {
closeAddToListModal();
}
};
// Hub Mode Functions
function populateHubWorlds() {
const worldSelect = document.getElementById("hubWorld");
const worlds = [...new Set(puzzleData.map((puzzle) => puzzle.World))].sort();
worlds.forEach((world) => {
const option = document.createElement("option");
option.value = world;
option.textContent = world;
worldSelect.appendChild(option);
});
}
function updateHubDistricts() {
const worldSelect = document.getElementById("hubWorld");
const districtSelect = document.getElementById("hubDistrict");
const wardSelect = document.getElementById("hubWard");
// Clear existing options
districtSelect.innerHTML = '<option value="">Select a district</option>';
wardSelect.innerHTML = '<option value="">Select a ward</option>';
if (worldSelect.value) {
const districts = [...new Set(puzzleData.filter((puzzle) => puzzle.World === worldSelect.value).map((puzzle) => puzzle.District))].sort();
districts.forEach((district) => {
const option = document.createElement("option");
option.value = district;
option.textContent = district;
districtSelect.appendChild(option);
});
}
document.getElementById("hubPuzzleContainer").innerHTML = "";
document.getElementById("hubPuzzlesFound").textContent = "";
}
function updateHubWards() {
const worldSelect = document.getElementById("hubWorld");
const districtSelect = document.getElementById("hubDistrict");
const wardSelect = document.getElementById("hubWard");
// Clear existing options
wardSelect.innerHTML = '<option value="">Select a ward</option>';
if (worldSelect.value && districtSelect.value) {
const wards = [...new Set(puzzleData.filter((puzzle) => puzzle.World === worldSelect.value && puzzle.District === districtSelect.value).map((puzzle) => puzzle.Ward))].sort((a, b) => parseInt(a) - parseInt(b));
wards.forEach((ward) => {
const option = document.createElement("option");
option.value = ward;
option.textContent = `Ward ${ward}`;
wardSelect.appendChild(option);
});
}
document.getElementById("hubPuzzleContainer").innerHTML = "";
document.getElementById("hubPuzzlesFound").textContent = "";
}
function filterByHub() {
const worldSelect = document.getElementById("hubWorld");
const districtSelect = document.getElementById("hubDistrict");
const wardSelect = document.getElementById("hubWard");
if (worldSelect.value && districtSelect.value && wardSelect.value) {
const hubPuzzles = puzzleData.filter((puzzle) => puzzle.World === worldSelect.value && puzzle.District === districtSelect.value && puzzle.Ward === wardSelect.value && puzzle.Status === "Active");
displayHubPuzzles(hubPuzzles);
}
}
function displayHubPuzzles(data) {
const container = document.getElementById("hubPuzzleContainer");
container.innerHTML = "";
data.forEach((puzzle) => {
const infoCard = createPuzzleCard(puzzle);
container.appendChild(infoCard);
});
document.getElementById("hubPuzzlesFound").textContent = `Puzzles Found: ${data.length}`;
if (exportMode) {
const checkboxes = document.querySelectorAll('#hubPuzzleContainer .checkbox-container input[type="checkbox"]');
checkboxes.forEach((checkbox) => {
checkbox.addEventListener("change", handlePuzzleSelection);
});
}
attachActionButtonListeners(container);
// Add dev mode buttons if enabled
if (devModeEnabled) {
addDevModeButtonsToExistingCards();
}
}
// Lists Functions
function createListFromSelection() {
if (selectedPuzzles.length === 0) {
showNotification("No puzzles selected. Please select some puzzles first.", "error");
return;
}
openListCreationModal();
}
function openListCreationModal() {
const modal = document.getElementById("listCreationModal");
const description = document.getElementById("listCreationDescription");
const input = document.getElementById("listNameInput");
description.textContent = `Creating a list with ${selectedPuzzles.length} selected puzzle${selectedPuzzles.length === 1 ? "" : "s"}.`;
input.value = "";
modal.style.display = "block";
input.focus();
// Add keyboard event listeners
input.addEventListener("keydown", handleListCreationKeydown);
modal.addEventListener("keydown", handleListCreationKeydown);
}
function handleListCreationKeydown(event) {
if (event.key === "Enter") {
event.preventDefault();
saveNewList();
} else if (event.key === "Escape") {
event.preventDefault();
closeListCreationModal();
}
}
function closeListCreationModal() {
const modal = document.getElementById("listCreationModal");
const input = document.getElementById("listNameInput");
// Remove event listeners
input.removeEventListener("keydown", handleListCreationKeydown);
modal.removeEventListener("keydown", handleListCreationKeydown);
modal.style.display = "none";
}
function saveNewList() {
const input = document.getElementById("listNameInput");
const listName = input.value.trim();
if (!listName) {
showNotification("Please enter a name for your list.", "error");
return;
}
if (lists[listName]) {
if (!confirm(`A list named "${listName}" already exists. Do you want to replace it?`)) {
return;
}
}
const timestamp = new Date().toISOString();
lists[listName] = {
name: listName,
puzzleIds: [...selectedPuzzles],
created: timestamp,
};
localStorage.setItem("puzzleLists", JSON.stringify(lists));
showNotification(`List "${listName}" created with ${selectedPuzzles.length} puzzle${selectedPuzzles.length === 1 ? "" : "s"}.`, "success");
clearSelection();
closeListCreationModal();
if (currentTab === "lists") {
displayLists();
}
}
function displayLists() {
const container = document.getElementById("listsContainer");
container.innerHTML = "";
const listNames = Object.keys(lists);
if (listNames.length === 0) {
container.innerHTML = '<p style="color: #ad9462;">No lists created yet. Use Selection Mode to create lists.</p>';
return;
}
listNames.forEach((listName) => {
const list = lists[listName];
const listSection = document.createElement("div");
listSection.className = "list-section";
const listHeader = document.createElement("div");
listHeader.className = "list-header";
listHeader.innerHTML = `
<h3>${listName} (${list.puzzleIds.length} puzzles)</h3>
<div class="list-actions">
<button onclick="copyList('${listName}')">Copy</button>
<button onclick="deleteList('${listName}')">Delete</button>
</div>
`;
const listItems = document.createElement("div");
listItems.className = "list-items";
listItems.id = `list-${listName.replace(/\s+/g, "-")}`;
// Add puzzles to the list
list.puzzleIds.forEach((puzzleId) => {
const puzzle = puzzleData.find((p) => p.ID === puzzleId);
if (puzzle) {
const listItem = createPuzzleListItem(puzzle, listName);
listItems.appendChild(listItem);
}
});
listHeader.addEventListener("click", (e) => {
if (!e.target.closest("button")) {
listItems.classList.toggle("expanded");
}
});
listSection.appendChild(listHeader);
listSection.appendChild(listItems);
container.appendChild(listSection);
attachActionButtonListeners(listItems);
});
}
function deleteList(listName) {
if (confirm(`Are you sure you want to delete the list "${listName}"?`)) {
delete lists[listName];
localStorage.setItem("puzzleLists", JSON.stringify(lists));
displayLists();
}
}
// Notification System
function showNotification(message, type = "info") {
// Remove any existing notifications
const existingNotification = document.querySelector(".notification");
if (existingNotification) {
existingNotification.remove();
}
const notification = document.createElement("div");
notification.className = `notification ${type}`;
notification.textContent = message;
document.body.appendChild(notification);
// Trigger animation
setTimeout(() => {
notification.classList.add("show");
}, 10);
// Auto remove after 4 seconds
setTimeout(() => {
notification.classList.remove("show");
setTimeout(() => {
if (notification.parentNode) {
notification.remove();
}
}, 300);
}, 4000);
}
function copyList(listName) {
const list = lists[listName];
if (!list) return;
let formattedText = `**${listName}**\n\n`;
list.puzzleIds.forEach((puzzleId) => {
const puzzle = puzzleData.find((p) => p.ID === puzzleId);
if (puzzle) {
const tags = getTags(puzzle);
const tagsDisplay = tags ? ` [${tags}]` : "";
formattedText += `- ${puzzleId}: ${getStarRating(puzzle.Rating)} ${puzzle.PuzzleName} by ${puzzle.Builder}${tagsDisplay} (${puzzle.Address})\n`;
}
});
copyToClipboard(formattedText);
showNotification(`List "${listName}" copied to clipboard`, "success");
}
function exportAllLists() {
const listNames = Object.keys(lists);
if (listNames.length === 0) {
showNotification("No lists to export", "error");
return;
}
let exportData = "**All Puzzle Lists**\n\n";
listNames.forEach((listName) => {
const list = lists[listName];
exportData += `**${listName}**\n`;
list.puzzleIds.forEach((puzzleId) => {
const puzzle = puzzleData.find((p) => p.ID === puzzleId);
if (puzzle) {
const tags = getTags(puzzle);
const tagsDisplay = tags ? ` [${tags}]` : "";
exportData += `- ${puzzleId}: ${getStarRating(puzzle.Rating)} ${puzzle.PuzzleName} by ${puzzle.Builder}${tagsDisplay} (${puzzle.Address})\n`;
}
});
exportData += "\n";
});
copyToClipboard(exportData);
showNotification(`All ${listNames.length} lists exported to clipboard`, "success");
}
function importListFromClipboard() {
navigator.clipboard
.readText()
.then((text) => {
// Try to parse as individual list format first
if (parseIndividualList(text)) {
return;
}
// Try to parse as export all format
if (parseAllListsFormat(text)) {
return;
}
// Try to parse as JSON format (backup/manual)
parseJSONFormat(text);
})
.catch(() => {
// Silently fail as requested - no error messages
});
}
function parseIndividualList(text) {
// Match format: **ListName** followed by lines with "- ID: puzzle info"
const listNameMatch = text.match(/^\*\*(.+?)\*\*/);
if (!listNameMatch) return false;
const listName = listNameMatch[1].trim();
const lines = text.split("\n");
const puzzleIds = [];
let foundPuzzles = false;
for (const line of lines) {
const puzzleMatch = line.match(/^-\s+(\d{5}):/);
if (puzzleMatch) {
puzzleIds.push(puzzleMatch[1]);
foundPuzzles = true;
}
}
if (foundPuzzles && puzzleIds.length > 0) {
// Validate that puzzles exist
const validPuzzleIds = puzzleIds.filter((id) => puzzleData.find((p) => p.ID === id));
if (validPuzzleIds.length > 0) {