-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
popup.js
3154 lines (2764 loc) · 130 KB
/
popup.js
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
// popup.js
var isExtensionOn = false;
var ssapp = false;
var USERNAMES = [];
function log(msg,a,b){
console.log(msg,a,b);
}
if (typeof(chrome.runtime)=='undefined'){
chrome = {};
chrome.browserAction = {};
chrome.browserAction.setIcon = function(icon){}
chrome.runtime = {}
chrome.runtime.id = 1;
log("pop up started");
if (typeof require !== "undefined"){
var { ipcRenderer, contextBridge } = require("electron");
ssapp = true;
try {
window.showOpenFilePicker = async function (a = null, c = null) {
var importFile = await ipcRenderer.sendSync("showOpenDialog", "");
return importFile;
};
} catch(e){}
} else {
var ipcRenderer = {};
ipcRenderer.sendSync = function(){};
ipcRenderer.invoke = function(){};
ipcRenderer.on = function(){};
console.warn("This isn't a functional mode; not yet at least.");
}
try {
var onMessageCallback = function (a, b, c) {};
chrome.runtime.onMessage = {};
chrome.runtime.onMessage.addListener = function (callback) {
onMessageCallback = callback;
};
ipcRenderer.on("fromMain", (event, ...args) => {
log("FROM MAIN", args);
var sender = {};
sender.tab = {};
sender.tab.id = null;
if (args[0] && args[0].forPopup) {
log("for pop up");
onMessageCallback(args[0], sender, function (response) {
if (event.returnValue) {
event.returnValue = response;
}
ipcRenderer.send("fromMainResponse", response);
});
} else {
log("some returned promise probably");
update(args[0], false);
}
});
ipcRenderer.on("fromBackground", (event, ...args) => {
log("FROM BACKGROUND", args);
var sender = {};
sender.tab = {};
sender.tab.id = null;
if (args[0]) {
onMessageCallback(args[0], sender, function (response) {
if (event.returnValue) {
event.returnValue = response;
}
ipcRenderer.send("fromBackgroundResponse", response);
});
}
});
} catch(e){
console.error(e);
}
chrome.runtime.sendMessage = async function(data, callback){ // every single response, is either nothing, or update()
let response = await ipcRenderer.sendSync('fromPopup',data);
if (typeof(callback) == "function"){
callback(response);
}
};
chrome.runtime.getManifest = function(){
return false; // I'll need to add version info eventually
}
try {
window.prompt = function(title, val, message=""){
log("window.prompt");
return ipcRenderer.sendSync('prompt', {title, val, message}); // call if needed in the future
};
} catch(err) {
console.error(err);
}
new Promise((resolve, reject) => {
try {
`+text+`
} catch(err) {
try {
throw { name: err.name, message: err.message, stack: err.stack }
} catch(e){}
}
})
}
function copyToClipboard(event) {
console.log(event);
if (event.target.parentNode.parentNode.querySelector("[data-raw] a[href]")){
navigator.clipboard.writeText(event.target.parentNode.querySelector("[data-raw] a[href]").href).then(function() {
console.log('Link copied to clipboard!');
event.target.classList.add("flashing");
setTimeout(()=>{
event.target.classList.remove("flashing");
},500);
}, function(err) {
console.error('Could not copy text: ', err);
});
} else if (event.target.parentNode.parentNode.parentNode.querySelector("[data-raw] a[href]")){
navigator.clipboard.writeText(event.target.parentNode.parentNode.parentNode.querySelector("[data-raw] a[href]").href).then(function() {
console.log('Link copied to clipboard!');
event.target.classList.add("flashing");
setTimeout(()=>{
event.target.classList.remove("flashing");
},500);
}, function(err) {
console.error('Could not copy text: ', err);
});
} else if (event.target.parentNode.parentNode.parentNode.parentNode.querySelector("[data-raw] a[href]")){
navigator.clipboard.writeText(event.target.parentNode.parentNode.parentNode.parentNode.querySelector("[data-raw] a[href]").href).then(function() {
console.log('Link copied to clipboard!');
event.target.classList.add("flashing");
setTimeout(()=>{
event.target.classList.remove("flashing");
},500);
}, function(err) {
console.error('Could not copy text: ', err);
});
}
}
var translation = {};
function getTranslation(key, value=false){
if (translation.innerHTML && (key in translation.innerHTML)){ // these are the proper translations
return translation.innerHTML[key];
} else if (translation.miscellaneous && (key in translation.miscellaneous)){
return translation.miscellaneous[key];
} else if (value!==false){
return value;
} else {
return key.replaceAll("-", " "); //
}
}
function miniTranslate(ele, ident = false, direct=false) {
if (ident){
if (translation.innerHTML && (ident in translation.innerHTML)){
if (ele.querySelector('[data-translate]')){
ele.querySelector('[data-translate]').innerHTML = translation.innerHTML[ident];
ele.querySelector('[data-translate]').dataset.translate = ident;
} else {
ele.innerHTML = translation.innerHTML[ident];
ele.dataset.translate = ident;
}
return;
} else if (direct){
if (ele.querySelector('[data-translate]')){
ele.querySelector('[data-translate]').innerHTML = direct;
ele.querySelector('[data-translate]').dataset.translate = ident;
} else {
ele.dataset.translate = ident;
ele.innerHTML = direct;
}
return;
} else {
log(ident + ": not found in translation file");
if (!translation.miscellaneous || !(ident in translation.miscellaneous)){
var value = ident.replaceAll("-", " "); // lets use the key as the translation
} else {
var value = translation.miscellaneous[ident]; // lets use a miscellaneous translation as backup?
}
if (ele.querySelector('[data-translate]')){
ele.querySelector('[data-translate]').innerHTML = value;
ele.querySelector('[data-translate]').dataset.translate = ident;
} else {
ele.innerHTML = value;
ele.dataset.translate = ident;
}
return;
}
}
var allItems = ele.querySelectorAll('[data-translate]');
allItems.forEach(function(ele2) {
if (translation.innerHTML && (ele2.dataset.translate in translation.innerHTML)){
ele2.innerHTML = translation.innerHTML[ele2.dataset.translate];
} else if (translation.miscellaneous && (ele2.dataset.translate in translation.miscellaneous)){
ele2.innerHTML = translation.miscellaneous[ele2.dataset.translate];
}
});
if (ele.dataset){
if (translation.innerHTML && (ele.dataset.translate in translation.innerHTML)){
ele.innerHTML = translation.innerHTML[ele.dataset.translate];
} else if (translation.miscellaneous && (ele.dataset.translate in translation.miscellaneous)){
ele.innerHTML = translation.miscellaneous[ele.dataset.translate];
}
}
if (translation.titles){
var allTitles = ele.querySelectorAll('[title]');
allTitles.forEach(function(ele2) {
var key = ele2.title.toLowerCase().replace(/[^a-zA-Z0-9\s\-]/g, '').replace(/[\n\t\r]/g, '').trim().replaceAll(" ","-");;
if (key in translation.titles) {
ele2.title = translation.titles[key];
}
});
if (ele.title){
var key = ele.title.toLowerCase().replace(/[^a-zA-Z0-9\s\-]/g, '').replace(/[\n\t\r]/g, '').trim().replaceAll(" ","-");;
if (key in translation.titles) {
ele.title = translation.titles[key];
}
}
}
if (translation.placeholders){
var allPlaceholders = ele.querySelectorAll('[placeholder]');
allPlaceholders.forEach(function(ele2) {
var key = ele2.placeholder.toLowerCase().replace(/[^a-zA-Z0-9\s\-]/g, '').replace(/[\n\t\r]/g, '').trim().replaceAll(" ","-");;
if (key in translation.placeholders) {
ele2.placeholder = translation.placeholders[key];
}
});
if (ele.placeholder){
var key = ele.placeholder.toLowerCase().replace(/[^a-zA-Z0-9\s\-]/g, '').replace(/[\n\t\r]/g, '').trim().replaceAll(" ","-");;
if (key in translation.placeholders) {
ele.placeholder = translation.placeholders[key];
}
}
}
}
function isFontAvailable(fontName) {
let canvas = document.createElement("canvas");
let context = canvas.getContext("2d");
context.font = "72px monospace"; // Use a large font size for better accuracy
const widthMonospace = context.measureText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").width;
context.font = `72px '${fontName}', monospace`;
const widthTest = context.measureText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").width;
return widthMonospace !== widthTest;
}
function populateFontDropdown() {
const fonts = ["Roboto", "Tahoma", "Arial", "Verdana", "Helvetica", "Serif", "Trebuchet MS", "Times New Roman", "Georgia", "Garamond", "Courier New", "Brush Script MT"];
var select = document.querySelector("[data-optionparam1='font']");
fonts.forEach(font => {
if (isFontAvailable(font)) {
let option = document.createElement("option");
option.value = font;
option.style="font-family:'"+font+"'";
option.innerText = font + " abc123XYZ";
select.appendChild(option);
}
});
select = document.querySelector("[data-optionparam2='font']");
fonts.forEach(font => {
if (isFontAvailable(font)) {
let option = document.createElement("option");
option.value = font;
option.style="font-family:'"+font+"'";
option.innerText = font + " abc123XYZ";
select.appendChild(option);
}
});
select = document.querySelector("[data-optionparam4='font']");
fonts.forEach(font => {
if (isFontAvailable(font)) {
let option = document.createElement("option");
option.value = font;
option.style="font-family:'"+font+"'";
option.innerText = font + " abc123XYZ";
select.appendChild(option);
}
});
select = document.querySelector("[data-optionparam5='font']");
fonts.forEach(font => {
if (isFontAvailable(font)) {
let option = document.createElement("option");
option.value = font;
option.style="font-family:'"+font+"'";
option.innerText = font + " abc123XYZ";
select.appendChild(option);
}
});
select = document.querySelector("[data-optionparam1='font']");
fonts.forEach(font => {
if (isFontAvailable(font)) {
let option = document.createElement("option");
option.value = font;
option.style="font-family:'"+font+"'";
option.innerText = font + " abc123XYZ";
select.appendChild(option);
}
});
}
function createUniqueVoiceIdentifiers(voices) {
let uniqueIdentifiersByLang = {};
// Group voices by language
voices.forEach(voiceObj => {
if (!uniqueIdentifiersByLang[voiceObj.lang]) {
uniqueIdentifiersByLang[voiceObj.lang] = [];
}
uniqueIdentifiersByLang[voiceObj.lang].push(voiceObj);
});
// Find unique identifiers within each language group
for (let lang in uniqueIdentifiersByLang) {
let voicesInLang = uniqueIdentifiersByLang[lang];
voicesInLang.forEach(voiceObj => {
const words = voiceObj.name.split(' ');
for (let i = 0; i < words.length; i++) {
let potentialIdentifier = words[i];
if (voicesInLang.filter(v => v.name.includes(potentialIdentifier)).length === 1) {
voiceObj.code = `${lang}&voice=${potentialIdentifier}`;
return;
}
}
// Fallback if no unique word is found
voiceObj.code = lang+"&voice="+`${voiceObj.name.replace(/[^a-zA-Z0-9]/g, '')}`;
});
}
var voicesOutput = [];
for (var voice in uniqueIdentifiersByLang){
uniqueIdentifiersByLang[voice].forEach(v=>{
voicesOutput.push(v);
});
}
return voicesOutput;
}
function addUsername(username, type='blacklistusers') {
const input = document.querySelector(`[data-textsetting="${type}"]`);
if (!input) return;
const usernames = input.value.split(',').map(u => u.trim()).filter(u => u);
let sourceType = document.getElementById(`new${type}Type`).value.toLowerCase().trim();
if (sourceType == "youtubeshorts"){
sourceType = "youtube";
}
const newEntry = sourceType ? `${username}:${sourceType}` : username;
if (!usernames.some(entry => {
const [name] = entry.split(':');
return name === username;
})) {
usernames.push(newEntry);
input.value = usernames.join(', ');
updateUsernameList(type);
updateSettings(input);
}
}
function removeUsername(username, sourceType='', type='blacklistusers') {
const input = document.querySelector(`[data-textsetting="${type}"]`);
if (!input) return;
const usernames = input.value.split(',').map(u => u.trim()).filter(u => u);
const index = usernames.findIndex(entry => {
const [name, type] = entry.split(':');
return name === username && (!sourceType || type === sourceType);
});
if (index > -1) {
usernames.splice(index, 1);
input.value = usernames.join(', ');
updateUsernameList(type);
updateSettings(input);
}
}
function updateUsernameList(type='blacklistusers') {
const input = document.querySelector(`[data-textsetting="${type}"]`);
const list = document.getElementById(`${type}List`);
if (!input || !list) return;
const usernames = input.value.split(',')
.map(u => u.trim())
.filter(u => u)
.map(entry => {
const [name, sourceType] = entry.split(':').map(part => part.trim());
return { name, sourceType };
});
list.innerHTML = usernames.map(({ name, sourceType }) => `
<div class="username-tag">
<span>${name}${sourceType ? `<span class="source-type"><img class="icon" src="./sources/images/${sourceType}.png" /> ${sourceType} </span>` : ''}</span>
<button class="remove-username" data-username="${name}" data-source-type="${sourceType || ''}">×</button>
</div>
`).join('');
}
document.addEventListener("DOMContentLoaded", async function(event) {
if (ssapp){
document.getElementById("disableButtonText").innerHTML = "🔌 Services Loading";
} else {
document.getElementById("disableButtonText").innerHTML = "🔌 Extension Loading";
}
//document.body.className = "extension-disabled";
document.getElementById("disableButton").style.display = "";
//chrome.browserAction.setIcon({path: "/icons/off.png"});
document.getElementById("extensionState").checked = null;
document.getElementById("disableButton").onclick = function(event){
event.stopPropagation()
chrome.runtime.sendMessage({cmd: "setOnOffState", data: {value: !isExtensionOn}}, function (response) {
chrome.runtime.lastError;
update(response);
});
return false;
};
document.getElementById('addCustomGifCommand').addEventListener('click', function() {
const commandsList = document.getElementById('customGifCommandsList');
const newCommandEntry = createCommandEntry();
commandsList.appendChild(newCommandEntry);
updateSettings(newCommandEntry, true);
});
document.querySelectorAll("[data-copy]").forEach(ele=>{
ele.onclick = copyToClipboard;
});
try {
const textInputs = document.querySelectorAll('.textInputContainer');
textInputs.forEach(container => {
const input = container.querySelector('.textInput');
if (!input) return;
const id = input.id;
if (['botnamesext', 'modnamesext', 'viplistusers', 'adminnames', 'hostnamesext', 'blacklistusers', 'whitelistusers'].includes(id)) {
input.classList.add('hidden');
const listContainer = document.createElement('div');
listContainer.className = 'username-list-container';
listContainer.id = `${id}List`;
const addContainer = document.createElement('div');
addContainer.className = 'add-username-container';
addContainer.innerHTML = `
<input type="text" id="new${id}" placeholder="Add username">
<input type="text" id="new${id}Type" placeholder="Source type (optional)">
<button id="add${id}">Add</button>
`;
container.parentNode.classList.add("isolate");
container.parentNode.insertBefore(listContainer, container.nextSibling);
container.parentNode.insertBefore(addContainer, listContainer.nextSibling);
}
});
const userTypes = ['botnamesext', 'modnamesext', 'viplistusers', 'adminnames', 'hostnamesext', 'blacklistusers', 'whitelistusers'];
userTypes.forEach(type => {
try {
document.getElementById(`${type}List`).addEventListener('click', (e) => {
if (e.target.classList.contains('remove-username')) {
removeUsername(
e.target.dataset.username,
e.target.dataset.sourceType,
type
);
}
});
document.getElementById(`add${type}`).addEventListener('click', () => {
const input = document.getElementById(`new${type}`);
const username = input.value.trim();
if (username) {
addUsername(username, type);
input.value = '';
document.getElementById(`new${type}Type`).value = '';
}
});
} catch(e) {
console.error(e);
}
});
} catch(e){
console.error(e);
}
populateFontDropdown();
PollManager.init();
// populate language drop down
if (speechSynthesis){
function populateVoices() {
const voices = createUniqueVoiceIdentifiers(speechSynthesis.getVoices());
voices.sort((a, b) => {
if (a.default) {
return -1; // a is the default, move a to the front
} else if (b.default) {
return 1; // b is the default, move b to the front
} else {
return 0; // neither a nor b is the default, keep original order
}
});
var voicesDropdown = document.getElementById('systemLanguageSelect');
var existingOptions = Array.from(voicesDropdown.options).map(option => option.textContent);
voices.forEach(voice => {
const voiceText = voice.name + ' (' + voice.lang + ')';
if (!existingOptions.includes(voiceText)) {
const option = document.createElement('option');
option.textContent = voiceText;
option.value = voice.code;
option.setAttribute('data-lang', voice.lang);
option.setAttribute('data-name', voice.name);
voicesDropdown.appendChild(option);
}
});
var voicesDropdown = document.getElementById('languageSelect2');
var existingOptions = Array.from(voicesDropdown.options).map(option => option.textContent);
voices.forEach(voice => {
const voiceText = voice.name + ' (' + voice.lang + ')';
if (!existingOptions.includes(voiceText)) {
const option = document.createElement('option');
option.textContent = voiceText;
option.value = voice.code;
option.setAttribute('data-lang', voice.lang);
option.setAttribute('data-name', voice.name);
voicesDropdown.appendChild(option);
}
});
try {
TTSManager.init(voices)
} catch(e){
console.error(e);
}
}
speechSynthesis.onvoiceschanged = populateVoices;
document.getElementById('searchInput').addEventListener('keyup', function() {
var searchQuery = this.value.toLowerCase();
if (searchQuery){
document.querySelectorAll('input.collapsible-input').forEach(ele=>{
ele.checked = true
});
document.querySelectorAll('.wrapper').forEach(w=>{
var menuItems = w.querySelectorAll('.options_group > div');
var matches = 0;
menuItems.forEach(function(item) {
var text = item.textContent.toLowerCase();
if (item.querySelector("[title]")){
text += " " + item.querySelector("[title]").title.toLowerCase();
}
if (item.querySelector("input")){
[...item.querySelector("input").attributes].forEach(att=>{
if (att.name.startsWith("data-")){
text += " " + att.value.toLowerCase();
}
});
}
if (text.includes(searchQuery)) {
item.style.display = '';
matches += 1;
} else {
item.style.display = 'none';
}
});
if (!matches){
w.style.display = "none";
} else {
w.style.display = "";
}
});
} else {
document.querySelectorAll('input.collapsible-input').forEach(ele=>{
ele.checked = null
});
document.querySelectorAll('.wrapper').forEach(ele=>{
ele.style.display = "";
});
document.querySelectorAll('.options_group > div').forEach(ele=>{
ele.style.display = "";
});
}
});
}
document.getElementById('searchIcon').addEventListener('click', function() {
var searchInput = document.getElementById('searchInput');
if (searchInput.style.display === 'none' || searchInput.style.display === '') {
searchInput.style.display = 'block';
searchInput.style.width = 'calc(100% - 35px)'; // Match this with your CSS width
searchInput.focus(); // Optional: Focus on the input field when it's shown
} else {
searchInput.style.display = 'none';
searchInput.style.width = '0';
}
});
var activeToggle = false;
document.getElementById('activeIcon').addEventListener('click', function() {
activeToggle = !activeToggle;
if (activeToggle) {
// Open all collapsible sections
document.querySelectorAll('input.collapsible-input').forEach(ele => {
ele.checked = true;
});
document.querySelectorAll('button:not(.showalways)').forEach(function(item) {
item.style.display = 'none';
});
document.querySelectorAll('.wrapper').forEach(w => {
var menuItems = w.querySelectorAll('.options_group > div');
var matches = 0;
menuItems.forEach(function(item) {
var checkbox = item.querySelector('input[type="checkbox"]');
var textInput = item.querySelector('input[type="text"], input[type="password"], input[type="number"]');
var isActive = false;
if (checkbox && checkbox.checked) {
isActive = true;
} else if (textInput) {
var associatedToggle = item.querySelector('input[type="checkbox"]');
if (associatedToggle && associatedToggle.checked && textInput.value.trim() !== '') {
isActive = true;
} else if (!associatedToggle && textInput.value.trim() !== '') {
isActive = true;
}
}
if (isActive) {
matches += 1;
item.style.display = '';
} else {
item.style.display = 'none';
}
});
if (!matches) {
w.style.display = "none";
} else {
w.style.display = "";
}
});
} else {
document.querySelectorAll('button:not(.showalways)').forEach(function(item) {
item.style.display = '';
});
// Reset to original state
document.querySelectorAll('input.collapsible-input').forEach(ele => {
ele.checked = false;
});
document.querySelectorAll('.wrapper').forEach(ele => {
ele.style.display = "";
});
document.querySelectorAll('.options_group > div').forEach(ele => {
ele.style.display = "";
});
}
});
const uploadBadwordsButton = document.getElementById('uploadBadwordsButton');
const deleteBadwordsButton = document.getElementById('deleteBadwordsButton');
if (uploadBadwordsButton) {
uploadBadwordsButton.addEventListener('click', uploadBadwordsFile);
}
if (deleteBadwordsButton) {
deleteBadwordsButton.addEventListener('click', deleteBadwordsFile);
}
const ragEnabledCheckbox = document.getElementById('ollamaRagEnabled');
const ragFileManagement = document.getElementById('ragFileManagement');
ragEnabledCheckbox.addEventListener('change', function() {
ragFileManagement.style.display = this.checked ? 'block' : 'none';
});
let initialSetup = setInterval(()=>{
log("pop up asking main for settings yet again..");
chrome.runtime.sendMessage({cmd: "getSettings"}, (response) => {
chrome.runtime.lastError;
log("getSettings response",response);
if ((response == undefined) || (!response.streamID)){
} else {
clearInterval(initialSetup);
update(response, false); // we dont want to sync things
}
});
}, 500);
log("pop up asking main for settings");
chrome.runtime.sendMessage({cmd: "getSettings"}, (response) => {
chrome.runtime.lastError;
log("getSettings response",response);
if ((response == undefined) || (!response.streamID)){
} else {
clearInterval(initialSetup);
update(response, false); // we dont want to sync things
}
});
for (var i=1;i<=20;i++){
var chat = document.createElement("div");
chat.innerHTML = '<label class="switch" style="vertical-align: top; margin: 26px 0 0 0">\
<input type="checkbox" data-setting="chatevent'+ i +'">\
<span class="slider round"></span>\
</label>\
<div style="display:inline-block">\
<div class="textInputContainer" style="width: 235px">\
<input type="text" id="chatcommand'+ i +'" class="textInput" autocomplete="off" placeholder="!someevent'+ i +'" data-textsetting="chatcommand'+ i +'">\
<label for="chatcommand'+ i +'">> Chat Command</label>\
</div>\
<div class="textInputContainer" style="width: 235px">\
<input type="text" id="chatwebhook'+ i +'" class="textInput" autocomplete="off" placeholder="Provide full URL" data-textsetting="chatwebhook'+ i +'">\
<label for="chatwebhook'+ i +'">> Webhook URL</label>\
</div>\
<div class="textInputContainer" style="width: 235px">\
<input type="number" id="chatcommandtimeout'+ i +'" class="textInput" min="0" autocomplete="off" placeholder="Timeout between triggers" data-numbersetting="chatcommandtimeout'+ i +'">\
<label for="chatcommandtimeout'+ i +'">> Trigger Timeout (ms)</label></div>\
</div>\
</div>';
document.getElementById("chatCommands").appendChild(chat);
}
for (var i=1;i<=10;i++){
var chat = document.createElement("div");
chat.innerHTML = '<label class="switch" style="vertical-align: top; margin: 26px 0 0 0">\
<input type="checkbox" data-setting="timemessageevent'+ i +'">\
<span class="slider round"></span>\
</label>\
<div style="display:inline-block">\
<div class="textInputContainer" style="width: 235px">\
<input type="text" id="timemessagecommand'+ i +'" maxlength="200" class="textInput" autocomplete="off" placeholder="Message to send to chat at an interval" data-textsetting="timemessagecommand'+ i +'">\
<label for="timemessagecommand'+ i +'">> Message to broadcast</label>\
</div>\
<div class="textInputContainer" style="width: 235px">\
<input type="number" id="timemessageinterval'+ i +'" class="textInput" value="15" min="0" autocomplete="off" title="Interval offset in minutes; 0 to issue just once." data-numbersetting="timemessageinterval'+ i +'">\
<label for="timemessageinterval'+ i +'">> Interval between broadcasts in minutes</label>\
</div>\
<div class="textInputContainer" style="width: 235px">\
<input type="number" id="timemessageoffset'+ i +'" value="0" min="0" class="textInput" autocomplete="off" title="Starting offset in minutes" data-numbersetting="timemessageoffset'+ i +'">\
<label for="timemessageoffset'+ i +'">> Starting time offset</label>\
</div>\
</div>';
document.getElementById("timedMessages").appendChild(chat);
}
for (var i=1;i<=10;i++){
var chat = document.createElement("div");
chat.innerHTML = '<label class="switch" style="vertical-align: top; margin: 26px 0 0 0">\
<input type="checkbox" data-setting="botReplyMessageEvent'+ i +'">\
<span class="slider round"></span>\
</label>\
<div style="display:inline-block">\
<div class="textInputContainer" style="width: 235px">\
<input type="text" id="botReplyMessageCommand'+ i +'" maxlength="200" class="textInput" autocomplete="off" placeholder="Triggering command" data-textsetting="botReplyMessageCommand'+ i +'">\
<label for="botReplyMessageCommand'+ i +'">> Triggering command. eg: !discord</label>\
</div>\
<div class="textInputContainer" style="width: 235px">\
<input type="text" id="botReplyMessageValue'+ i +'" maxlength="200" class="textInput" autocomplete="off" placeholder="Message to respond with" data-textsetting="botReplyMessageValue'+ i +'">\
<label for="botReplyMessageValue'+ i +'">> Message to respond with.</label>\
</div>\
<div class="textInputContainer" style="width: 235px">\
<input type="number" id="botReplyMessageTimeout'+ i +'" class="textInput" min="0" autocomplete="off" placeholder="Timeout needed between responses" data-numbersetting="botReplyMessageTimeout'+ i +'">\
<label for="botReplyMessageTimeout'+ i +'">> Trigger timeout (ms)</label>\
</div>\
<div class="textInputContainer" style="width: 235px" title="If a source is provided, limit the response to this source. Comma-separated" >\
<input type="text" id="botReplyMessageSource'+ i +'" class="textInput" min="0" autocomplete="off" placeholder="ie: youtube,twitch (comma separated)" data-textsetting="botReplyMessageSource'+ i +'">\
<label for="botReplyMessageSource'+ i +'">> Limit to specific sites</label>\
</div>\
<span data-translate="reply-to-all">\
Reply to all instead of just the source\
</span>\
<label class="switch">\
<input type="checkbox" data-setting="botReplyAll'+ i +'">\
<span class="slider round"></span>\
</label>\
</div>';
document.getElementById("botReplyMessages").appendChild(chat);
}
//botReplyAll
var iii = document.querySelectorAll("input[type='checkbox']");
for (var i=0;i<iii.length;i++){
iii[i].onchange = updateSettings;
}
var iii = document.querySelectorAll("input[type='text'],textarea");
for (var i=0;i<iii.length;i++){
iii[i].onchange = updateSettings;
}
var iii = document.querySelectorAll("input[type='text'][class*='instant']");
for (var i=0;i<iii.length;i++){
iii[i].oninput = updateSettings;
}
var iii = document.querySelectorAll("input[type='number']");
for (var i=0;i<iii.length;i++){
iii[i].onchange = updateSettings;
}
var iii = document.querySelectorAll("input[type='password']");
for (var i=0;i<iii.length;i++){
iii[i].onchange = updateSettings;
}
var iii = document.querySelectorAll("input[type='color']");
for (var i=0;i<iii.length;i++){
iii[i].onchange = updateSettings;
}
var iii = document.querySelectorAll("select");
for (var i=0;i<iii.length;i++){
iii[i].onchange = updateSettings;
}
var iii = document.querySelectorAll("button[data-action]");
for (var i=0;i<iii.length;i++){
iii[i].onclick = function(e){
var msg = {};
msg.cmd = this.dataset.action;
msg.ctrl = e.ctrlKey || false;
if (this.dataset.target){
msg.target = this.dataset.target;
}
msg.value = this.dataset.value || null;
if (msg.cmd == "fakemsg"){
chrome.runtime.sendMessage(msg, function (response) {
// actions have callbacks? maybe
});
} else if (msg.cmd == "uploadRAGfile"){
chrome.runtime.sendMessage({cmd: "uploadRAGfile", enhancedProcessing: document.getElementById('enhancedProcessing').checked}, function (response) {
});
} else if (msg.cmd == "savePoll"){
PollManager.saveCurrentPoll();
} else if (msg.cmd == "createNewPoll"){
PollManager.createNewPoll();
} else if (msg.cmd == "bigwipe"){
var confirmit = confirm("Are you sure you want to reset all your settings?");
if (confirmit){
chrome.runtime.sendMessage(msg, function (response) { // actions have callbacks? maybe
setTimeout(function(){
window.location.reload();
},100);
});
}
} else {
console.log(msg);
chrome.runtime.sendMessage(msg, function (response) { // actions have callbacks? maybe
log("ignore callback for this action");
// update(response);
});
}
};
}
document.getElementById("ytcopy").onclick = async function(){
document.getElementById("ytcopy").innerHTML = "📎";
var YoutubeChannel = document.querySelector('input[data-textsetting="youtube_username"]').value;
if (!YoutubeChannel){return;}
if (!YoutubeChannel.startsWith("@")){
YoutubeChannel = "@"+YoutubeChannel;
}
fetch("https://www.youtube.com/c/"+YoutubeChannel+"/live").then((response) => response.text()).then((data) => {
document.getElementById("ytcopy").innerHTML = "🔄";
try{
var videoID = data.split('{"videoId":"')[1].split('"')[0];
log(videoID);
if (videoID){
navigator.clipboard.writeText(videoID).then(() => {
document.getElementById("ytcopy").innerHTML = "✔️"; // Video ID copied to clipboard
setTimeout(function(){
document.getElementById("ytcopy").innerHTML = "📎";
},1000);
}, () => {
document.getElementById("ytcopy").innerHTML = "❌"; // Failed to copy to clipboard
});
}
} catch(e){
document.getElementById("ytcopy").innerHTML = "❓"; // Video not found
}
});
};
checkVersion();
let hideLinks = false;
document.querySelectorAll("input[data-setting='hideyourlinks']").forEach(x=>{
if (x.checked){
hideLinks = true;
}
});
if (hideLinks){
document.body.classList.add("hidelinks");
}
});
var streamID = false;
var lastResponse = false;
function update(response, sync=true){
log("update-> response: ",response);
if (response !== undefined){
if (response.documents){
updateDocumentList(response.documents);
}
if (response.streamID){
lastResponse = response;
streamID = true;
var password = "";
if ('password' in response && response.password){
password = "&password="+response.password;
}
let hideLinks = false;
document.querySelectorAll("input[data-setting='hideyourlinks']").forEach(x=>{
if (x.checked){
hideLinks = true;
}
});
if (hideLinks){
document.body.classList.add("hidelinks");
} else {
document.body.classList.remove("hidelinks");
}
document.getElementById("sessionid").value = response.streamID;
document.getElementById("sessionpassword").value = response.password || "";