-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscogs-collection.html
More file actions
1333 lines (1192 loc) · 67.8 KB
/
discogs-collection.html
File metadata and controls
1333 lines (1192 loc) · 67.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Discogs Collection Viewer</title>
<style>
* { box-sizing: border-box; }
body { background: #111; color: #eee; font-family: system-ui, sans-serif; margin: 0; padding: 12px 10px; }
@media (min-width: 600px) { body { padding: 20px; } }
.header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
h1 { margin: 0; font-weight: 700; font-size: clamp(1.1rem, 5vw, 1.8rem); }
#logoutBtn { flex-shrink: 0; width: auto; padding: 6px 12px; background: transparent; border: 1px solid #333; border-radius: 6px; color: #777; font-size: 0.78rem; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
#logoutBtn:hover { color: #eee; border-color: #555; background: #1a1a1a; }
.setup-box { background: #1b1b1b; border: 1px solid #333; padding: 20px; border-radius: 6px; max-width: 400px; width: 100%; }
label { font-size: 0.9rem; color: #ccc; }
input { width: 100%; padding: 10px; margin-top: 8px; margin-bottom: 12px; border-radius: 4px; border: 1px solid #444; background: #222; color: #eee; font-size: 1rem; }
button { padding: 12px 20px; background: #3b82f6; border: none; border-radius: 4px; font-weight: 600; cursor: pointer; color: #111; font-size: 1rem; width: 100%; }
/* Tabs */
.tabs { display: flex; gap: 0; margin-bottom: 8px; border-bottom: 1px solid #2a2a2a; }
.tab { padding: 8px 16px 8px 0; background: none; border: none; border-bottom: 2px solid transparent; color: #666; font-size: 0.88rem; font-weight: 600; cursor: pointer; width: auto; margin-bottom: -1px; display: flex; align-items: center; gap: 6px; border-radius: 0; }
.tab:hover { color: #aaa; }
.tab.active { color: #3b82f6; border-bottom-color: #3b82f6; }
.tab-count { background: #222; border-radius: 10px; padding: 1px 7px; font-size: 0.72rem; color: #666; }
.tab.active .tab-count { background: #1a3a6a; color: #3b82f6; }
/* Search */
.search-wrap { position: relative; margin-top: 8px; }
.search-icon { position: absolute; left: 10px; top: 50%; color: #666; pointer-events: none; display: flex; align-items: center; }
#searchInput { width: 100%; padding: 10px 36px 10px 34px; border-radius: 6px; border: 1px solid #333; background: #1a1a1a; color: #eee; font-size: 0.95rem; margin: 0; }
#searchInput:focus { outline: none; border-color: #3b82f6; }
#searchInput::placeholder { color: #555; }
.search-clear { position: absolute; right: 8px; top: 50%; background: none; border: none; color: #555; cursor: pointer; font-size: 1.1rem; padding: 4px 6px; width: auto; display: none; line-height: 1; }
.search-clear:hover { color: #eee; }
/* Filter pill rows */
.pill-section { margin-top: 8px; }
.pill-section-label { font-size: 0.7rem; color: #555; text- letter-spacing: 0.06em; margin-bottom: 4px; }
.pill-section-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; padding: 2px 0; }
.pill-section-toggle:hover .pill-section-label { color: #888; }
.pill-section-chevron { font-size: 0.65rem; color: #444; display: inline-block; }
.pill-section-toggle.open .pill-section-chevron { }
.pill-section-toggle.open .pill-section-label { color: #888; }
.genre-active-badge { font-size: 0.7rem; background: #1a3a6a; color: #3b82f6; border-radius: 10px; padding: 1px 7px; font-weight: 600; }
.genre-pills-wrap { display: none; }
.genre-pills-wrap.open { display: block; }
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 4px 10px; border-radius: 20px; border: 1px solid #333; background: #1a1a1a; color: #aaa; font-size: 0.78rem; cursor: pointer; user-select: none; white-space: nowrap; }
.pill:hover { border-color: #555; color: #eee; }
.pill.active { background: #3b82f6; border-color: #3b82f6; color: #fff; font-weight: 600; }
/* Sort bar */
.sort-bar { margin-top: 8px; margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select { background: #1b1b1b; color: #eee; border: 1px solid #333; padding: 8px 12px; border-radius: 4px; font-size: 0.9rem; flex: 1; min-width: 0; }
#randomBtn { flex-shrink: 0; width: auto; padding: 8px 14px; background: #1a1a1a; border: 1px solid #333; border-radius: 4px; color: #eee; font-size: 0.88rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#randomBtn:hover { background: #222; border-color: #3b82f6; color: #3b82f6; }
#randomBtn .dice { font-size: 1.1rem; display: inline-block; }
#randomBtn.spinning .dice { } 40% { } 100% { } }
/* Result count */
.result-count { font-size: 0.78rem; color: #666; margin-top: 6px; min-height: 1.2em; }
.result-count span { color: #3b82f6; font-weight: 600; }
/* Dashboard */
.dashboard { margin-top: 8px; margin-bottom: 8px; background: #151515; border: 1px solid #333; border-radius: 8px; padding: 8px 12px; }
.dashboard-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; padding: 2px 0; }
.dashboard-header-left { display: flex; align-items: center; gap: 8px; }
.dashboard-title { font-weight: 600; font-size: 0.9rem; }
.dashboard-toggle { font-size: 0.82rem; color: #aaa; }
.dashboard-body { margin-top: 8px; display: none; }
.dashboard-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 600px) { .dashboard-cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; } }
.stat-card { background: #1b1b1b; border: 1px solid #333; border-radius: 6px; padding: 8px 10px; font-size: 0.82rem; }
.stat-card-header { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; font-weight: 600; font-size: 0.8rem; }
.stat-icon { font-size: 0.9rem; }
.stat-main { font-size: 0.85rem; margin-bottom: 3px; word-break: break-word; }
.stat-sub { font-size: 0.75rem; color: #aaa; word-break: break-word; }
/* Decade bar */
.decade-bar-wrap { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.decade-row { display: flex; align-items: center; gap: 6px; font-size: 0.7rem; }
.decade-label { width: 32px; color: #666; flex-shrink: 0; text-align: right; }
.decade-track { flex: 1; background: #222; border-radius: 2px; height: 6px; overflow: hidden; }
.decade-fill { height: 100%; background: #3b82f6; border-radius: 2px; }
.decade-count { color: #555; flex-shrink: 0; width: 28px; text-align: right; }
/* On this day */
.otd-card { background: #0f1f0f; border: 1px solid #1a3a1a; border-radius: 6px; padding: 8px 10px; margin-top: 8px; font-size: 0.82rem; display: none; }
.otd-header { font-size: 0.75rem; font-weight: 600; color: #4ade80; margin-bottom: 4px; }
.otd-item { color: #aaa; padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.otd-item strong { color: #eee; }
/* Grid / Shelf toggle */
#gridToggleBtn { flex-shrink: 0; width: auto; padding: 8px 10px; background: #1a1a1a; border: 1px solid #333; border-radius: 4px; color: #777; font-size: 0.82rem; cursor: pointer; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
#gridToggleBtn:hover { color: #eee; border-color: #555; }
/* Grid (default) */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 20px; } }
.card { background: #1b1b1b; border: 1px solid #333; border-radius: 6px; padding: 8px; cursor: pointer; min-width: 0; overflow: hidden; }
@media (min-width: 600px) { .card { padding: 10px; } }
.card:hover { }
.card.highlighted { border-color: #3b82f6; box-shadow: 0 0 0 2px #3b82f620; }
/* Shelf layout */
.grid.shelf { grid-template-columns: 1fr; gap: 0; }
.grid.shelf .card { display: flex; gap: 12px; align-items: flex-start; border-radius: 0; border-left: none; border-right: none; border-top: none; border-bottom: 1px solid #1e1e1e; padding: 10px 4px; }
.grid.shelf .card:first-child { border-top: 1px solid #1e1e1e; }
.grid.shelf .cover-wrap { flex-shrink: 0; width: 64px; }
.grid.shelf .cover { border-radius: 2px; }
.grid.shelf .card-body { flex: 1; min-width: 0; }
.grid.shelf .card-title-row { margin-top: 0; }
.grid.shelf .title { font-size: 0.9rem; -webkit-line-clamp: 1; }
.grid.shelf .meta { font-size: 0.8rem; }
.grid.shelf .label-meta { font-size: 0.75rem; }
.grid.shelf .genre-tags { margin-top: 3px; }
.grid.shelf .details { font-size: 0.8rem; }
.grid.shelf .pressings { font-size: 0.8rem; }
.cover-wrap { position: relative; }
.cover { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 3px; background: #000; display: block; }
/* Format badges on cover */
.format-badges { position: absolute; bottom: 5px; left: 5px; display: flex; gap: 3px; flex-wrap: wrap; max-width: calc(100% - 10px); }
.format-badge { background: rgba(0,0,0,0.75); border: 1px solid rgba(255,255,255,0.12); color: #ddd; font-size: 0.6rem; font-weight: 600; padding: 2px 5px; border-radius: 3px; backdrop-filter: blur(4px); white-space: nowrap; letter-spacing: 0.03em; }
.format-badge.vinyl { border-color: rgba(59,130,246,0.5); color: #93c5fd; }
.format-badge.cd { border-color: rgba(167,139,250,0.5); color: #c4b5fd; }
.format-badge.cassette { border-color: rgba(52,211,153,0.5); color: #6ee7b7; }
.format-badge.box { border-color: rgba(251,191,36,0.5); color: #fde68a; }
.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 4px; margin-top: 6px; }
.title { font-size: 0.85rem; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; word-break: break-word; }
@media (min-width: 600px) { .title { font-size: 0.95rem; } }
.discogs-link { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 4px; background: #222; border: 1px solid #3a3a3a; color: #3b82f6; text-decoration: none; margin-top: 1px; }
.discogs-link:hover { background: #3b82f6; border-color: #3b82f6; color: #111; }
.meta { margin-top: 3px; font-size: 0.76rem; color: #aaa; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 600px) { .meta { font-size: 0.82rem; } }
.label-meta { margin-top: 2px; font-size: 0.72rem; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 600px) { .label-meta { font-size: 0.78rem; color: #777; } }
/* Genre tags on card */
.genre-tags { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 4px; }
.genre-tag { font-size: 0.62rem; color: #555; border: 1px solid #2a2a2a; border-radius: 3px; padding: 1px 5px; white-space: nowrap; }
.details { margin-top: 8px; padding-top: 8px; border-top: 1px solid #333; font-size: 0.8rem; display: none; }
@media (min-width: 600px) { .details { font-size: 0.85rem; } }
.track { margin: 3px 0; color: #ccc; line-height: 1.4; }
.runtime { margin-top: 8px; font-weight: 600; color: #60a5fa; }
.loading { font-size: 0.9rem; color: #aaa; margin-top: 6px; }
/* Wantlist note on card */
.want-note { margin-top: 4px; font-size: 0.68rem; color: #a78bfa; }
/* Copies count badge (top-right of cover) */
.copies-badge { position: absolute; top: 5px; right: 5px; background: rgba(0,0,0,0.78); border: 1px solid rgba(255,255,255,0.15); color: #fbbf24; font-size: 0.65rem; font-weight: 700; padding: 2px 6px; border-radius: 3px; letter-spacing: 0.02em; }
/* Pressings list inside expanded card */
.pressings { margin-top: 8px; padding-top: 8px; border-top: 1px solid #2a2a2a; display: none; }
.pressing-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 5px 0; border-bottom: 1px solid #1e1e1e; font-size: 0.75rem; color: #aaa; cursor: pointer; }
.pressing-row:last-child { border-bottom: none; }
.pressing-row:hover { color: #eee; }
.pressing-info { flex: 1; min-width: 0; }
.pressing-fmt { font-size: 0.68rem; color: #3b82f6; font-weight: 600; margin-top: 1px; }
.pressing-link { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 3px; background: #222; border: 1px solid #333; color: #3b82f6; text-decoration: none; }
.pressing-link:hover { background: #3b82f6; color: #111; }
/* Also in collection (modal) */
.modal-also { margin-top: 12px; padding-top: 12px; border-top: 1px solid #2a2a2a; font-size: 0.82rem; }
.modal-also-title { font-size: 0.75rem; font-weight: 600; color: #555; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.modal-also-item { color: #aaa; padding: 2px 0; }
.modal-also-item span { color: #eee; }
/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; opacity: 0; pointer-events: none; }
.modal-overlay.visible { opacity: 1; pointer-events: all; }
.modal { background: #1a1a1a; border: 1px solid #2a2a2a; border-radius: 12px; width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; position: relative; }
.modal-overlay.visible .modal { }
.modal-cover-wrap { position: relative; }
.modal-cover { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 10px 10px 0 0; display: block; }
.modal-close { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; min-width: 32px; border-radius: 50%; background: rgba(0,0,0,0.6); border: none; color: #eee; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1; padding: 0; backdrop-filter: blur(4px); }
.modal-close:hover { background: rgba(0,0,0,0.85); }
.modal-body { padding: 16px; }
.modal-title { font-size: 1.15rem; font-weight: 700; line-height: 1.3; margin: 0 0 4px; }
.modal-artist { font-size: 0.9rem; color: #aaa; margin-bottom: 2px; }
.modal-meta { font-size: 0.82rem; color: #666; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.modal-btn-primary { flex: 1; padding: 10px; background: #3b82f6; border: none; border-radius: 6px; color: #fff; font-weight: 600; font-size: 0.9rem; cursor: pointer; text-decoration: none; display: flex; align-items: center; justify-content: center; gap: 6px; width: auto; }
.modal-btn-primary:hover { background: #2563eb; }
.modal-btn-secondary { flex: 1; padding: 10px; background: #222; border: 1px solid #333; border-radius: 6px; color: #eee; font-weight: 600; font-size: 0.9rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; width: auto; }
.modal-btn-secondary:hover { background: #2a2a2a; border-color: #444; }
.modal-tracklist { border-top: 1px solid #2a2a2a; padding-top: 12px; }
.modal-tracklist-title { font-size: 0.78rem; font-weight: 600; color: #555; text- letter-spacing: 0.06em; margin-bottom: 8px; }
.modal-track { font-size: 0.82rem; color: #ccc; padding: 3px 0; line-height: 1.4; display: flex; justify-content: space-between; gap: 8px; }
.modal-track-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-track-dur { color: #555; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.modal-runtime { margin-top: 10px; font-size: 0.82rem; font-weight: 600; color: #60a5fa; }
.modal-loading { color: #555; font-size: 0.85rem; padding: 12px 0; text-align: center; }
</style>
</head>
<body>
<div class="header-row">
<h1><span style="font-size:0.85em;margin-right:6px;">🎶</span><span id="header">Discogs Collection</span></h1>
<button id="logoutBtn" style="display:none;" title="Change user or log out">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
Change User
</button>
</div>
<div id="tabs" class="tabs" style="display:none;">
<button class="tab active" data-tab="collection" id="tabCollection">
💿 Collection <span class="tab-count" id="tabCountCollection">0</span>
</button>
<button class="tab" data-tab="wantlist" id="tabWantlist">
❤️ Wantlist <span class="tab-count" id="tabCountWantlist">0</span>
</button>
</div>
<div id="dashboard" class="dashboard" style="display:none;">
<div class="dashboard-header" id="dashboardToggle">
<div class="dashboard-header-left"><span>📊</span><span class="dashboard-title">Collector Dashboard</span></div>
<div class="dashboard-toggle" id="dashboardToggleText">Hide</div>
</div>
<div class="dashboard-body" id="dashboardBody">
<div class="dashboard-cards">
<div class="stat-card"><div class="stat-card-header"><span class="stat-icon">💠</span><span>Collection</span></div><div class="stat-main" id="collectionMain">—</div><div class="stat-sub" id="collectionSub">—</div></div>
<div class="stat-card"><div class="stat-card-header"><span class="stat-icon">🎼</span><span>Artists</span></div><div class="stat-main" id="artistMain">—</div><div class="stat-sub" id="artistSub">—</div></div>
<div class="stat-card"><div class="stat-card-header"><span class="stat-icon">💿</span><span>Formats</span></div><div class="stat-main" id="formatMain">—</div><div class="stat-sub" id="formatSub">—</div></div>
<div class="stat-card"><div class="stat-card-header"><span class="stat-icon">🕰</span><span>History</span></div><div class="stat-main" id="historyMain">—</div><div class="stat-sub" id="historySub">—</div></div>
<div class="stat-card" style="grid-column:1/-1"><div class="stat-card-header"><span class="stat-icon">📊</span><span>By Decade</span></div><div class="decade-bar-wrap" id="decadeBar"></div></div>
</div>
<div class="otd-card" id="otdCard">
<div class="otd-header" id="otdHeader"></div>
<div id="otdList"></div>
</div>
</div>
</div>
<div id="searchArea" style="display:none;">
<div class="search-wrap">
<span class="search-icon">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
</span>
<input id="searchInput" type="search" placeholder="Artist, album, label, year, 70s, 1980s…" autocomplete="off" spellcheck="false">
<button class="search-clear" id="searchClear" title="Clear">✕</button>
</div>
<div class="pill-section" id="formatPillSection">
<div class="pill-section-label">Format</div>
<div class="filter-pills" id="formatPills"></div>
</div>
<div class="pill-section" id="genrePillSection" style="display:none;">
<div class="pill-section-toggle" id="genreToggle">
<span class="pill-section-chevron">▶</span>
<span class="pill-section-label">Genre</span>
<span class="genre-active-badge" id="genreActiveBadge" style="display:none;"></span>
</div>
<div class="genre-pills-wrap" id="genrePillsWrap">
<div class="filter-pills" id="genrePills" style="margin-top:6px;"></div>
</div>
</div>
<div class="result-count" id="resultCount"></div>
</div>
<div class="sort-bar" id="sortBar" style="display:none;">
<select id="sortSelect">
<option value="artist">Sort by Artist (A–Z)</option>
<option value="yearAsc">Sort by Year (Oldest → Newest)</option>
<option value="yearDesc">Sort by Year (Newest → Oldest)</option>
<option value="addedDesc">Sort by Recently Added</option>
<option value="addedAsc">Sort by First Added</option>
</select>
<button id="randomBtn" title="Pick a random record">
<span class="dice">🎲</span> Random
</button>
<button id="gridToggleBtn" title="Toggle view">
<svg id="gridIcon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/></svg>
<svg id="shelfIcon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:none"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
</button>
</div>
<div id="setup"></div>
<div id="loading" class="loading"></div>
<div id="results" class="grid"></div>
<div style="text-align:center;margin-top:40px;padding-top:16px;border-top:1px solid #1a1a1a;">
<a href="https://github.com/dhrandy/discogs-collection" target="_blank" rel="noopener noreferrer" style="color:#444;font-size:0.75rem;text-decoration:none;display:inline-flex;align-items:center;gap:6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0 0 24 12c0-6.63-5.37-12-12-12z"/></svg>
dhrandy/discogs-collection
</a>
</div>
<!-- Random Modal -->
<div class="modal-overlay" id="randomModal" role="dialog" aria-modal="true">
<div class="modal" id="modalContent">
<div class="modal-cover-wrap">
<img class="modal-cover" id="modalCover" src="" alt="">
<button class="modal-close" id="modalClose" title="Close">✕</button>
</div>
<div class="modal-body">
<div class="modal-title" id="modalTitle"></div>
<div class="modal-artist" id="modalArtist"></div>
<div class="modal-meta" id="modalMeta"></div>
<div class="modal-actions">
<a class="modal-btn-primary" id="modalDiscogsLink" href="#" target="_blank" rel="noopener noreferrer">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>
View on Discogs
</a>
<button class="modal-btn-secondary" id="modalPickAnother"><span>🎲</span> Pick Another</button>
</div>
<div class="modal-also" id="modalAlso" style="display:none;">
<div class="modal-also-title">Also in your collection</div>
<div id="modalAlsoList"></div>
</div>
<div class="modal-tracklist" id="modalTracklist"></div>
</div>
</div>
</div>
<script>
let globalReleases = []; // collection releases
let wantlistReleases = []; // wantlist releases
let activeTab = "collection"; // "collection" | "wantlist"
let activeFormat = null;
let activeGenre = null;
let currentFilteredReleases = [];
const detailsCache = new Map();
function txt(str) {
const el = document.createElement("span");
el.textContent = str ?? "";
return el.textContent;
}
const linkIconSVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="width:13px;height:13px;"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>`;
// ── Format badge colour class ─────────────────────────────────────
function formatBadgeClass(name) {
const n = (name || "").toLowerCase();
if (n.includes("vinyl") || n === "lp" || n === "12\"" || n === "7\"" || n === "10\"") return "vinyl";
if (n.includes("cd") || n.includes("sacd")) return "cd";
if (n.includes("cassette") || n.includes("tape")) return "cassette";
if (n.includes("box")) return "box";
return "";
}
// ── Setup ─────────────────────────────────────────────────────────
function showSetup() {
const box = document.createElement("div");
box.className = "setup-box";
box.innerHTML = `<h2>Setup</h2><label>Discogs Username</label><input id="usernameInput" placeholder="e.g., dhrandy" autocomplete="username"><label>API Token (optional — required for wantlist)</label><input id="tokenInput" placeholder="Settings → Developers → Generate token" type="password" autocomplete="off"><p style="font-size:0.78rem;color:#777;margin:0 0 12px">Stored locally on this device only.</p>`;
const btn = document.createElement("button");
btn.textContent = "Save";
btn.addEventListener("click", saveSetup);
box.appendChild(btn);
document.getElementById("setup").appendChild(box);
}
function saveSetup() {
const username = document.getElementById("usernameInput").value.trim();
const token = document.getElementById("tokenInput").value.trim();
if (!username) { alert("Username is required."); return; }
if (!/^[\w.-]{1,50}$/.test(username)) { alert("Invalid username."); return; }
localStorage.setItem("discogs_username", username);
localStorage.setItem("discogs_token", token);
location.reload();
}
function initDashboardToggle() {
const body = document.getElementById("dashboardBody");
const toggleText = document.getElementById("dashboardToggleText");
const stored = localStorage.getItem("discogs_dashboard_collapsed");
if (stored === "false") { body.style.display = "block"; toggleText.textContent = "Hide"; }
else { body.style.display = "none"; toggleText.textContent = "Show"; }
document.getElementById("dashboardToggle").addEventListener("click", () => {
const v = body.style.display === "block";
body.style.display = v ? "none" : "block";
toggleText.textContent = v ? "Show" : "Hide";
localStorage.setItem("discogs_dashboard_collapsed", v ? "true" : "false");
});
}
// ── Fetch ─────────────────────────────────────────────────────────
async function fetchAllPages(baseURL) {
let page = 1, all = [];
while (true) {
const sep = baseURL.includes("?") ? "&" : "?";
const res = await fetch(`${baseURL}${sep}page=${page}&per_page=100`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const data = await res.json();
// Collection uses data.releases; wantlist uses data.wants
all = all.concat(data.releases || data.wants || []);
const pages = data.pagination?.pages ?? 1;
if (page >= pages) break;
page++;
}
return all;
}
async function loadCollection() {
const username = localStorage.getItem("discogs_username");
const token = localStorage.getItem("discogs_token");
if (!username) { showSetup(); return; }
document.getElementById("header").textContent = txt(username) + "'s Discogs Collection";
document.getElementById("logoutBtn").style.display = "flex";
const auth = token ? "?token=" + encodeURIComponent(token) : "";
const loadingEl = document.getElementById("loading");
loadingEl.textContent = "Loading your collection…";
try {
const collURL = `https://api.discogs.com/users/${encodeURIComponent(username)}/collection/folders/0/releases` + auth;
globalReleases = await fetchAllPages(collURL);
} catch (err) {
loadingEl.textContent = "Failed to load collection: " + err.message;
return;
}
loadingEl.textContent = "";
// Load wantlist in background (needs token for private wantlists)
loadWantlist(username, auth);
document.getElementById("tabs").style.display = "flex";
document.getElementById("tabCountCollection").textContent = globalReleases.length;
document.getElementById("dashboard").style.display = "block";
document.getElementById("searchArea").style.display = "block";
document.getElementById("sortBar").style.display = "flex";
buildDuplicateMap();
initDashboardToggle();
computeDashboard(globalReleases);
buildFormatPills(globalReleases);
buildGenrePills(globalReleases);
initSearch();
initRandom();
initLogout();
initTabs();
// Restore saved sort before first render
const savedSort = localStorage.getItem("discogs_sort");
if (savedSort) document.getElementById("sortSelect").value = savedSort;
applyFilters();
document.getElementById("sortSelect").addEventListener("change", () => {
localStorage.setItem("discogs_sort", document.getElementById("sortSelect").value);
applyFilters();
});
initGridToggle();
initKeyboardShortcuts();
}
async function loadWantlist(username, auth) {
try {
const wantURL = `https://api.discogs.com/users/${encodeURIComponent(username)}/wants` + auth;
wantlistReleases = await fetchAllPages(wantURL);
// Normalise wantlist items — they have basic_information nested under .basic_information same as collection
document.getElementById("tabCountWantlist").textContent = wantlistReleases.length;
} catch (err) {
// Wantlist can fail silently (private or no token) — tab stays but shows 0
console.warn("Could not load wantlist:", err.message);
}
}
// ── Tabs ──────────────────────────────────────────────────────────
function initTabs() {
document.querySelectorAll(".tab").forEach(tab => {
tab.addEventListener("click", () => {
const which = tab.dataset.tab;
if (which === activeTab) return;
activeTab = which;
document.querySelectorAll(".tab").forEach(t => t.classList.toggle("active", t.dataset.tab === which));
// Rebuild pills for the active dataset
const data = activeTab === "wantlist" ? wantlistReleases : globalReleases;
activeFormat = null;
activeGenre = null;
const badge = document.getElementById("genreActiveBadge");
if (badge) { badge.style.display = "none"; }
buildFormatPills(data);
buildGenrePills(data);
computeDashboard(activeTab === "collection" ? globalReleases : wantlistReleases);
applyFilters();
});
});
}
function activeReleases() {
return activeTab === "wantlist" ? wantlistReleases : globalReleases;
}
// ── Format pills ──────────────────────────────────────────────────
function buildFormatPills(releases) {
const counts = {};
releases.forEach(item => {
item.basic_information?.formats?.forEach(f => {
const n = f.name || "Unknown";
counts[n] = (counts[n] || 0) + 1;
});
});
const container = document.getElementById("formatPills");
container.innerHTML = "";
const allPill = document.createElement("button");
allPill.className = "pill active";
allPill.textContent = "All";
allPill.addEventListener("click", () => setFormatPill(allPill, ""));
container.appendChild(allPill);
Object.entries(counts).sort((a, b) => b[1] - a[1]).forEach(([name, count]) => {
const pill = document.createElement("button");
pill.className = "pill";
pill.textContent = name + " (" + count + ")";
pill.addEventListener("click", () => setFormatPill(pill, name));
container.appendChild(pill);
});
}
function setFormatPill(clickedPill, formatName) {
document.querySelectorAll("#formatPills .pill").forEach(p => p.classList.remove("active"));
clickedPill.classList.add("active");
activeFormat = formatName || null;
applyFilters();
}
// ── Genre pills ───────────────────────────────────────────────────
let genreToggleInited = false;
function buildGenrePills(releases) {
const counts = {};
releases.forEach(item => {
const info = item.basic_information;
const tags = [...(info?.genres || []), ...(info?.styles || [])];
tags.forEach(g => { counts[g] = (counts[g] || 0) + 1; });
});
const section = document.getElementById("genrePillSection");
const container = document.getElementById("genrePills");
container.innerHTML = "";
if (Object.keys(counts).length === 0) { section.style.display = "none"; return; }
section.style.display = "block";
const allPill = document.createElement("button");
allPill.className = "pill active";
allPill.textContent = "All";
allPill.addEventListener("click", () => setGenrePill(allPill, ""));
container.appendChild(allPill);
Object.entries(counts).sort((a, b) => b[1] - a[1]).forEach(([name, count]) => {
const pill = document.createElement("button");
pill.className = "pill";
pill.textContent = name + " (" + count + ")";
pill.addEventListener("click", () => setGenrePill(pill, name));
container.appendChild(pill);
});
// Wire up toggle once
if (!genreToggleInited) {
genreToggleInited = true;
document.getElementById("genreToggle").addEventListener("click", () => {
const toggle = document.getElementById("genreToggle");
const wrap = document.getElementById("genrePillsWrap");
const isOpen = wrap.classList.toggle("open");
toggle.classList.toggle("open", isOpen);
});
}
}
function setGenrePill(clickedPill, genreName) {
document.querySelectorAll("#genrePills .pill").forEach(p => p.classList.remove("active"));
clickedPill.classList.add("active");
activeGenre = genreName || null;
const badge = document.getElementById("genreActiveBadge");
if (activeGenre) { badge.textContent = activeGenre; badge.style.display = "inline"; }
else { badge.style.display = "none"; }
applyFilters();
}
// ── Search ────────────────────────────────────────────────────────
function initSearch() {
const input = document.getElementById("searchInput");
const clear = document.getElementById("searchClear");
let timer;
input.addEventListener("input", () => {
clearTimeout(timer);
clear.style.display = input.value ? "block" : "none";
timer = setTimeout(applyFilters, 120);
});
clear.addEventListener("click", () => {
input.value = "";
clear.style.display = "none";
applyFilters();
input.focus();
});
}
function parseQuery(raw) {
const q = raw.trim().toLowerCase();
if (!q) return { type: "empty" };
const dm = q.match(/^(?:19|20)?(\d0)'?s$/);
if (dm) { const d = parseInt(dm[1]); const start = (d <= 30 ? 2000 : 1900) + d; return { type: "decade", start, end: start + 9 }; }
const ym = q.match(/^(19\d{2}|20\d{2})$/);
if (ym) return { type: "year", year: parseInt(ym[1]) };
const rm = q.match(/^(19\d{2}|20\d{2})\s*[-]\s*(19\d{2}|20\d{2})$/);
if (rm) return { type: "range", start: parseInt(rm[1]), end: parseInt(rm[2]) };
return { type: "text", q };
}
function matchesQuery(item, parsed) {
if (parsed.type === "empty") return true;
const info = item.basic_information;
const year = Number(info?.year) || 0;
if (parsed.type === "decade") return year >= parsed.start && year <= parsed.end;
if (parsed.type === "year") return year === parsed.year;
if (parsed.type === "range") return year >= parsed.start && year <= parsed.end;
const q = parsed.q;
const artist = (info?.artists?.[0]?.name || "").toLowerCase();
const title = (info?.title || "").toLowerCase();
const label = (info?.labels?.[0]?.name || "").toLowerCase();
return artist.includes(q) || title.includes(q) || label.includes(q) || String(info?.year || "").includes(q);
}
function matchesFormat(item) {
if (!activeFormat) return true;
return item.basic_information?.formats?.some(f => f.name === activeFormat) ?? false;
}
function matchesGenre(item) {
if (!activeGenre) return true;
const info = item.basic_information;
return [...(info?.genres || []), ...(info?.styles || [])].includes(activeGenre);
}
function artistSortKey(name) {
return (name || "").toLowerCase().replace(/\s*\(\d+\)\s*$/, "").replace(/^(the|a|an)\s+/, "");
}
// ── Apply filters + sort + render ─────────────────────────────────
function applyFilters() {
const query = document.getElementById("searchInput")?.value ?? "";
const parsed = parseQuery(query);
const mode = document.getElementById("sortSelect").value;
const pool = activeReleases();
let results = pool.filter(item => matchesQuery(item, parsed) && matchesFormat(item) && matchesGenre(item));
if (mode === "artist") {
const keys = new Map(results.map(i => [i, artistSortKey(i.basic_information?.artists?.[0]?.name)]));
results.sort((a, b) => keys.get(a).localeCompare(keys.get(b)));
} else if (mode === "yearAsc") {
results.sort((a, b) => (a.basic_information?.year || 9999) - (b.basic_information?.year || 9999));
} else if (mode === "yearDesc") {
results.sort((a, b) => (b.basic_information?.year || 0) - (a.basic_information?.year || 0));
} else if (mode === "addedDesc") {
results.sort((a, b) => new Date(b.date_added || 0) - new Date(a.date_added || 0));
} else if (mode === "addedAsc") {
results.sort((a, b) => new Date(a.date_added || 0) - new Date(b.date_added || 0));
}
currentFilteredReleases = results;
renderGrid(results);
updateResultCount(results.length, pool.length, parsed, query);
}
function updateResultCount(shown, total, parsed, query) {
const el = document.getElementById("resultCount");
if (!el) return;
if (shown === total && !activeFormat && !activeGenre) { el.innerHTML = ""; return; }
let label = "";
if (parsed.type === "decade") label = parsed.start + "s";
else if (parsed.type === "year") label = String(parsed.year);
else if (parsed.type === "range") label = parsed.start + "–" + parsed.end;
else if (parsed.type === "text" && query.trim()) label = '"' + query.trim() + '"';
const parts = [];
if (label) parts.push("matching " + label);
if (activeFormat) parts.push(activeFormat);
if (activeGenre) parts.push(activeGenre);
const suffix = parts.length ? " · " + parts.join(" · ") : "";
el.innerHTML = "<span>" + shown + "</span> of " + total + " records" + suffix;
}
// ── Render grid ───────────────────────────────────────────────────
function renderGrid(releases) {
const container = document.getElementById("results");
container.innerHTML = "";
if (releases.length === 0) {
const empty = document.createElement("div");
empty.style.cssText = "grid-column:1/-1;color:#666;font-size:0.9rem;padding:20px 0;";
empty.textContent = "No records match your search.";
container.appendChild(empty);
return;
}
const isWantlist = activeTab === "wantlist";
const fragment = document.createDocumentFragment();
// Group releases by normalised title so duplicates show as one card
const seen = new Map(); // normTitle -> first item index in grouped array
const grouped = [];
releases.forEach(item => {
const key = normTitle(item.basic_information.title);
if (seen.has(key)) {
grouped[seen.get(key)].copies.push(item);
} else {
seen.set(key, grouped.length);
grouped.push({ primary: item, copies: [item] });
}
});
grouped.forEach(({ primary, copies }) => {
const info = primary.basic_information;
const releaseId = info.id;
const totalCopies = copies.length;
// Label text (from primary)
const labelName = info.labels?.[0]?.name ?? null;
const labelCatno = info.labels?.[0]?.catno ?? null;
let labelText = "";
if (labelName && labelName !== "Not On Label") {
labelText = labelName;
if (labelCatno && labelCatno.toLowerCase() !== "none") labelText += " · " + labelCatno;
}
// Formats from primary
const formats = info.formats?.map(f => f.name).filter(Boolean) || [];
// Genres + styles for tags
const genres = [...(info.genres || []), ...(info.styles || [])].slice(0, 3);
const card = document.createElement("div");
card.className = "card";
// Cover wrap
const coverWrap = document.createElement("div");
coverWrap.className = "cover-wrap";
const img = document.createElement("img");
img.className = "cover"; img.src = info.cover_image || ""; img.alt = txt(info.title); img.loading = "lazy";
coverWrap.appendChild(img);
// Format badges
if (formats.length > 0) {
const badgeRow = document.createElement("div");
badgeRow.className = "format-badges";
formats.forEach(name => {
const badge = document.createElement("span");
badge.className = "format-badge " + formatBadgeClass(name);
badge.textContent = name;
badgeRow.appendChild(badge);
});
coverWrap.appendChild(badgeRow);
}
// Copies count badge (top-right of cover)
if (totalCopies > 1) {
const copiesBadge = document.createElement("div");
copiesBadge.className = "copies-badge";
copiesBadge.textContent = totalCopies + "×";
coverWrap.appendChild(copiesBadge);
}
card.appendChild(coverWrap);
// Card body (wraps all content after the cover for shelf layout)
const cardBody = document.createElement("div");
cardBody.className = "card-body";
// Title row
const titleRow = document.createElement("div");
titleRow.className = "card-title-row";
const titleEl = document.createElement("div");
titleEl.className = "title"; titleEl.textContent = info.title || "";
const link = document.createElement("a");
link.className = "discogs-link";
link.href = "https://www.discogs.com/release/" + encodeURIComponent(releaseId);
link.target = "_blank"; link.rel = "noopener noreferrer"; link.title = "View on Discogs";
link.innerHTML = linkIconSVG;
link.addEventListener("click", e => e.stopPropagation());
titleRow.appendChild(titleEl); titleRow.appendChild(link);
cardBody.appendChild(titleRow);
// Artist · Year
const metaEl = document.createElement("div");
metaEl.className = "meta";
metaEl.textContent = (info.artists?.[0]?.name || "Unknown") + " · " + (info.year || "Unknown");
cardBody.appendChild(metaEl);
// Label
if (labelText) {
const labelEl = document.createElement("div");
labelEl.className = "label-meta"; labelEl.textContent = "🏷 " + labelText;
cardBody.appendChild(labelEl);
}
// Genre tags
if (genres.length > 0) {
const tagRow = document.createElement("div");
tagRow.className = "genre-tags";
genres.forEach(g => {
const tag = document.createElement("span");
tag.className = "genre-tag"; tag.textContent = g;
tagRow.appendChild(tag);
});
cardBody.appendChild(tagRow);
}
// Wantlist / recently added note (use primary)
if (isWantlist && primary.date_added) {
const noteEl = document.createElement("div");
noteEl.className = "want-note";
noteEl.textContent = "❤️ Wanted since " + new Date(primary.date_added).getFullYear();
cardBody.appendChild(noteEl);
}
if (!isWantlist && primary.date_added) {
const d = new Date(primary.date_added);
const days = Math.floor((new Date() - d) / 86400000);
if (days <= 30) {
const noteEl = document.createElement("div");
noteEl.className = "want-note"; noteEl.style.color = "#86efac";
noteEl.textContent = days === 0 ? "🆕 Added today" : "🆕 Added " + days + " day" + (days === 1 ? "" : "s") + " ago";
cardBody.appendChild(noteEl);
}
}
// If multiple copies: pressings list (collapsed), else single tracklist
if (totalCopies > 1) {
const pressingsEl = document.createElement("div");
pressingsEl.className = "pressings";
pressingsEl.id = "pressings-" + releaseId;
copies.forEach(copy => {
const ci = copy.basic_information;
const cid = ci.id;
const row = document.createElement("div");
row.className = "pressing-row";
row.addEventListener("click", e => { e.stopPropagation(); loadDetails(cid); });
const infoDiv = document.createElement("div");
infoDiv.className = "pressing-info";
const yearLabel = ci.labels?.[0]?.name && ci.labels[0].name !== "Not On Label"
? (ci.year || "?") + " · " + ci.labels[0].name
: (ci.year || "Unknown");
infoDiv.textContent = yearLabel;
const fmtDiv = document.createElement("div");
fmtDiv.className = "pressing-fmt";
fmtDiv.textContent = ci.formats?.map(f => f.name).join(", ") || "";
infoDiv.appendChild(fmtDiv);
const cLink = document.createElement("a");
cLink.className = "pressing-link";
cLink.href = "https://www.discogs.com/release/" + encodeURIComponent(cid);
cLink.target = "_blank"; cLink.rel = "noopener noreferrer"; cLink.title = "View on Discogs";
cLink.innerHTML = linkIconSVG;
cLink.addEventListener("click", e => e.stopPropagation());
row.appendChild(infoDiv); row.appendChild(cLink);
pressingsEl.appendChild(row);
// Tracklist for each pressing (injected below the pressing row when clicked)
const detailsEl = document.createElement("div");
detailsEl.className = "details"; detailsEl.id = "details-" + cid;
pressingsEl.appendChild(detailsEl);
});
cardBody.appendChild(pressingsEl);
card.appendChild(cardBody);
// Click card body = toggle pressings
card.addEventListener("click", () => {
const el = document.getElementById("pressings-" + releaseId);
if (el) el.style.display = el.style.display === "block" ? "none" : "block";
});
} else {
// Single copy — tracklist directly on card
const detailsEl = document.createElement("div");
detailsEl.className = "details"; detailsEl.id = "details-" + releaseId;
cardBody.appendChild(detailsEl);
card.appendChild(cardBody);
card.addEventListener("click", () => loadDetails(releaseId));
}
fragment.appendChild(card);
});
container.appendChild(fragment);
}
// ── Tracklist ─────────────────────────────────────────────────────
async function loadDetails(releaseId) {
const detailsEl = document.getElementById("details-" + releaseId);
if (!detailsEl) return;
if (detailsEl.style.display === "block") { detailsEl.style.display = "none"; return; }
detailsEl.style.display = "block";
if (detailsCache.has(releaseId)) { detailsEl.innerHTML = detailsCache.get(releaseId); return; }
detailsEl.textContent = "Loading…";
try {
const res = await fetch("https://api.discogs.com/releases/" + encodeURIComponent(releaseId));
if (!res.ok) throw new Error(res.status + " " + res.statusText);
const data = await res.json();
if (!data.tracklist || data.tracklist.length === 0) { detailsEl.textContent = "No tracklist available."; return; }
if (data.tracklist) detailsCache.set(releaseId + "_raw", data.tracklist);
const frag = document.createDocumentFragment();
let totalSeconds = 0;
data.tracklist.forEach((track, index) => {
const pos = (track.position || "").replace(/[-]+$/g, "").trim();
const time = track.duration || "";
const trackEl = document.createElement("div");
trackEl.className = "track";
trackEl.textContent = (pos || (index + 1)) + ". " + (track.title || "") + (time ? " — " + time : "");
frag.appendChild(trackEl);
if (time.includes(":")) { const [m, s] = time.split(":").map(Number); totalSeconds += (m * 60) + s; }
});
const runtimeEl = document.createElement("div");
runtimeEl.className = "runtime";
runtimeEl.textContent = "Total runtime: " + Math.floor(totalSeconds / 60) + ":" + String(totalSeconds % 60).padStart(2, "0");
frag.appendChild(runtimeEl);
detailsEl.innerHTML = "";
detailsEl.appendChild(frag);
detailsCache.set(releaseId, detailsEl.innerHTML);
} catch (err) {
detailsEl.textContent = "Could not load tracklist: " + err.message;
}
}
// ── Random modal ──────────────────────────────────────────────────
function initRandom() {
const btn = document.getElementById("randomBtn");
const overlay = document.getElementById("randomModal");
document.getElementById("modalClose").addEventListener("click", closeModal);
document.getElementById("modalPickAnother").addEventListener("click", openRandomModal);
overlay.addEventListener("click", e => { if (e.target === overlay) closeModal(); });
document.addEventListener("keydown", e => { if (e.key === "Escape") closeModal(); });
btn.addEventListener("click", () => {
openRandomModal();
});
}
function openRandomModal() {
const pool = currentFilteredReleases.length > 0 ? currentFilteredReleases : activeReleases();
if (pool.length === 0) return;
const item = pool[Math.floor(Math.random() * pool.length)];
const info = item.basic_information;
const releaseId = info.id;
document.getElementById("modalCover").src = info.cover_image || "";
document.getElementById("modalCover").alt = txt(info.title);
document.getElementById("modalTitle").textContent = info.title || "";
document.getElementById("modalArtist").textContent = info.artists?.[0]?.name || "";
const labelName = info.labels?.[0]?.name;
const labelCatno = info.labels?.[0]?.catno;
let metaParts = [];
if (info.year) metaParts.push(info.year);
if (labelName && labelName !== "Not On Label") {
let l = labelName;
if (labelCatno && labelCatno.toLowerCase() !== "none") l += " · " + labelCatno;
metaParts.push(l);
}
document.getElementById("modalMeta").textContent = metaParts.join(" · ");
document.getElementById("modalDiscogsLink").href = "https://www.discogs.com/release/" + encodeURIComponent(releaseId);
// "Also in collection" — other pressings of the same title
const titleKey = normTitle(info.title);
const others = (duplicateMap.get(titleKey) || []).filter(r => r.basic_information.id !== releaseId);
const alsoEl = document.getElementById("modalAlso");
const alsoList = document.getElementById("modalAlsoList");
alsoList.innerHTML = "";
if (others.length > 0) {
alsoEl.style.display = "block";
others.forEach(r => {
const bi = r.basic_information;
const div = document.createElement("div");
div.className = "modal-also-item";
const fmts = bi.formats?.map(f => f.name).join(", ") || "";
const lbl = bi.labels?.[0]?.name || "";
let desc = "";
if (bi.year) desc += bi.year;
if (lbl && lbl !== "Not On Label") desc += (desc ? " · " : "") + lbl;
if (fmts) desc += (desc ? " · " : "") + fmts;
div.textContent = desc || "Another pressing";
alsoList.appendChild(div);
});
} else {
alsoEl.style.display = "none";
}
document.querySelectorAll(".card.highlighted").forEach(c => c.classList.remove("highlighted"));
const card = document.getElementById("details-" + releaseId)?.closest(".card");
if (card) { card.classList.add("highlighted"); card.scrollIntoView({ behavior: "smooth", block: "center" }); }
loadModalTracklist(releaseId);
document.getElementById("randomModal").classList.add("visible");
document.body.style.overflow = "hidden";
}
function closeModal() {
document.getElementById("randomModal").classList.remove("visible");