-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriendly-chat.html
More file actions
2975 lines (2697 loc) · 126 KB
/
friendly-chat.html
File metadata and controls
2975 lines (2697 loc) · 126 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>Friendly Chat</title>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--chat-font-size: 13px;
--bg: #0d0d0f;
--surface: #16161a;
--surface2: #1e1e24;
--surface3: #26262e;
--border: rgba(255,255,255,0.07);
--border2: rgba(255,255,255,0.12);
--text: #e8e8f0;
--text-muted: #6b6b80;
--text-dim: #3d3d50;
--twitch: #9146ff;
--twitch-dim: rgba(145,70,255,0.15);
--twitch-border: rgba(145,70,255,0.35);
--kick: #53fc18;
--kick-dim: rgba(83,252,24,0.12);
--kick-border: rgba(83,252,24,0.3);
--accent: #7c6bff;
}
*{box-sizing:border-box;margin:0;padding:0;}
body{font-family:'DM Sans',sans-serif;background:var(--bg);color:var(--text);height:100vh;display:flex;flex-direction:column;overflow:hidden;}
/* OAUTH MODAL */
#oauth-overlay{position:fixed;inset:0;background:rgba(0,0,0,0.85);display:flex;align-items:center;justify-content:center;z-index:1000;backdrop-filter:blur(4px);}
#oauth-overlay.hidden{display:none;}
.oauth-modal{background:var(--surface);border:1px solid var(--border2);border-radius:16px;width:480px;max-width:95vw;overflow:hidden;}
.oauth-header{padding:24px 28px 20px;border-bottom:1px solid var(--border);}
.oauth-header h2{font-family:'JetBrains Mono',monospace;font-size:14px;font-weight:600;letter-spacing:0.04em;color:var(--text);margin-bottom:6px;}
.oauth-header p{font-size:13px;color:var(--text-muted);line-height:1.5;}
.oauth-platforms{padding:20px 28px;display:flex;flex-direction:column;gap:10px;}
.oauth-row{display:flex;align-items:center;gap:14px;padding:14px 16px;border-radius:12px;border:1px solid var(--border);background:var(--surface2);transition:border-color 0.2s,background 0.2s;}
.oauth-row.conn-twitch{border-color:var(--twitch-border);background:var(--twitch-dim);}
.oauth-row.conn-kick{border-color:var(--kick-border);background:var(--kick-dim);}
.plat-icon{width:36px;height:36px;border-radius:8px;display:flex;align-items:center;justify-content:center;flex-shrink:0;font-size:11px;font-weight:700;font-family:'JetBrains Mono',monospace;}
.plat-icon.twitch{background:var(--twitch);color:#fff;}
.plat-icon.kick{background:var(--kick);color:#0a0a0a;}
.plat-info{flex:1;}
.plat-info strong{font-size:14px;font-weight:500;display:block;}
.plat-info small{font-size:12px;color:var(--text-muted);}
.status-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0;}
.status-dot.on{background:#53fc18;}
.status-dot.off{background:var(--text-dim);}
.conn-btn{padding:7px 16px;border-radius:8px;font-size:12px;font-weight:500;font-family:'DM Sans',sans-serif;cursor:pointer;border:1px solid transparent;transition:all 0.15s;white-space:nowrap;}
.conn-btn.twitch-c{background:var(--twitch);color:#fff;border-color:var(--twitch);}
.conn-btn.kick-c{background:var(--kick);color:#0a0a0a;border-color:var(--kick);}
.conn-btn.discon{background:transparent;border-color:var(--border2);color:var(--text-muted);}
.conn-btn.discon:hover{border-color:#ff5555;color:#ff5555;}
.conn-btn.pending{opacity:0.6;cursor:wait;}
.oauth-footer{padding:16px 28px 24px;display:flex;align-items:center;justify-content:space-between;}
.skip-btn{font-size:13px;color:var(--text-muted);cursor:pointer;text-decoration:underline;text-underline-offset:2px;background:none;border:none;font-family:'DM Sans',sans-serif;}
.skip-btn:hover{color:var(--text);}
.continue-btn{padding:9px 22px;background:var(--accent);color:#fff;border:none;border-radius:8px;font-size:13px;font-weight:500;font-family:'DM Sans',sans-serif;cursor:pointer;}
.continue-btn:hover{opacity:0.85;}
/* MAIN APP */
#main-app{flex:1;display:flex;flex-direction:column;overflow:hidden;min-height:0;}
#main-app.hidden{display:none;}
.topbar{height:52px;background:var(--surface);border-bottom:1px solid var(--border);display:flex;align-items:center;padding:0 14px;gap:14px;flex-shrink:0;}
.app-logo{font-family:'JetBrains Mono',monospace;font-size:13px;font-weight:600;letter-spacing:0.06em;display:flex;align-items:center;gap:8px;flex-shrink:0;}
.ch-inputs{display:flex;gap:7px;flex:1;min-width:0;}
.ch-wrap{display:flex;align-items:center;border-radius:8px;overflow:hidden;border:1px solid var(--border);background:var(--surface2);flex:1;min-width:0;transition:border-color 0.2s;}
.ch-wrap:focus-within{border-color:var(--border2);}
.ch-wrap.act-twitch{border-color:var(--twitch-border);}
.ch-wrap.act-kick{border-color:var(--kick-border);}
.plat-tag{padding:0 9px;height:34px;display:flex;align-items:center;font-size:10px;font-weight:600;font-family:'JetBrains Mono',monospace;letter-spacing:0.05em;border-right:1px solid var(--border);white-space:nowrap;flex-shrink:0;}
.plat-tag.twitch{color:var(--twitch);background:var(--twitch-dim);}
.plat-tag.kick{color:var(--kick);background:var(--kick-dim);}
.ch-wrap input{flex:1;background:transparent;border:none;outline:none;padding:0 9px;font-size:12px;font-family:'JetBrains Mono',monospace;color:var(--text);height:34px;min-width:0;}
.ch-wrap input::placeholder{color:var(--text-dim);}
.join-btn{padding:0 12px;height:34px;border-radius:0;border:none;border-left:1px solid var(--border);background:transparent;color:var(--text-muted);font-size:11px;font-weight:500;font-family:'DM Sans',sans-serif;cursor:pointer;transition:all 0.15s;white-space:nowrap;flex-shrink:0;}
.join-btn:hover{background:var(--surface3);color:var(--text);}
.join-btn.joined{color:var(--accent);}
.acc-btn{display:flex;align-items:center;gap:8px;padding:6px 12px;border-radius:8px;background:var(--surface2);border:1px solid var(--border);cursor:pointer;font-size:12px;font-family:'DM Sans',sans-serif;color:var(--text-muted);transition:all 0.15s;flex-shrink:0;}
.acc-btn:hover{border-color:var(--border2);color:var(--text);}
.acc-dots{display:flex;gap:4px;align-items:center;}
.acc-dot{width:6px;height:6px;border-radius:50%;background:var(--text-dim);transition:background 0.3s;}
.acc-dot.on-twitch{background:var(--twitch);}
.acc-dot.on-kick{background:var(--kick);}
.app-body{flex:1;display:flex;overflow:hidden;min-height:0;}
.chat-col{flex:1;display:flex;flex-direction:column;overflow:hidden;min-height:0;}
.auth-banner{padding:7px 16px;background:rgba(255,200,0,0.07);border-bottom:1px solid rgba(255,200,0,0.15);display:flex;align-items:center;gap:10px;flex-shrink:0;font-size:12px;color:rgba(255,200,0,0.8);}
.auth-banner.hidden{display:none;}
.auth-banner-dot{width:5px;height:5px;border-radius:50%;background:rgba(255,200,0,0.8);flex-shrink:0;}
.banner-link{color:rgba(255,200,0,0.9);cursor:pointer;text-decoration:underline;text-underline-offset:2px;background:none;border:none;font-family:'DM Sans',sans-serif;font-size:12px;padding:0;}
.filter-bar{height:38px;background:var(--surface);border-bottom:1px solid var(--border);display:flex;align-items:center;padding:0 12px;gap:6px;flex-shrink:0;}
.font-size-ctrl{display:flex;align-items:center;gap:4px;margin-left:auto;}
.fs-btn{background:var(--surface2);border:1px solid var(--border);border-radius:5px;color:var(--text-muted);cursor:pointer;font-size:11px;font-weight:600;font-family:'JetBrains Mono',monospace;padding:2px 7px;transition:all 0.15s;line-height:1.4;}
.fs-btn:hover{border-color:var(--border2);color:var(--text);}
.fs-input{width:42px;background:var(--surface2);border:1px solid var(--border);border-radius:5px;color:var(--text);font-size:11px;font-family:'JetBrains Mono',monospace;padding:2px 4px;text-align:center;outline:none;-moz-appearance:textfield;}
.fs-input:focus{border-color:var(--border2);}
.fs-input::-webkit-outer-spin-button,.fs-input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0;}
.chip{padding:3px 10px;border-radius:20px;font-size:11px;font-weight:500;font-family:'JetBrains Mono',monospace;cursor:pointer;border:1px solid transparent;transition:all 0.15s;user-select:none;}
.chip.all{border-color:var(--border2);color:var(--text-muted);}
.chip.all.on{background:var(--surface3);color:var(--text);border-color:var(--border2);}
.chip.twitch{border-color:var(--twitch-border);color:var(--twitch);background:var(--twitch-dim);opacity:0.4;}
.chip.twitch.on{opacity:1;}
.chip.kick{border-color:var(--kick-border);color:var(--kick);background:var(--kick-dim);opacity:0.4;}
.chip.kick.on{opacity:1;}
.f-spacer{flex:1;}
.msg-ct{font-size:calc(var(--chat-font-size) - 2px);font-family:'JetBrains Mono',monospace;color:var(--text-dim);}
.feed{flex:1;overflow-y:auto;padding:6px 0;min-height:0;}
.feed::-webkit-scrollbar{width:3px;}
.feed::-webkit-scrollbar-thumb{background:var(--surface3);border-radius:2px;}
.msg{padding:4px 14px;display:flex;gap:9px;align-items:baseline;transition:background 0.1s;animation:fi 0.18s ease;}
.msg:hover{background:var(--surface2);}
@keyframes fi{from{opacity:0;transform:translateY(3px);}to{opacity:1;transform:translateY(0);}}
.msg.hide{display:none;}
.m-dot{width:3px;height:3px;border-radius:50%;flex-shrink:0;margin-top:7px;}
.m-dot.twitch{background:var(--twitch);}
.m-dot.kick{background:var(--kick);}
.m-time{font-size:10px;font-family:'JetBrains Mono',monospace;color:var(--text-muted);flex-shrink:0;min-width:38px;}
.m-author{font-size:var(--chat-font-size);font-weight:500;flex-shrink:0;}
.m-author.twitch{color:var(--twitch);}
.m-author.kick{color:var(--kick);}
.m-colon{color:var(--text-dim);margin-right:3px;font-size:var(--chat-font-size);}
.m-body{font-size:var(--chat-font-size);color:var(--text);line-height:1.4;word-break:break-word;}
.chat-link{color:#7c9fff;text-decoration:underline;text-underline-offset:2px;word-break:break-all;}
.chat-link:hover{color:#a8bfff;}
.twitch-emote{width:28px;height:28px;vertical-align:middle;margin:0 1px;}
.kick-emote{width:28px;height:28px;vertical-align:middle;margin:0 1px;}
.thirdparty-emote{height:28px;width:auto;vertical-align:middle;margin:0 1px;}
.badge{display:inline-flex;align-items:center;font-size:9px;font-family:'JetBrains Mono',monospace;padding:1px 5px;border-radius:3px;margin-right:4px;vertical-align:middle;font-weight:600;letter-spacing:0.04em;}
.badge.sub{background:rgba(145,70,255,0.25);color:var(--twitch);}
.badge.mod{background:rgba(83,252,24,0.2);color:var(--kick);}
.badge.vip{background:rgba(255,200,0,0.2);color:#ffcc00;}
.twitch-badges{display:inline-flex;align-items:center;gap:3px;margin-right:4px;vertical-align:middle;}
.twitch-badge-img{width:18px;height:18px;vertical-align:middle;border-radius:2px;image-rendering:auto;}
.twitch-badge-fallback{display:inline-flex;align-items:center;height:16px;padding:0 5px;border-radius:3px;font-size:9px;font-family:'JetBrains Mono',monospace;letter-spacing:0.04em;font-weight:600;text-transform:uppercase;line-height:1;background:rgba(145,70,255,0.2);color:#c6a5ff;}
.kick-badges{display:inline-flex;align-items:center;gap:3px;margin-right:4px;vertical-align:middle;flex-wrap:wrap;}
.kick-badge-label{display:inline-flex;align-items:center;height:16px;padding:0 5px;border-radius:3px;font-size:9px;font-family:'JetBrains Mono',monospace;letter-spacing:0.04em;font-weight:600;text-transform:uppercase;line-height:1;}
.kick-badge-img{width:16px;height:16px;border-radius:3px;vertical-align:middle;object-fit:cover;}
.kick-badge-moderator{background:rgba(83,252,24,0.2);color:var(--kick);}
.kick-badge-subscriber{background:rgba(145,70,255,0.25);color:#c6a5ff;}
.kick-badge-vip{background:rgba(255,200,0,0.2);color:#ffcc00;}
.kick-badge-event{background:rgba(124,107,255,0.24);color:#c4b8ff;}
.kick-badge-gifter,.kick-badge-gifted{background:rgba(255,90,138,0.2);color:#ff9fbc;}
.kick-badge-default{background:var(--surface3);color:var(--text-muted);}
.sys-msg{padding:3px 14px;font-size:calc(var(--chat-font-size) - 2px);font-family:'JetBrains Mono',monospace;color:#8888aa;display:flex;align-items:center;gap:8px;}
.sys-msg::before,.sys-msg::after{content:'';flex:1;height:1px;background:var(--border);}
.send-bar{background:var(--surface);border-top:1px solid var(--border);padding:9px 14px;display:flex;flex-direction:column;gap:7px;flex-shrink:0;}
.send-targets{display:flex;align-items:center;gap:5px;}
.s-label{font-size:11px;color:var(--text-dim);font-family:'JetBrains Mono',monospace;margin-right:3px;}
.t-chip{padding:3px 10px;border-radius:20px;font-size:11px;font-weight:500;font-family:'JetBrains Mono',monospace;cursor:pointer;border:1px solid transparent;transition:all 0.15s;user-select:none;}
.t-chip.all-t{border-color:var(--border2);color:var(--text-muted);opacity:0.5;}
.t-chip.all-t.sel{opacity:1;background:var(--surface3);}
.t-chip.twitch-t{border-color:var(--twitch-border);color:var(--twitch);opacity:0.3;}
.t-chip.twitch-t.sel{opacity:1;background:var(--twitch-dim);}
.t-chip.kick-t{border-color:var(--kick-border);color:var(--kick);opacity:0.3;}
.t-chip.kick-t.sel{opacity:1;background:var(--kick-dim);}
.t-chip.locked{opacity:0.15!important;cursor:not-allowed;}
.send-row{display:flex;gap:8px;align-items:center;}
.send-input{flex:1;background:var(--surface2);border:1px solid var(--border);border-radius:8px;padding:8px 12px;font-size:13px;font-family:'DM Sans',sans-serif;color:var(--text);outline:none;transition:border-color 0.2s;}
.send-input:focus{border-color:var(--border2);}
.send-input::placeholder{color:var(--text-dim);}
.send-input:disabled{opacity:0.4;cursor:not-allowed;}
.emote-btn{width:34px;height:34px;border-radius:8px;border:1px solid var(--border);background:var(--surface2);color:var(--text-muted);font-size:16px;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:all 0.15s;line-height:1;}
.emote-btn:hover{border-color:var(--border2);color:var(--text);background:var(--surface3);}
.emote-btn:disabled{opacity:0.3;cursor:not-allowed;}
.send-btn{padding:8px 18px;background:var(--accent);border:none;border-radius:8px;color:#fff;font-size:12px;font-weight:500;font-family:'DM Sans',sans-serif;cursor:pointer;transition:opacity 0.15s;flex-shrink:0;}
.send-btn:hover{opacity:0.85;}
.send-btn:disabled{opacity:0.3;cursor:not-allowed;}
/* Mention highlight — when someone says your name in chat */
.msg.mention-highlight{background:rgba(124,107,255,0.08);border-left:2px solid var(--accent);}
.msg.mention-highlight:hover{background:rgba(124,107,255,0.14);}
.mention-highlight .m-body .mention-self{background:rgba(124,107,255,0.25);color:#c4b8ff;border-radius:3px;padding:0 3px;font-weight:500;}
/* Autocomplete popup for emotes and mentions */
.autocomplete-popup{display:none;position:fixed;bottom:70px;left:0;right:0;background:var(--surface);border-top:1px solid var(--border2);max-height:360px;overflow-y:scroll;z-index:9999;}
.autocomplete-popup::-webkit-scrollbar{width:4px;}
.autocomplete-popup::-webkit-scrollbar-thumb{background:var(--surface3);border-radius:2px;}
.autocomplete-popup::-webkit-scrollbar{width:3px;}
.autocomplete-popup::-webkit-scrollbar-thumb{background:var(--surface3);border-radius:2px;}
.ac-item{display:flex;align-items:center;gap:10px;padding:7px 12px;cursor:pointer;transition:background 0.1s;font-size:13px;color:var(--text);}
.ac-item:hover,.ac-item.selected{background:var(--surface3);}
.ac-item img{width:24px;height:24px;object-fit:contain;flex-shrink:0;}
.ac-item-name{font-family:'JetBrains Mono',monospace;font-size:12px;}
.ac-item-source{font-size:10px;color:var(--text-dim);margin-left:auto;}
.ac-header{padding:4px 12px;font-size:10px;font-family:'JetBrains Mono',monospace;color:var(--text-dim);border-bottom:1px solid var(--border);letter-spacing:0.05em;}
.emote-grid-item{width:36px;height:36px;display:flex;align-items:center;justify-content:center;border-radius:6px;cursor:pointer;transition:background 0.1s;}
.emote-grid-item:hover{background:var(--surface3);}
.emote-grid-item img{width:28px;height:28px;object-fit:contain;}
/* User action menu */
.user-menu{position:fixed;background:var(--surface);border:1px solid var(--border2);border-radius:10px;min-width:180px;z-index:300;overflow:hidden;box-shadow:0 8px 32px rgba(0,0,0,0.4);}
.user-menu.hidden{display:none;}
.user-menu-name{padding:10px 14px;font-size:12px;font-weight:500;font-family:'JetBrains Mono',monospace;color:var(--text-muted);border-bottom:1px solid var(--border);background:var(--surface2);}
.user-menu-actions{display:flex;flex-direction:column;}
.um-action{padding:9px 14px;font-size:13px;color:var(--text);cursor:pointer;transition:background 0.1s;display:flex;align-items:center;gap:8px;border:none;background:transparent;font-family:'DM Sans',sans-serif;width:100%;text-align:left;}
.um-action:hover{background:var(--surface3);}
.um-action.danger{color:#ff6b6b;}
.um-action.danger:hover{background:rgba(255,107,107,0.12);}
.um-sep{height:1px;background:var(--border);margin:2px 0;}
.empty{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;color:#8888aa;}
.empty-icon{font-size:28px;opacity:0.25;font-family:'JetBrains Mono',monospace;}
.empty p{font-size:var(--chat-font-size);font-family:'JetBrains Mono',monospace;}
#toast{position:fixed;bottom:76px;left:50%;transform:translateX(-50%) translateY(12px);background:var(--surface3);border:1px solid var(--border2);border-radius:8px;padding:7px 14px;font-size:12px;color:var(--text);font-family:'JetBrains Mono',monospace;opacity:0;transition:all 0.22s;pointer-events:none;z-index:500;white-space:nowrap;}
#toast.show{opacity:1;transform:translateX(-50%) translateY(0);}
.file-warning{display:none;margin:0 28px 16px;padding:12px 14px;background:rgba(255,160,0,0.12);border:1px solid rgba(255,160,0,0.35);border-radius:8px;}
.file-warning.visible{display:block;}
.file-warning p{font-size:12px;color:rgba(255,180,0,0.95);line-height:1.6;font-family:'JetBrains Mono',monospace;}
.file-warning strong{font-weight:600;}
.file-warning code{background:rgba(255,255,255,0.1);padding:1px 6px;border-radius:4px;font-size:11px;}
</style>
</head>
<body>
<div id="oauth-overlay">
<div class="oauth-modal">
<div class="oauth-header">
<h2>FRIENDLY CHAT // CONNECT PLATFORMS</h2>
<p>Sign in to send messages. You can still watch and read chats without signing in.</p>
</div>
<div class="file-warning" id="file-warning">
<p><strong>Not running from a local server.</strong><br>
OAuth login requires a local server. Open a terminal in the folder containing this file and run:<br><br>
<code>python -m http.server 8080</code><br><br>
Then open <code>http://localhost:8080/friendly-chat.html</code> in your browser. Connect buttons will not work until you do this.</p>
</div>
<div class="oauth-platforms">
<div class="oauth-row" id="row-twitch">
<div class="plat-icon twitch">TW</div>
<div class="plat-info"><strong>Twitch</strong><small id="st-twitch">Not connected</small></div>
<div class="status-dot off" id="sd-twitch"></div>
<button class="conn-btn twitch-c" id="btn-twitch" onclick="startOAuth('twitch')">Connect</button>
</div>
<div class="oauth-row" id="row-kick">
<div class="plat-icon kick">KI</div>
<div class="plat-info"><strong>Kick</strong><small id="st-kick">Not connected</small></div>
<div class="status-dot off" id="sd-kick"></div>
<button class="conn-btn kick-c" id="btn-kick" onclick="startOAuth('kick')">Connect</button>
</div>
</div>
<div class="oauth-footer">
<button class="skip-btn" onclick="dismiss()">Skip for now (read-only)</button>
<button class="continue-btn" onclick="dismiss()">Continue</button>
</div>
</div>
</div>
<div id="main-app" class="hidden">
<div class="topbar">
<div class="app-logo"><span>FRIENDLY CHAT</span></div>
<div class="ch-inputs">
<div class="ch-wrap" id="cw-twitch">
<span class="plat-tag twitch">TWITCH</span>
<input type="text" id="ci-twitch" placeholder="channel name" />
<button class="join-btn" id="jb-twitch" onclick="joinCh('twitch')">Join</button>
</div>
<div class="ch-wrap" id="cw-kick">
<span class="plat-tag kick">KICK</span>
<input type="text" id="ci-kick" placeholder="channel name" />
<button class="join-btn" id="jb-kick" onclick="joinCh('kick')">Join</button>
</div>
</div>
<button class="acc-btn" onclick="openOAuth()">
<div class="acc-dots">
<div class="acc-dot" id="ad-twitch"></div>
<div class="acc-dot" id="ad-kick"></div>
</div>
<span>Accounts</span>
</button>
</div>
<div class="app-body">
<div class="chat-col">
<div class="auth-banner hidden" id="auth-banner">
<div class="auth-banner-dot"></div>
<span>Read-only mode. <button class="banner-link" onclick="openOAuth()">Connect accounts</button> to send messages.</span>
</div>
<div class="filter-bar">
<span class="chip all on" id="fc-all" onclick="toggleFilterAll()">ALL</span>
<span class="chip twitch" id="fc-twitch" onclick="toggleFilter('twitch')">TWITCH</span>
<span class="chip kick" id="fc-kick" onclick="toggleFilter('kick')">KICK</span>
<div class="font-size-ctrl">
<button class="fs-btn" onclick="adjustFontSize(-1)" title="Decrease font size">A−</button>
<input type="number" id="fs-input" class="fs-input" value="13" min="9" max="22" title="Font size in px" onchange="setFontSizeFromInput()" onkeydown="if(event.key==='Enter') setFontSizeFromInput()">
<button class="fs-btn" onclick="adjustFontSize(1)" title="Increase font size">A+</button>
</div>
<span class="f-spacer"></span>
<span class="msg-ct" id="msg-ct">0 messages</span>
</div>
<div class="feed" id="feed">
<div class="empty" id="empty-state">
<div class="empty-icon">◈</div>
<p>join a channel to start watching</p>
</div>
</div>
<!-- Autocomplete popup for emotes (:) and mentions (@) — rendered outside send-bar to avoid clipping -->
<div class="send-bar">
<div class="send-targets">
<span class="s-label">TO:</span>
<span class="t-chip all-t sel" id="tc-all" onclick="toggleTargetAll()">ALL</span>
<span class="t-chip twitch-t" id="tc-twitch" onclick="toggleTarget('twitch')">TWITCH</span>
<span class="t-chip kick-t" id="tc-kick" onclick="toggleTarget('kick')">KICK</span>
</div>
<div class="send-row">
<button class="emote-btn" id="emote-btn" onclick="toggleEmotePicker()" title="Browse emotes">😊</button>
<input type="text" class="send-input" id="send-input" placeholder="Type a message..." disabled autocomplete="off" />
<button class="send-btn" id="send-btn" onclick="sendMsg()" disabled>Send</button>
</div>
</div>
<!-- User action menu (shown on username click) -->
<div class="user-menu hidden" id="user-menu">
<div class="user-menu-name" id="user-menu-name"></div>
<div class="user-menu-actions" id="user-menu-actions"></div>
</div>
</div>
</div>
</div>
<div id="toast"></div>
<!-- Autocomplete popup rendered at body level to avoid any overflow clipping -->
<div class="autocomplete-popup" id="autocomplete-popup"></div>
<script>
// Credentials are loaded from the server at startup via /config.
// Nothing sensitive is hardcoded here.
let TWITCH_CLIENT_ID = '';
let KICK_CLIENT_ID_PUB = '';
async function loadConfig(retries = 5, delayMs = 800) {
dbg('config', 'Loading /config', { retries, delayMs });
for(let attempt = 1; attempt <= retries; attempt++) {
try {
const r = await fetch('/config');
if(!r.ok) throw new Error(`HTTP ${r.status}`);
const c = await r.json();
TWITCH_CLIENT_ID = c.twitch?.client_id || '';
KICK_CLIENT_ID_PUB = c.kick?.client_id || '';
dbg('config', 'Loaded /config successfully', {
hasKickClientId: !!KICK_CLIENT_ID_PUB,
hasTwitchClientId: !!TWITCH_CLIENT_ID
});
CFG.twitch.url = `https://id.twitch.tv/oauth2/authorize?client_id=${TWITCH_CLIENT_ID}&scope=chat%3Aread+chat%3Aedit+user%3Awrite%3Achat+moderator%3Amanage%3Abanned_users+moderator%3Amanage%3Achat_messages+moderator%3Aread%3Afollowers+user%3Aread%3Aemotes&response_type=token`;
return;
} catch(e) {
dbg('config', `Attempt ${attempt} failed`, e.message);
if(attempt < retries) {
await new Promise(res => setTimeout(res, delayMs));
} else {
console.warn('Could not load config after', retries, 'attempts:', e.message);
}
}
}
}
const CFG = {
twitch: {
name:'Twitch', logoText:'TW', logoBg:'#9146ff', logoColor:'#fff',
scopes:['Read your chat messages','Send chat messages','View your profile information'],
authBtnBg:'#9146ff', authBtnColor:'#fff', authBtnLabel:'Authorize with Twitch',
url:'' // populated after loadConfig()
},
kick: {
name:'Kick', logoText:'KI', logoBg:'#53fc18', logoColor:'#0a0a0a',
scopes:['Read your chat messages','Send chat messages','Access your channel information'],
authBtnBg:'#53fc18', authBtnColor:'#0a0a0a', authBtnLabel:'Authorize with Kick',
url: null
}
};
const S = {
auth:{twitch:false,kick:false},
tokens:{twitch:null,kick:null},
channels:{twitch:null,kick:null},
filter: null, target: null, msgCount:0,
currentPlatform:null,
sockets:{twitch:null,kick:null},
intervals:{twitch:null,kick:null},
// Twitch send helpers — cached to avoid re-fetching on every message
twitchUserId:null, twitchUserLogin:null,
twitchBroadcasterId:null, twitchBroadcasterChannel:null,
// Kick broadcaster ID cache
kickBroadcasterId:null, kickBroadcasterChannel:null,
kickUserLogin:null,
// Third-party emote maps: { emoteName -> { url, source } }
// Keyed per platform so Twitch and Kick have separate sets
thirdPartyEmotes: { twitch: {}, kick: {} },
// Native emotes fetched from platform APIs: { emoteName -> { url, source } }
nativeEmotes: { twitch: {}, kick: {} },
// Twitch badge set cache { global: {setId -> versions}, channel: {setId -> versions} }
twitchBadges: { global: {}, channel: {}, broadcasterId: null },
// Recent chatters for @mention autocomplete { "platform:name" -> { name, platform } }
recentChatters: new Map(),
// Per-platform moderation capability for the currently joined channel
canModerate: { twitch: false, kick: false },
};
const KICK_EMOTE_CACHE_KEY = 'kick_emotes_cache_v1';
const KICK_EMOTE_CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
// ALL_PLATFORMS must be defined before S.filter and S.target are initialized
const ALL_PLATFORMS = ['twitch','kick'];
S.filter = new Set(ALL_PLATFORMS);
S.target = new Set(ALL_PLATFORMS);
function ftime(){const d=new Date();return `${d.getHours().toString().padStart(2,'0')}:${d.getMinutes().toString().padStart(2,'0')}`;}
function dbg(scope, message, meta = null) {
const ts = new Date().toISOString();
let line = `[${ts}] [${scope}] ${message}`;
if(meta !== null && meta !== undefined) {
try {
line += ` | ${typeof meta === 'string' ? meta : JSON.stringify(meta)}`;
} catch(_) {}
}
console.log(line);
}
window.addEventListener('error', (e) => {
dbg('window.error', e.message, { file: e.filename, line: e.lineno, col: e.colno });
});
window.addEventListener('unhandledrejection', (e) => {
const reason = e.reason?.message || e.reason || 'unknown rejection';
dbg('window.unhandledrejection', String(reason));
});
function getRedirectUri() {
return window.location.origin + window.location.pathname;
}
function setPkceVerifier(platform, verifier) {
if(!platform || !verifier) return;
const key = `${platform}_verifier`;
sessionStorage.setItem(key, verifier);
localStorage.setItem(key, verifier);
}
function getPkceVerifier(platform, openerWindow = null) {
if(!platform) return '';
const key = `${platform}_verifier`;
let fromOpener = '';
try {
fromOpener = openerWindow?.sessionStorage?.getItem(key) || '';
} catch(_) {
// Cross-origin access to opener can throw SecurityError; fall back
// to the popup's own storage (which shares localStorage with the opener).
fromOpener = '';
}
return fromOpener
|| sessionStorage.getItem(key)
|| localStorage.getItem(key)
|| '';
}
function clearPkceVerifier(platform) {
if(!platform) return;
const key = `${platform}_verifier`;
sessionStorage.removeItem(key);
localStorage.removeItem(key);
}
function normalizeChannelName(name) {
return String(name || '').trim().toLowerCase();
}
function getKickEmoteCache() {
try {
return JSON.parse(localStorage.getItem(KICK_EMOTE_CACHE_KEY) || '{}') || {};
} catch(_) {
return {};
}
}
function saveKickEmoteCache(cache) {
try {
localStorage.setItem(KICK_EMOTE_CACHE_KEY, JSON.stringify(cache || {}));
} catch(_) {}
}
function loadKickCachedEmotes(channel) {
const cache = getKickEmoteCache();
const key = normalizeChannelName(channel);
const rec = cache[key];
if(!rec || !rec.ts || !rec.emotes) return false;
if(Date.now() - rec.ts > KICK_EMOTE_CACHE_TTL_MS) {
delete cache[key];
saveKickEmoteCache(cache);
return false;
}
S.nativeEmotes.kick = { ...rec.emotes, ...S.nativeEmotes.kick };
return Object.keys(rec.emotes).length > 0;
}
function cacheKickEmotes(channel) {
const key = normalizeChannelName(channel);
if(!key) return;
const cache = getKickEmoteCache();
cache[key] = { ts: Date.now(), emotes: S.nativeEmotes.kick || {} };
saveKickEmoteCache(cache);
}
function setCanModerate(platform, canModerate) {
if(!platform || !(platform in S.canModerate)) return;
S.canModerate[platform] = !!canModerate;
}
function emitOAuthCallback(platform, payload) {
if(!platform) return;
const key = `oauth_callback_${platform}`;
try {
localStorage.setItem(key, JSON.stringify({
...payload,
platform,
type: 'oauth_callback',
ts: Date.now()
}));
} catch(_) {}
}
// On page load, check if we're the OAuth redirect landing inside a popup.
// If so, pass the token back to the parent window and close immediately.
// This avoids the popup re-running the full app and fighting with the parent.
(function handleOAuthCallback() {
const hash = window.location.hash;
const search = window.location.search;
if(!hash && !search) return;
const fromHash = new URLSearchParams(hash.replace('#',''));
const fromSearch = new URLSearchParams(search.replace('?',''));
const token = fromHash.get('access_token') || fromSearch.get('access_token');
const code = fromSearch.get('code');
const error = fromHash.get('error') || fromSearch.get('error');
const errorDesc= fromHash.get('error_description') || fromSearch.get('error_description');
const platform = fromHash.get('state') || fromSearch.get('state');
if(!platform || !CFG[platform]) return;
if(window.opener && !window.opener.closed) {
if(code && platform === 'kick') {
// Kick PKCE: exchange the code for a token via the local proxy server,
// then post the resulting token back to the parent window
const verifier = window.opener.sessionStorage?.getItem('kick_verifier')
|| sessionStorage.getItem('kick_verifier');
fetch('/kick-token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code, code_verifier: verifier }),
})
.then(r => r.json())
.then(d => {
window.opener.postMessage({
type: 'oauth_callback',
platform: 'kick',
token: d.access_token || null,
refresh_token: d.refresh_token || null,
expires_in: d.expires_in || null,
error: d.error || null,
errorDesc: d.detail || null
}, window.location.origin);
window.close();
})
.catch(e => {
window.opener.postMessage({
type: 'oauth_callback', platform: 'kick',
token: null, error: e.message
}, window.location.origin);
window.close();
});
return;
}
// Twitch implicit flow — token is in the hash directly
window.opener.postMessage({
type: 'oauth_callback', platform,
token: token || null,
error: error || null, errorDesc: errorDesc || null
}, window.location.origin);
window.close();
return;
}
// Fallback: main tab full-page redirect
if(token) {
history.replaceState(null, '', window.location.pathname);
markConnected(platform, token);
}
})();
// Show the file:// warning banner if not running from a proper server
(function checkProtocol() {
if(window.location.protocol === 'file:') {
document.getElementById('file-warning').classList.add('visible');
}
})();
// Load credentials from server then restore any saved sessions
loadConfig().then(() => {
restoreTwitchSession();
restoreKickSession();
});
function restoreKickSession() {
const refreshToken = localStorage.getItem('kick_refresh_token');
const accessToken = localStorage.getItem('kick_access_token');
const expiry = parseInt(localStorage.getItem('kick_token_expiry') || '0', 10);
if(!refreshToken) return;
if(accessToken && expiry > Date.now() + 300000) {
markConnected('kick', accessToken);
return;
}
fetch('/kick-refresh', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ refresh_token: refreshToken })
})
.then(r => r.json())
.then(d => {
if(d.access_token) {
localStorage.setItem('kick_access_token', d.access_token);
localStorage.setItem('kick_refresh_token', d.refresh_token || refreshToken);
localStorage.setItem('kick_token_expiry', Date.now() + ((d.expires_in || 3600) * 1000));
markConnected('kick', d.access_token);
} else {
localStorage.removeItem('kick_refresh_token');
localStorage.removeItem('kick_access_token');
localStorage.removeItem('kick_token_expiry');
}
})
.catch(() => {});
}
function restoreTwitchSession() {
const token = localStorage.getItem('twitch_access_token');
if(!token) return;
fetch('https://id.twitch.tv/oauth2/validate', {
headers: { 'Authorization': `OAuth ${token}` }
})
.then(r => r.ok ? r.json() : null)
.then(d => {
if(d && d.client_id) { markConnected('twitch', token); }
else { localStorage.removeItem('twitch_access_token'); }
})
.catch(() => markConnected('twitch', token));
}
// Kick uses PKCE Authorization Code flow via the local proxy server.
// OAuth callback flow.
function startOAuth(p) {
dbg('oauth', 'Start requested', { platform: p, protocol: window.location.protocol });
if(window.location.protocol === 'file:') {
showToast('Run from a local server first — see the warning above');
return;
}
if(p === 'kick') { startKickOAuth(); return; }
S.currentPlatform = p;
const c = CFG[p];
const btn = document.getElementById(`btn-${p}`);
btn.textContent = 'Connecting...';
btn.className = 'conn-btn pending';
// Build redirect_uri dynamically from the current page URL so it always
// matches exactly what is registered in the platform developer console
const redirectUri = encodeURIComponent(window.location.origin + window.location.pathname);
const oauthUrl = c.url + `&redirect_uri=${redirectUri}&state=${p}`;
// Open a real browser popup pointing at the platform's auth page
const width = 500, height = 700;
const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
const popup = window.open(oauthUrl, `${p}_oauth`, `width=${width},height=${height},left=${left},top=${top},toolbar=no,menubar=no`);
if(!popup) {
// Browser blocked the popup — fall back to redirecting the current tab
showToast('Popup blocked — redirecting in current tab...');
setTimeout(() => { window.location.href = oauthUrl; }, 1000);
return;
}
// Listen for the token being posted back from the popup via postMessage
function onMessage(e) {
if(e.origin !== window.location.origin) return;
if(!e.data || e.data.type !== 'oauth_callback') return;
if(e.data.platform !== p) return;
window.removeEventListener('message', onMessage);
clearInterval(closedPoll);
if(e.data.token) {
// Persist Twitch token so it survives page reloads.
if(p === 'twitch') localStorage.setItem('twitch_access_token', e.data.token);
markConnected(p, e.data.token);
} else {
resetConnectBtn(p);
const desc = (e.data.errorDesc || e.data.error || 'unknown error').replace(/\+/g,' ');
showToast(`Auth failed: ${desc}`);
}
}
window.addEventListener('message', onMessage);
// Fallback: if user manually closes popup without authorizing
const closedPoll = setInterval(() => {
let wasClosed = false;
try {
wasClosed = !!popup.closed;
} catch(_) {
// Some OAuth pages enforce policies that temporarily block access to
// popup.closed while the popup is on a different origin. Ignore that and
// keep waiting for postMessage or for the popup to return/close.
return;
}
if(wasClosed) {
clearInterval(closedPoll);
window.removeEventListener('message', onMessage);
if(!S.tokens[p]) {
resetConnectBtn(p);
showToast('Authorization cancelled');
}
}
}, 400);
}
// ── Kick PKCE OAuth flow ──────────────────────────────────────────────────────
// Kick requires Authorization Code + PKCE. The code verifier stays in the
// browser; the code exchange happens via the local proxy server (server.js)
// which holds the client secret securely.
function base64urlEncode(buf) {
return btoa(String.fromCharCode(...new Uint8Array(buf)))
.replace(/\+/g,'-').replace(/\//g,'_').replace(/=+$/,'');
}
async function generatePKCE() {
const verifier = base64urlEncode(crypto.getRandomValues(new Uint8Array(32)));
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier));
const challenge = base64urlEncode(digest);
return { verifier, challenge };
}
async function startKickOAuth() {
const btn = document.getElementById('btn-kick');
btn.textContent = 'Connecting...';
btn.className = 'conn-btn pending';
// Get Kick client ID — already loaded into KICK_CLIENT_ID_PUB from /config
// If still empty, try fetching directly from the proxy
let clientId = KICK_CLIENT_ID_PUB;
if(!clientId) {
try {
const r = await fetch('/config');
if(r.ok) {
const d = await r.json();
clientId = d.kick?.client_id || '';
if(clientId) KICK_CLIENT_ID_PUB = clientId;
}
} catch(e) {}
}
if(!clientId) {
resetConnectBtn('kick');
showToast('Kick: could not reach proxy — check kick.proxy_url in config.json');
return;
}
// Generate PKCE challenge
const { verifier, challenge } = await generatePKCE();
// Store verifier in sessionStorage so the popup callback page can retrieve it
sessionStorage.setItem('kick_verifier', verifier);
const redirectUri = encodeURIComponent(`http://localhost:8080/friendly-chat.html`);
const state = 'kick';
const oauthUrl = `https://id.kick.com/oauth/authorize`
+ `?response_type=code`
+ `&client_id=${clientId}`
+ `&redirect_uri=${redirectUri}`
+ `&scope=user%3Aread+channel%3Aread+chat%3Awrite+moderation%3Aban+moderation%3Achat_message%3Amanage`
+ `&code_challenge=${challenge}`
+ `&code_challenge_method=S256`
+ `&state=${state}`;
S.currentPlatform = 'kick';
const width = 500, height = 700;
const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
const popup = window.open(oauthUrl, 'kick_oauth',
`width=${width},height=${height},left=${left},top=${top},toolbar=no,menubar=no`);
if(!popup) {
showToast('Popup blocked — redirecting in current tab...');
setTimeout(() => { window.location.href = oauthUrl; }, 1000);
return;
}
function onMessage(e) {
if(e.origin !== window.location.origin) return;
if(!e.data || e.data.type !== 'oauth_callback' || e.data.platform !== 'kick') return;
window.removeEventListener('message', onMessage);
clearInterval(closedPoll);
if(e.data.token) {
if(e.data.refresh_token) {
localStorage.setItem('kick_refresh_token', e.data.refresh_token);
localStorage.setItem('kick_access_token', e.data.token);
const expiry = Date.now() + ((e.data.expires_in || 3600) * 1000);
localStorage.setItem('kick_token_expiry', expiry);
}
markConnected('kick', e.data.token);
} else {
resetConnectBtn('kick');
showToast(`Kick auth failed: ${(e.data.errorDesc || e.data.error || 'unknown').replace(/\+/g,' ')}`);
}
}
window.addEventListener('message', onMessage);
const closedPoll = setInterval(() => {
if(popup.closed) {
clearInterval(closedPoll);
window.removeEventListener('message', onMessage);
if(!S.tokens.kick) { resetConnectBtn('kick'); showToast('Kick authorization cancelled'); }
}
}, 400);
}
function markConnected(p, token) {
dbg('oauth', 'Platform connected', { platform: p, hasToken: !!token });
S.auth[p] = true;
S.tokens[p] = token;
document.getElementById(`row-${p}`).className = `oauth-row conn-${p}`;
document.getElementById(`sd-${p}`).className = 'status-dot on';
fetchDisplayName(p, token);
// Fetch native emotes for Twitch after connecting (needs user ID first)
if(p === 'twitch') {
fetch('https://api.twitch.tv/helix/users', {
headers: { 'Authorization': `Bearer ${token}`, 'Client-Id': TWITCH_CLIENT_ID }
})
.then(r => r.ok ? r.json() : null)
.then(d => {
if(d?.data?.[0]) {
S.twitchUserId = d.data[0].id;
S.twitchUserLogin = d.data[0].login;
fetchTwitchNativeEmotes();
// If already watching a channel, reconnect IRC with real credentials
// so Twitch sends USERSTATE with emote-sets (same as Chatterino's reconnect on login)
if(S.channels.twitch) {
connectTwitch(S.channels.twitch);
}
}
})
.catch(() => {});
}
const btn = document.getElementById(`btn-${p}`);
btn.textContent = 'Disconnect';
btn.className = 'conn-btn discon';
btn.onclick = () => disconnectPlatform(p);
refreshAccDots(); refreshTargets();
showToast(`${CFG[p].name} connected`);
S.currentPlatform = null;
}
function resetConnectBtn(p) {
dbg('oauth', 'Reset connect button', { platform: p });
const btn = document.getElementById(`btn-${p}`);
btn.textContent = 'Connect';
btn.className = `conn-btn ${p}-c`;
btn.onclick = () => startOAuth(p);
S.currentPlatform = null;
}
// Fetch the authenticated user's display name to show in the status line
function fetchDisplayName(p, token) {
const statusEl = document.getElementById(`st-${p}`);
statusEl.textContent = 'Connected';
if(p === 'twitch') {
fetch('https://api.twitch.tv/helix/users', {
headers: {
'Authorization': `Bearer ${token}`,
'Client-Id': extractClientId(CFG.twitch.url)
}
})
.then(r => r.json())
.then(d => {
const name = d.data?.[0]?.display_name;
const login = d.data?.[0]?.login;
if(name) statusEl.textContent = `Connected as ${name}`;
if(login) S.twitchUserLogin = login;
})
.catch(() => {});
} else if(p === 'kick') {
fetch('https://api.kick.com/public/v1/users', {
headers: { 'Authorization': `Bearer ${token}` }
})
.then(r => r.json())
.then(d => {
const name = d.data?.[0]?.name || d.data?.[0]?.username;
if(name) { statusEl.textContent = `Connected as ${name}`; S.kickUserLogin = name; }
})
.catch(() => {});
}
}
function extractClientId(url) {
if(TWITCH_CLIENT_ID) return TWITCH_CLIENT_ID;
const m = url.match(/client_id=([^&]+)/);
return m ? m[1] : '';
}
function denyOAuth() {
const p = S.currentPlatform;
if(p) resetConnectBtn(p);
showToast('Authorization denied');
}
function disconnectPlatform(p) {
S.auth[p] = false;
S.tokens[p] = null;
setCanModerate(p, false);
if(p === 'kick') {
localStorage.removeItem('kick_refresh_token');
localStorage.removeItem('kick_access_token');
localStorage.removeItem('kick_token_expiry');
}
if(p === 'twitch') { localStorage.removeItem('twitch_access_token'); S.twitchUserLogin = null; S.twitchUserId = null; }
if(p === 'kick') { S.kickUserLogin = null; }
document.getElementById(`row-${p}`).className = 'oauth-row';
document.getElementById(`sd-${p}`).className = 'status-dot off';
document.getElementById(`st-${p}`).textContent = 'Not connected';
const btn = document.getElementById(`btn-${p}`);
btn.textContent = 'Connect';
btn.className = `conn-btn ${p}-c`;
btn.onclick = () => startOAuth(p);
refreshAccDots(); refreshTargets();
showToast(`${CFG[p].name} disconnected`);
}
function dismiss() {
document.getElementById('oauth-overlay').classList.add('hidden');
document.getElementById('main-app').classList.remove('hidden');
refreshAccDots(); refreshTargets(); refreshBanner();
}
function openOAuth() { document.getElementById('oauth-overlay').classList.remove('hidden'); }
function refreshAccDots() {
['twitch','kick'].forEach(p => {
document.getElementById(`ad-${p}`).className = `acc-dot${S.auth[p]?' on-'+p:''}`;
});
}
function refreshBanner() {
const any = Object.values(S.auth).some(Boolean);
document.getElementById('auth-banner').classList.toggle('hidden', any);
}
function refreshTargets() {
const any = Object.values(S.auth).some(Boolean);
document.getElementById('send-input').disabled = !any;
document.getElementById('send-btn').disabled = !any;
const anyChannel = Object.values(S.channels).some(Boolean);
const emoteBtn = document.getElementById('emote-btn');
emoteBtn.disabled = !anyChannel;
emoteBtn.classList.toggle('locked', !anyChannel);
document.getElementById('send-input').placeholder = any ? 'Type a message...' : 'Connect an account to send messages...';
ALL_PLATFORMS.forEach(p => {
document.getElementById(`tc-${p}`).classList.toggle('locked', !S.auth[p]);
});
syncTargetChips();
}
// S.filter is now a Set of visible platforms — initialized above after ALL_PLATFORMS
function syncFilterChips() {
const all = ALL_PLATFORMS.every(p => S.filter.has(p));
document.getElementById('fc-all').classList.toggle('on', all);
ALL_PLATFORMS.forEach(p => {
document.getElementById(`fc-${p}`).classList.toggle('on', S.filter.has(p));
});
}
function applyFilter() {
document.querySelectorAll('.msg').forEach(m => {
m.classList.toggle('hide', !S.filter.has(m.dataset.platform));
});
}
// ── Font size control ────────────────────────────────────────────────────────
let chatFontSize = parseInt(localStorage.getItem('chatFontSize') || '13', 10);
applyFontSize(); // restore saved preference immediately
function applyFontSize() {
document.documentElement.style.setProperty('--chat-font-size', chatFontSize + 'px');
const input = document.getElementById('fs-input');
if(input) input.value = chatFontSize;
localStorage.setItem('chatFontSize', chatFontSize);
}
function adjustFontSize(delta) {
chatFontSize = Math.min(22, Math.max(9, chatFontSize + delta));