-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlibs.js
More file actions
1093 lines (1035 loc) · 38.8 KB
/
libs.js
File metadata and controls
1093 lines (1035 loc) · 38.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
function log(msg) {
if (devmode) { // only show log if in dev mode; else it will just spam the log and cause higher resource usage
console.log(msg);
}
}
const SSAPP_ACCEPT_LANGUAGE = window.SSAPP_ACCEPT_LANGUAGE || ((window.ssappLocale && window.ssappLocale.acceptLanguage) || 'en-US,en;q=0.9');
window.SSAPP_ACCEPT_LANGUAGE = SSAPP_ACCEPT_LANGUAGE;
window.onerror = function(message, source, lineno, colno, error) {
console.error("Global error:", message, "at", source, ":", lineno);
return true;
};
window.addEventListener('unhandledrejection', (event) => {
console.error('Unhandled promise rejection:', event.reason);
});
function getOperatingSystem() {
const platform = navigator.platform.toLowerCase();
if (platform.includes('mac')) return 'mac';
if (platform.includes('linux')) return 'linux';
return 'windows'; // Default to Windows for other cases
}
function getConfigFileName(os) {
switch (os) {
case 'mac':
return 'config_mac_0.json';
case 'linux':
return 'config_linux_0.json';
default:
return 'config_0.json';
}
}
function compareVersions(version1, version2) {
const parts1 = version1.split('.').map(Number);
const parts2 = version2.split('.').map(Number);
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
const num1 = parts1[i] || 0;
const num2 = parts2[i] || 0;
if (num1 > num2) return 1;
if (num2 > num1) return -1;
}
return 0;
}
function extractRumbleIdentifiersFromHtml(html) {
if (!html || typeof html !== 'string') {
return {
chatId: null,
videoId: null,
fullPath: null
};
}
const buildVideoInfoFromCandidate = (candidate) => {
if (!candidate || typeof candidate !== 'string') {
return {
videoId: null,
fullPath: null
};
}
try {
const parsed = candidate.startsWith('http')
? new URL(candidate)
: new URL(candidate, 'https://rumble.com');
const pathname = (parsed.pathname || '').trim();
const match = pathname.match(/\/((?:v|p)[a-zA-Z0-9]+[^\/]*\.html)/i);
if (!match || !match[1]) {
return {
videoId: null,
fullPath: null
};
}
const fullPath = match[1];
const idMatch = fullPath.match(/^((?:v|p)[a-zA-Z0-9]+)/i);
return {
videoId: idMatch && idMatch[1] ? idMatch[1] : null,
fullPath
};
} catch (_) {
return {
videoId: null,
fullPath: null
};
}
};
const directChatPatterns = [
/chat\/popup\/(\d+)/i,
/(?:^|[^a-z])video_id\s*[:=]\s*["']?(\d+)/i,
/["']video_id["']\s*[:=]\s*["']?(\d+)/i,
/["']chatId["']\s*[:=]\s*["']?(\d+)/i
];
let chatId = null;
for (const regex of directChatPatterns) {
const match = html.match(regex);
if (match && match[1] && /^\d+$/.test(match[1])) {
chatId = match[1];
break;
}
}
const pageUrlPatterns = [
/<link[^>]+rel=["']?canonical["']?[^>]*href=["']?([^"' >]+)/i,
/<meta[^>]+property=["']?og:url["']?[^>]*content=["']?([^"' >]+)/i,
/<meta[^>]+name=["']?twitter:url["']?[^>]*content=["']?([^"' >]+)/i,
/<meta[^>]+itemprop=["']?url["']?[^>]*content=["']?([^"' >]+)/i
];
for (const regex of pageUrlPatterns) {
const match = html.match(regex);
if (match && match[1]) {
const info = buildVideoInfoFromCandidate(match[1]);
if (info.videoId || info.fullPath) {
return {
chatId,
videoId: info.videoId,
fullPath: info.fullPath
};
}
}
}
const liveTilePatterns = [
/<div[^>]+data-video-id=["'](\d+)["'][\s\S]{0,1800}?(?:thumbnail__thumb--live|videostream__footer--live)[\s\S]{0,1200}?href=["']\/([^"']+\.html)/i,
/<div[^>]+data-video-id=["'](\d+)["'][\s\S]{0,1800}?(?:thumbnail__thumb--live|videostream__status--live|videostream__footer--live)/i
];
for (const regex of liveTilePatterns) {
const match = html.match(regex);
if (!match || !match[1] || !/^\d+$/.test(match[1])) {
continue;
}
const info = match[2]
? buildVideoInfoFromCandidate(match[2])
: { videoId: null, fullPath: null };
return {
chatId: match[1],
videoId: info.videoId,
fullPath: info.fullPath
};
}
return {
chatId,
videoId: null,
fullPath: null
};
}
async function getRumbleVideoId(url) {
// Returns numeric chat ID extracted from the Rumble video page
const headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': SSAPP_ACCEPT_LANGUAGE,
'Referer': 'https://rumble.com/',
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
};
try {
// Prefer main-process fetch to avoid CORS/UA quirks
if (typeof ipcRenderer !== 'undefined' && ipcRenderer) {
const response = await ipcRenderer.invoke('nodefetch', {
url,
headers: { ...headers, 'User-Agent': (config?.global?.userAgent || 'Mozilla/5.0') },
timeout: 15000
});
const html = response?.data || '';
if (html) {
const identifiers = extractRumbleIdentifiersFromHtml(html);
if (identifiers.chatId) return identifiers.chatId;
}
}
} catch (e) {
console.warn('nodefetch getRumbleVideoId failed, falling back to renderer fetch:', e?.message || e);
}
try {
const res = await fetch(url, { headers, credentials: 'omit', cache: 'no-store' });
const html = await res.text();
const identifiers = extractRumbleIdentifiersFromHtml(html);
if (identifiers.chatId) return identifiers.chatId;
} catch (e) {
console.error('Error fetching Rumble video page:', e);
}
return "";
}
async function getRumbleChatId(videoId) {
if (!videoId) return null;
let target = typeof videoId === 'string' ? videoId.trim() : '';
if (!target) return null;
const popupMatch = target.match(/chat\/popup\/(\d+)/i);
if (popupMatch && popupMatch[1]) {
return popupMatch[1];
}
if (/^\d+$/.test(target)) {
return target;
}
let url;
if (target.startsWith('http')) {
url = target;
} else {
target = target.replace(/^https?:\/\//i, '').replace(/^rumble\.com\/+/i, '');
if (target.startsWith('/')) target = target.slice(1);
let hash = '';
const hashIndex = target.indexOf('#');
if (hashIndex !== -1) {
hash = target.slice(hashIndex);
target = target.slice(0, hashIndex);
}
let query = '';
const queryIndex = target.indexOf('?');
if (queryIndex !== -1) {
query = target.slice(queryIndex);
target = target.slice(0, queryIndex);
}
if (target && !target.endsWith('.html')) {
const hasExtension = /\.[a-z0-9]+$/i.test(target);
if (!hasExtension) target += '.html';
}
url = `https://rumble.com/${target}${query}${hash}`;
}
const headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': SSAPP_ACCEPT_LANGUAGE,
'Referer': 'https://rumble.com/',
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
};
try {
// Prefer main-process fetch
if (typeof ipcRenderer !== 'undefined' && ipcRenderer) {
const response = await ipcRenderer.invoke('nodefetch', {
url,
headers: { ...headers, 'User-Agent': (config?.global?.userAgent || 'Mozilla/5.0') },
timeout: 15000
});
const html = response?.data || '';
const identifiers = extractRumbleIdentifiersFromHtml(html);
if (identifiers.chatId) {
console.log(`Found Rumble chat ID: ${identifiers.chatId} for video: ${videoId}`);
return identifiers.chatId;
}
}
} catch (e) {
console.warn('nodefetch getRumbleChatId failed, falling back to renderer fetch:', e?.message || e);
}
try {
const res = await fetch(url, {
headers,
credentials: 'omit',
cache: 'no-store'
});
const html = await res.text();
const identifiers = extractRumbleIdentifiersFromHtml(html);
if (identifiers.chatId) {
console.log(`Found Rumble chat ID: ${identifiers.chatId} for video: ${videoId}`);
return identifiers.chatId;
}
} catch (e) {
console.error('Error fetching Rumble chat ID:', e);
}
console.warn(`Could not find chat ID for Rumble video: ${videoId}`);
return null;
}
function matchRuleShort(str, rule) {
var escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
return new RegExp("^" + rule.split("*").map(escapeRegex).join(".*") + "$").test(str);
}
function getPrimaryDomain(url) {
try {
url = url.trim();
if (!url.startsWith('http://') && !url.startsWith('https://')) {
url = 'https://' + url;
}
const parsedUrl = new URL(url);
const hostParts = parsedUrl.hostname.split('.');
if (hostParts.length > 2 && hostParts[0] === 'www') {
return hostParts.slice(-2).join('.');
}
return hostParts.slice(-2).join('.');
} catch (error) {
console.error('Invalid URL:', error);
return null;
}
}
function checkSupported(str) {
var matches = [];
manifest.content_scripts.forEach(dom => {
dom.matches.forEach(dom2 => {
if (matchRuleShort(str, dom2)) {
log(dom2);
if (!matches.includes(dom.js[0])) {
matches.push(dom.js[0]);
}
}
});
});
return matches;
}
const tipsContent = {
tiktok: `
<div class="tips-section">
<h3>You Must Be Live</h3>
<p>TikTok chat only works when you are actively streaming. Click <strong>🔄 Reload</strong> after going live.</p>
</div>
<div class="tips-section">
<h3>Which Mode Should I Use?</h3>
<table style="width:100%; border-collapse: collapse; font-size: 0.9em; margin: 8px 0;">
<tr style="border-bottom: 1px solid rgba(255,255,255,0.2);">
<th style="text-align:left; padding: 6px 8px;">Mode</th>
<th style="text-align:center; padding: 6px 8px;">Replies</th>
<th style="text-align:left; padding: 6px 8px;">Best For</th>
</tr>
<tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
<td style="padding: 6px 8px;"><strong>TikTok WS</strong></td>
<td style="text-align:center; padding: 6px 8px;">⚙️</td>
<td style="padding: 6px 8px;">Recommended default — smooth + auto-fallback</td>
</tr>
<tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
<td style="padding: 6px 8px;"><strong>Standard</strong></td>
<td style="text-align:center; padding: 6px 8px;">✅</td>
<td style="padding: 6px 8px;">Need to reply (requires sign-in)</td>
</tr>
<tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
<td style="padding: 6px 8px;"><strong>Polling</strong></td>
<td style="text-align:center; padding: 6px 8px;">❌</td>
<td style="padding: 6px 8px;">Fallback only — messages arrive in batches</td>
</tr>
</table>
<p style="font-size: 0.85em; opacity: 0.8;"><strong>TikTok WS</strong> with <strong>Auto</strong> is the default. It tries WebSocket first and falls back to Polling if needed. Reply support depends on the signing provider.</p>
<p style="font-size: 0.85em; opacity: 0.8;"><strong>Backup option:</strong> If TikTok modes keep failing or miss messages, use a <strong>TikFinity OBS Dock</strong> URL as an <strong>Other chat site</strong> in SSN. In TikFinity, go to <strong>Overlay -> OBS Docks</strong>, set one dock to chat, copy the URL, and keep TikFinity open.</p>
</div>
<div class="tips-section">
<h3>Troubleshooting</h3>
<p><strong>Standard mode not working?</strong></p>
<ul>
<li>Click <strong>👁️ Show capture page</strong> to check for CAPTCHA or sign-in</li>
<li>If nothing appears, try <strong>🔄 Reload</strong></li>
<li>Clear cache via the ⚙️ settings menu</li>
</ul>
<p><strong>Getting blocked or throttled?</strong></p>
<ul>
<li>Close other TikTok tabs/apps on this device</li>
<li>Avoid viewing the same stream elsewhere</li>
<li>Wait a few minutes, then try again</li>
</ul>
<p><strong>Still missing chat?</strong></p>
<ul>
<li>Use a <strong>TikFinity OBS Dock</strong> URL as an <strong>Other chat site</strong> in SSN</li>
<li>In TikFinity, go to <strong>Overlay -> OBS Docks</strong> and set a dock to chat</li>
<li>Keep TikFinity open during the stream</li>
</ul>
<p><strong>Need to reply to chat?</strong></p>
<ul>
<li>Use <strong>Standard</strong> mode with <strong>🔑 Sign-in</strong></li>
<li>Or try <strong>TikTok WS</strong> with <strong>Local Signer</strong> (experimental)</li>
</ul>
</div>
`,
youtube: `
<div class="tips-section">
<h3>Important: You Must Be Live</h3>
<p>YouTube chat only works when you are actively streaming. If you're not live yet, there's no chat to capture.</p>
<p>When you go live, click the <strong>🔄 Reload</strong> button to start capturing chat.</p>
</div>
<div class="tips-section">
<h3>Connection Modes</h3>
<ul>
<li><span class="tips-highlight">Standard Mode:</span> Uses a browser page to capture chat.</li>
<li><span class="tips-highlight">WebSocket Mode:</span> Direct API connection with more event types (followers, memberships, Super Chats). Requires sign-in.</li>
</ul>
<p style="margin-top: 8px;">If Standard mode has issues, try <strong>WebSocket mode</strong> as an alternative.</p>
</div>
<div class="tips-section">
<h3>Finding Your Stream</h3>
<ul>
<li><span class="tips-highlight">By Username/Channel:</span> Your stream must be <strong>Public</strong>. Unlisted or Private streams cannot be found this way.</li>
<li><span class="tips-highlight">By Video ID:</span> If your stream is Unlisted, add it using the YouTube Video ID instead (the part after "v=" in the URL).</li>
</ul>
</div>
<div class="tips-section">
<h3>Trouble Signing In?</h3>
<p>If sign-in is rejected as "invalid browser", try changing the <strong>User Agent</strong> via the ⚙️ settings menu (try Firefox or a newer Chrome version).</p>
</div>
`,
twitch: `
<div class="tips-section">
<h3>Twitch is Always Ready</h3>
<p>Unlike some platforms, Twitch chat is available even when you're not live. You can start capturing chat immediately.</p>
</div>
<div class="tips-section">
<h3>Connection Modes</h3>
<ul>
<li><span class="tips-highlight">Standard Mode:</span> Uses a browser page to capture chat.</li>
<li><span class="tips-highlight">WebSocket Mode:</span> Direct connection with more event types (followers, subs, raids, bits). Requires sign-in.</li>
</ul>
<p style="margin-top: 8px;">If Standard mode has issues, try <strong>WebSocket mode</strong> as an alternative.</p>
</div>
<div class="tips-section">
<h3>Trouble Signing In?</h3>
<p>If sign-in is rejected as "invalid browser", try changing the <strong>User Agent</strong> via the ⚙️ settings menu (try Firefox or a newer Chrome version).</p>
</div>
`,
kick: `
<div class="tips-section">
<h3>Kick is Always Ready</h3>
<p>Like Twitch, Kick chat is available even when you're not live. You can start capturing chat immediately.</p>
</div>
<div class="tips-section">
<h3>Connection Modes</h3>
<ul>
<li><span class="tips-highlight">Standard Mode:</span> Uses a browser page to capture chat.</li>
<li><span class="tips-highlight">WebSocket Mode:</span> Direct connection with more event types (followers, subs, etc.). Requires sign-in.</li>
</ul>
<p style="margin-top: 8px;">If Standard mode has issues, try <strong>WebSocket mode</strong> as an alternative.</p>
</div>
<div class="tips-section">
<h3>Trouble Signing In?</h3>
<ul>
<li>Try signing in with <strong>email + password</strong> instead of Google/SSO — it often works better</li>
<li>If sign-in is rejected as "invalid browser", try changing the <strong>User Agent</strong> via the ⚙️ settings menu (try Firefox or a newer Chrome version)</li>
<li>If Standard mode sign-in fails, try <strong>WebSocket mode</strong> with the <strong>external sign-in</strong> option</li>
</ul>
</div>
`,
rumble: `
<div class="tips-section">
<h3>You Must Be Live First</h3>
<p>Rumble chat only works when you are already streaming. <strong>Go live before activating</strong> this source.</p>
</div>
<div class="tips-section">
<h3>If Username Doesn't Work</h3>
<p>Adding by username requires a lookup that can sometimes fail. Try adding the chat URL directly instead:</p>
<ol>
<li>Open your Rumble stream in a browser</li>
<li>Find the chat popup URL (right-click on chat, look for popup option)</li>
<li>Add a new source using <strong>"Other"</strong> and paste the chat URL</li>
</ol>
</div>
<div class="tips-section">
<h3>Chat Visible But Not Capturing?</h3>
<p>Click <strong>👁️ Show capture page</strong> to check. If chat is visible but not capturing, try <strong>🔄 Reload</strong>.</p>
</div>
`,
facebook: `
<div class="tips-section">
<h3>You Must Be Live</h3>
<p>Facebook chat only works when the stream is actively live. There's no chat to capture otherwise.</p>
</div>
<div class="tips-section">
<h3>Getting Started</h3>
<ol>
<li>Click <strong>👁️ Show capture page</strong> to open the browser window</li>
<li>Sign in to Facebook if prompted</li>
<li>Navigate to the page where the live chat is visible</li>
<li>Once you can see the chat, it should start capturing</li>
</ol>
</div>
<div class="tips-section">
<h3>Streaming From Your Own Account?</h3>
<p>If you're signed into the same account you're streaming from, you may need to navigate to your <strong>Facebook Live Producer Studio</strong> instead of the normal watch page to see the chat.</p>
<p><span class="tips-highlight">Group streams:</span> Navigate to the group's live stream page. Once the chat is visible, it should work.</p>
</div>
<div class="tips-section">
<h3>Trouble Signing In?</h3>
<p>If sign-in is rejected as "invalid browser", try changing the <strong>User Agent</strong> via the ⚙️ settings menu (try Firefox or a newer Chrome version).</p>
</div>
<div class="tips-section">
<h3>Chat Visible But Not Capturing?</h3>
<p>If you can see the chat in the popup but it's not being captured, try clicking <strong>🔄 Reload</strong>.</p>
<p><span class="tips-highlight">Alternative:</span> The <strong>Chrome Extension</strong> may work better since you can navigate more easily in your regular browser.</p>
</div>
`,
linkedin: `
<div class="tips-section">
<h3>LinkedIn Requires Sign-in</h3>
<p>LinkedIn chat capture requires you to be signed in. Use the <strong>🔑 Sign-in</strong> button first.</p>
</div>
<div class="tips-section">
<h3>If Chat Isn't Working</h3>
<ol>
<li>Click <strong>👁️ Reveal capture page</strong> to see the hidden browser</li>
<li>Make sure the chat/comments are visible on the page</li>
<li>Check that you're signed in properly</li>
</ol>
<p><span class="tips-highlight">Alternative:</span> Consider using the <strong>Chrome Extension</strong> instead. It often works better for LinkedIn since you can sign in and navigate more easily in your regular browser.</p>
</div>
<div class="tips-section">
<h3>Understanding the Capture Page</h3>
<p>Social Stream uses a hidden browser page to capture chat. The <strong>🔄 Reload</strong> button refreshes this page if needed.</p>
</div>
`,
instagram: `
<div class="tips-section">
<h3>You Must Be Live</h3>
<p>Instagram chat only works when the stream is actively live.</p>
</div>
<div class="tips-section">
<h3>Getting Started</h3>
<ol>
<li>Click <strong>👁️ Show capture page</strong> to open the browser window</li>
<li>Sign in to Instagram if prompted</li>
<li>Navigate to the page where the live chat/comments are visible</li>
<li>Once you can see the chat, it should start capturing</li>
</ol>
</div>
<div class="tips-section">
<h3>Trouble Signing In?</h3>
<p>If sign-in is rejected as "invalid browser", try changing the <strong>User Agent</strong> via the ⚙️ settings menu (try Firefox or a newer Chrome version).</p>
</div>
<div class="tips-section">
<h3>Chat Visible But Not Capturing?</h3>
<p>If you can see the chat in the popup but it's not being captured, try clicking <strong>🔄 Reload</strong>.</p>
<p><span class="tips-highlight">Alternative:</span> The <strong>Chrome Extension</strong> may work better since you can navigate more easily in your regular browser.</p>
</div>
`,
instagramlive: `
<div class="tips-section">
<h3>You Must Be Live</h3>
<p>Instagram Live chat only works when the stream is actively live.</p>
</div>
<div class="tips-section">
<h3>Getting Started</h3>
<ol>
<li>Click <strong>👁️ Show capture page</strong> to open the browser window</li>
<li>Sign in to Instagram if prompted</li>
<li>Navigate to the page where the live chat is visible</li>
<li>Once you can see the chat, it should start capturing</li>
</ol>
</div>
<div class="tips-section">
<h3>Trouble Signing In?</h3>
<p>If sign-in is rejected as "invalid browser", try changing the <strong>User Agent</strong> via the ⚙️ settings menu (try Firefox or a newer Chrome version).</p>
</div>
<div class="tips-section">
<h3>Chat Visible But Not Capturing?</h3>
<p>If you can see the chat in the popup but it's not being captured, try clicking <strong>🔄 Reload</strong>.</p>
<p><span class="tips-highlight">Alternative:</span> The <strong>Chrome Extension</strong> may work better since you can navigate more easily in your regular browser.</p>
</div>
`,
zoom: `
<div class="tips-section">
<h3>Zoom Requires Sign-in</h3>
<p>Zoom chat capture requires you to be signed in and in an active meeting.</p>
</div>
<div class="tips-section">
<h3>If Chat Isn't Working</h3>
<ol>
<li>Click <strong>👁️ Reveal capture page</strong> to see the hidden browser</li>
<li>Make sure the chat panel is open and visible</li>
<li>Check that you're signed in and in an active meeting</li>
</ol>
<p><span class="tips-highlight">Alternative:</span> Consider using the <strong>Chrome Extension</strong> instead. It often works better for Zoom since you can sign in and navigate more easily in your regular browser.</p>
</div>
<div class="tips-section">
<h3>Understanding the Capture Page</h3>
<p>Social Stream uses a hidden browser page to capture chat. The <strong>🔄 Reload</strong> button refreshes this page if needed.</p>
</div>
`,
slack: `
<div class="tips-section">
<h3>Slack Requires Sign-in</h3>
<p>Slack chat capture requires you to be signed in to your workspace.</p>
</div>
<div class="tips-section">
<h3>If Chat Isn't Working</h3>
<ol>
<li>Click <strong>👁️ Reveal capture page</strong> to see the hidden browser</li>
<li>Make sure you're signed in and the channel is visible</li>
<li>Check that messages are loading properly</li>
</ol>
<p><span class="tips-highlight">Alternative:</span> Consider using the <strong>Chrome Extension</strong> instead. It often works better for Slack since you can sign in and navigate more easily in your regular browser.</p>
</div>
<div class="tips-section">
<h3>Understanding the Capture Page</h3>
<p>Social Stream uses a hidden browser page to capture chat. The <strong>🔄 Reload</strong> button refreshes this page if needed.</p>
</div>
`,
discord: `
<div class="tips-section">
<h3>Discord Requires Sign-in</h3>
<p>Discord chat capture requires you to be signed in to your server.</p>
</div>
<div class="tips-section">
<h3>If Chat Isn't Working</h3>
<ol>
<li>Click <strong>👁️ Reveal capture page</strong> to see the hidden browser</li>
<li>Make sure you're signed in and the channel is visible</li>
<li>Check that messages are loading properly</li>
</ol>
<p><span class="tips-highlight">Alternative:</span> Consider using the <strong>Chrome Extension</strong> instead. It often works better for Discord since you can sign in and navigate more easily in your regular browser.</p>
</div>
<div class="tips-section">
<h3>Understanding the Capture Page</h3>
<p>Social Stream uses a hidden browser page to capture chat. The <strong>🔄 Reload</strong> button refreshes this page if needed.</p>
</div>
`,
x: `
<div class="tips-section">
<h3>X.com Requires Sign-in</h3>
<p>X.com chat capture requires you to be signed in. Click <strong>👁️ Show capture page</strong> and sign in if needed.</p>
</div>
<div class="tips-section">
<h3>Trouble Signing In?</h3>
<ul>
<li>Try signing in with <strong>email + password</strong> instead of Google or other SSO providers</li>
<li>If sign-in is rejected as "invalid browser", try changing the <strong>User Agent</strong> via the ⚙️ settings menu (try Firefox or a newer Chrome version)</li>
</ul>
</div>
<div class="tips-section">
<h3>Chat Not Capturing?</h3>
<p>Make sure you're on a page where the live chat/Space is visible. If chat is visible but not capturing, try <strong>🔄 Reload</strong>.</p>
</div>
`
};
const genericTipsContent = `
<div class="tips-section">
<h3>Getting Started</h3>
<ol>
<li>Click <strong>▶️ Activate source</strong> to start capturing</li>
<li>If sign-in is required, click <strong>🔑 Sign-in</strong> first</li>
<li>Click <strong>👁️ Show capture page</strong> to see the browser window and verify chat is visible</li>
</ol>
</div>
<div class="tips-section">
<h3>Troubleshooting</h3>
<ul>
<li>If chat isn't capturing, click <strong>🔄 Reload</strong></li>
<li>If sign-in fails, try using <strong>email + password</strong> instead of Google/SSO</li>
<li>If sign-in is rejected as "invalid browser", try changing the <strong>User Agent</strong> via the ⚙️ settings menu</li>
<li>Clear cache via the ⚙️ settings menu if having persistent issues</li>
</ul>
</div>
`;
function showTips(ele) {
showTipsModal(ele.parentNode.dataset.target || ele.dataset.target || ele.parentNode.parentNode.dataset.target);
}
function showTipsModal(platform) {
const modal = document.getElementById('tipsModal');
const modalTitle = document.getElementById('tipsModalTitle');
const modalContent = document.getElementById('tipsModalContent');
const platformName = platform ? platform.charAt(0).toUpperCase() + platform.slice(1) : 'This Source';
modalTitle.textContent = `Tips for ${platformName}`;
modalContent.innerHTML = tipsContent[platform] || genericTipsContent;
modal.classList.remove('hidden');
}
function closeTipsModal() {
document.getElementById('tipsModal').classList.add('hidden');
}
window.closeTipsModal = closeTipsModal;
const Toast = {
container: null,
init() {
this.container = document.getElementById('toastContainer');
if (!this.container) {
this.container = document.createElement('div');
this.container.id = 'toastContainer';
this.container.className = 'toast-container';
document.body.appendChild(this.container);
}
},
show(options) {
this.init();
// Handle when show is called with just strings
if (typeof options === 'string') {
options = {
message: options
};
}
const defaults = {
title: '',
message: '',
type: 'info', // info, success, warning, error
duration: 5000, // ms
showProgress: true,
onClose: null
};
const settings = {
...defaults,
...options
};
// Create toast element
const toast = document.createElement('div');
toast.className = `toast toast-${settings.type}`;
// Create content
let iconClass = '';
switch (settings.type) {
case 'success':
iconClass = 'la-check-circle';
break;
case 'warning':
iconClass = 'la-exclamation-triangle';
break;
case 'error':
iconClass = 'la-exclamation-circle';
break;
default:
iconClass = 'la-info-circle';
}
// Debug
console.log("Creating toast with:", {
title: settings.title,
message: settings.message,
type: settings.type
});
toast.innerHTML = `
<div class="toast-icon">
<i class="las ${iconClass}"></i>
</div>
<div class="toast-content">
${settings.title ? `<div class="toast-title">${settings.title}</div>` : ''}
<p class="toast-message">${String(settings.message)}</p>
</div>
<button class="toast-close">
<i class="las la-times"></i>
</button>
${settings.showProgress ? '<div class="toast-progress"><div class="toast-progress-bar"></div></div>' : ''}
`;
// Add to container
this.container.appendChild(toast);
// Animate progress bar
const progressBar = toast.querySelector('.toast-progress-bar');
if (progressBar && settings.showProgress && settings.duration > 0) {
progressBar.style.animation = `progress ${settings.duration / 1000}s linear forwards`;
}
// Show toast with slight delay to trigger animation
setTimeout(() => {
toast.classList.add('show');
}, 10);
// Set up close button
const closeBtn = toast.querySelector('.toast-close');
if (closeBtn) {
closeBtn.addEventListener('click', () => {
this.hide(toast);
if (typeof settings.onClose === 'function') {
settings.onClose();
}
});
}
// Auto-close after duration
if (settings.duration > 0) {
setTimeout(() => {
if (toast.parentNode) {
this.hide(toast);
if (typeof settings.onClose === 'function') {
settings.onClose();
}
}
}, settings.duration);
}
return toast;
},
hide(toast) {
toast.classList.remove('show');
// Remove element after animation
setTimeout(() => {
if (toast.parentNode) {
toast.parentNode.removeChild(toast);
}
}, 300);
},
success(message, title = '', options = {}) {
if (typeof title === 'object') {
options = title;
title = '';
}
return this.show({
...options,
title,
message,
type: 'success'
});
},
info(message, title = '', options = {}) {
if (typeof title === 'object') {
options = title;
title = '';
}
return this.show({
...options,
title,
message,
type: 'info'
});
},
warning(message, title = '', options = {}) {
if (typeof title === 'object') {
options = title;
title = '';
}
return this.show({
...options,
title,
message,
type: 'warning'
});
},
error(message, title = '', options = {}) {
if (typeof title === 'object') {
options = title;
title = '';
}
return this.show({
...options,
title,
message,
type: 'error'
});
}
};
function getDefaultConfig() {
const platform = navigator.platform.toLowerCase();
const baseConfig = {
"global": {
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
"size": {
"width": 600,
"height": 450
},
"signin": {
"userAgent": "Chrome",
"size": {
"width": 600,
"height": 600
},
"enforceSigninCSP": true
}
}
};
if (platform.includes('mac')) {
baseConfig.global.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36";
} else if (platform.includes('linux')) {
baseConfig.global.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36";
} else { // Default to Windows NT 10
baseConfig.global.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36";
}
return baseConfig;
}
const WELCOME_GUIDE_URL = "https://www.youtube.com/watch?v=VpD2pnZVYF0";
const WELCOME_GUIDE_THUMBNAIL_URL = "https://i.ytimg.com/vi/VpD2pnZVYF0/hqdefault.jpg";
function normalizeWelcomeFrameUrl(url) {
if (typeof url !== "string") return "";
if (/^[a-zA-Z]:[\\/]/.test(url)) {
try {
const { pathToFileURL } = require("url");
return pathToFileURL(url).href;
} catch (_) {
return `file:///${url.replace(/\\/g, "/")}`;
}
}
return url;
}
function addWelcomeFrameBaseHref(html, resolvedUrl) {
if (!html || !resolvedUrl) return html;
if (/<base\s/i.test(html)) return html;
const baseHref = resolvedUrl.href.replace(/[^/?#]*([?#].*)?$/, "");
return html.replace(/<head([^>]*)>/i, `<head$1><base href="${baseHref}">`);
}
function patchWelcomeFrameHtml(html, options = {}) {
if (!html || typeof html !== "string") return html;
let patchedHtml = html.replace(/allow="([^"]*)"/gi, (match, value) => {
const filteredTokens = value
.split(";")
.map((token) => token.trim())
.filter(Boolean)
.filter((token) => token.toLowerCase() !== "web-share");
return `allow="${filteredTokens.join("; ")}"`;
});
if (options.useVideoFallback) {
if (!patchedHtml.includes(".video-fallback-link")) {
const fallbackStyles = `
.video-fallback-link {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
overflow: hidden;
border-radius: 8px;
text-decoration: none;
background: #000;
}
.video-fallback-link img {
width: 100%;
height: 100%;
object-fit: cover;
opacity: 0.78;
}
.video-fallback-label {
position: absolute;
padding: 12px 18px;
border-radius: 999px;
background: rgba(0, 0, 0, 0.72);
color: #fff;
font-weight: bold;
letter-spacing: 0.01em;
}
`;
patchedHtml = patchedHtml.replace(/<\/style>/i, `${fallbackStyles}</style>`);
}
const fallbackMarkup = `
<div class="video-container">
<a class="video-fallback-link" href="${WELCOME_GUIDE_URL}" target="_blank" rel="noopener noreferrer">
<img src="${WELCOME_GUIDE_THUMBNAIL_URL}" alt="Social Stream Ninja walkthrough video thumbnail">
<span class="video-fallback-label">Watch the walkthrough on YouTube</span>
</a>
</div>`;
patchedHtml = patchedHtml.replace(
/<div class="video-container">\s*<iframe[\s\S]*?src="https:\/\/www\.youtube\.com\/embed\/VpD2pnZVYF0"[\s\S]*?<\/iframe>\s*<\/div>/i,
fallbackMarkup
);
}
return patchedHtml;
}
async function readWelcomeFrameFileContent(fileUrl) {
const fs = require("fs").promises;
const { fileURLToPath } = require("url");
return fs.readFile(fileURLToPath(fileUrl), "utf8");
}
async function loadWelcomeFrameContent(frame, url) {
if (!frame) return;
const normalizedUrl = normalizeWelcomeFrameUrl(url);
const resetToSrc = (targetUrl) => {
try {
frame.removeAttribute('srcdoc');
} catch (_) {
// Ignore if attribute is absent.
}
frame.src = targetUrl || '';
};
if (!normalizedUrl) {
resetToSrc('');
return;
}
const currentOrigin = typeof window !== 'undefined' && window.location ? window.location.origin : null;
if (normalizedUrl.startsWith('file://')) {
try {
const resolvedUrl = new URL(normalizedUrl, window.location ? window.location.href : undefined);
let html = await readWelcomeFrameFileContent(normalizedUrl);
html = patchWelcomeFrameHtml(html, { useVideoFallback: true });
html = addWelcomeFrameBaseHref(html, resolvedUrl);
frame.srcdoc = html;
return;
} catch (err) {
console.warn('Failed to inline local welcome frame content; falling back to iframe src.', err);
resetToSrc(normalizedUrl);
return;
}
}
const shouldInlineResponse = (response, resolvedUrl) => {
const normalized = (value) => (value || '').trim().toLowerCase();
const xFrameOptions = normalized(response.headers.get('x-frame-options'));
if (xFrameOptions.includes('deny')) {
return true;