forked from vyneer/dgg-chat-gui-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdgg-utilities.user.js
3506 lines (3288 loc) · 141 KB
/
dgg-utilities.user.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
// ==UserScript==
// @name d.gg utilities
// @namespace https://www.destiny.gg/
// @version 1.9
// @description small, but useful tools for both regular dggers and newbies alike
// @author vyneer
// @match *://*.destiny.gg/embed/chat*
// @include /https?:\/\/www\.destiny\.gg\/embed\/chat/
// @run-at document-start
// @allFrames true
// @grant GM.xmlHttpRequest
// @grant GM.registerMenuCommand
// @connect vyneer.me
// @connect mitchdev.net
// @connect youtube.com
// @downloadURL none
// @homepageURL https://github.com/vyneer/dgg-chat-gui-scripts
// @icon data:image/png;base64,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
// ==/UserScript==
// ==Changelog==
// v1.9 - 2024-03-01
// * add native embeds support
// * pull data platforms from vyneer.me (eliminates the need for updates when native phrases/nukes/mutelinks get added)
// * fix a nuke detection bug
// v1.8 - 2023-06-17
// * increased flair check range up to 100 for new flairs (big PepoTurkey to Voiture)
// * add multi-stream chat embed support (big thanks to [@mattroseman](https://github.com/mattroseman) <3)
// * excluded whispers from phrase detection (big PepoTurkey to Revel)
// * add channel+title formatting for YouTube embeds (big thanks to [@cantclosevim](https://github.com/cantclosevim) <3)
// * add Rumble embed formatting
// * add Kick embeds
// * fix broken connection detection
// * add a manual update button
// v1.7.4 - 2023-02-17
// * added an option to stick in-line mentions to top of chat (big PepoTurkey to Voiture for the idea (gobl))
// * fixed the whole script breaking sometimes when "Add button to toggle to the currently embedded video's chat" was on (big thanks to [@mattroseman](https://github.com/mattroseman) <3)
// * fixed chat losing scroll position when "Format YouTube embeds directly in messages according to Utilities settings" formatted an embed
// v1.7.3 - 2023-02-03
// * added an option to embed a hosted stream's chat, same as embedded stream or live YT chat (big thanks to [@mattroseman](https://github.com/mattroseman) <3)
// * fixed settings menu not scrolling
// v1.7.2 - 2022-12-31
// * add an option to update the live pill for Youtube stream with channel name (big thanks to @mattroseman <3)
// * add Rumble embeds
// v1.7.1 - 2022-10-10
// * remove the violentmonkey workaround
let EMBEDS_PROVIDER = "native"; // possible options: vyneer, native, disabled
let PHRASES_PROVIDER = "vyneer"; // possible options: vyneer, native
let NUKES_PROVIDER = "vyneer"; // possible options: vyneer, native
let MUTELINKS_PROVIDER = "vyneer"; // possible options: vyneer, native
// DEBUG MODE, DON'T SET TO TRUE IF YOU DON'T KNOW WHAT YOU'RE DOING
// replaces the data given by the server with data provided below and makes nuke/mutelinks buttons always active
const DEBUG = false;
const DEBUG_NUKE_DATA = [
{
time: "2020-03-20T14:28:23.382748",
type: "meganuke",
duration: "10m",
word: "test",
},
{
time: "2020-03-20T14:28:23.382748",
type: "meganuke",
duration: "10m",
word: "test2",
},
];
const DEBUG_LINKS_DATA = [
{
status: "on",
},
];
const scriptVersion = GM_info.script.version.includes('dev-') ? 'dev' : '';
const timeOptions = {
hour12: false,
hour: "2-digit",
minute: "2-digit",
};
const mutelinksChecklist = [
"https://",
"http://",
"www.",
".com",
".org",
".ru",
".net",
".uk",
".au",
".in",
".de",
".ir",
".ca",
".gov",
".be",
".tv",
".it"
];
let phrases = [];
let phrasesEtag = "";
let nukes = [];
let nukesCompiled = [];
let mutelinks = false;
let foundPhraseOrNuke = false;
let nukesTimestamp = 0;
let mutelinksTimestamp = 0;
let phrasesTimestamp = 0;
const updateCheck = (cb) => {
GM.xmlHttpRequest({
method: "GET",
url: `https://vyneer.me/tools/script/${scriptVersion}`,
onload: (response) => {
if (response.status == 200) {
let data = JSON.parse(response.response);
if ("link" in data && "version" in data) {
if (GM_info.script.version < data.version) {
cb(data);
} else {
cb(undefined);
}
} else {
cb(undefined);
}
} else {
console.error(`[ERROR] [dgg-utils] couldn't check for updates - HTTP status code: ${response.status} - ${response.statusText}`);
}
},
onerror: () => {
console.error(`[ERROR] [dgg-utils] couldn't check for updates - HTTP error`);
},
ontimeout: () => {
console.error(`[ERROR] [dgg-utils] couldn't check for updates - HTTP timeout`);
}
});
}
const gmUpdateDataFunc = (data) => {
if (data) {
window.open(data.link, '_blank').focus();
}
};
GM.registerMenuCommand("Check for updates", () => {
updateCheck(gmUpdateDataFunc)
});
class ConfigItem {
constructor(keyName, defaultValue) {
this.keyName = keyName;
this.defaultValue = defaultValue;
}
}
const configItems = {
alwaysScrollDown : new ConfigItem("alwaysScrollDown", true ),
changeTitleOnLive : new ConfigItem("changeTitleOnLive", false ),
embedIconStyle : new ConfigItem("embedIconStyle", 1 ),
doubleClickCopy : new ConfigItem("doubleClickCopy", false ),
embedChat : new ConfigItem("embedChat", false ),
embedsOnLaunch : new ConfigItem("embedsOnLaunch", false ),
showLastVOD : new ConfigItem("showLastVOD", false ),
lastEmbeds : new ConfigItem("lastEmbeds", false ),
lastIfNone : new ConfigItem("lastIfNone", false ),
embedTime : new ConfigItem("embedTime", 30 ),
twitchEmbedFormat : new ConfigItem("twitchEmbedFormat", 1 ),
youtubeEmbedFormat: new ConfigItem("youtubeEmbedFormat", 1 ),
rumbleEmbedFormat : new ConfigItem("rumbleEmbedFormat", 1 ),
nativeEmbedTop : new ConfigItem("nativeEmbedTop", 5 ),
nativeEmbedLimit : new ConfigItem("nativeEmbedLimit", 0 ),
colorOnMutelinks : new ConfigItem("colorOnMutelinks", false ),
phraseColor : new ConfigItem("phraseColor", "1f0000"),
nukeColor : new ConfigItem("nukeColor", "1f1500"),
mutelinksColor : new ConfigItem("mutelinksColor", "120016"),
customPhrases : new ConfigItem("customPhrases", [] ),
customPhrasesSoft : new ConfigItem("customPhrasesSoft", [] ),
customColor : new ConfigItem("customColor", "1f0000"),
customSoftColor : new ConfigItem("customSoftColor", "260019"),
editEmbeds : new ConfigItem("editEmbeds", false ),
editEmbedPill : new ConfigItem("editEmbedPill", false ),
preventEnter : new ConfigItem("preventEnter", false ),
hiddenFlairs : new ConfigItem("hiddenFlairs", [] ),
stickyMentions : new ConfigItem("stickyMentions", false ),
stickyWhispers : new ConfigItem("stickyWhispers", false ),
ignorePhrases : new ConfigItem("ignorePhrases", false ),
ignoredPhraseList : new ConfigItem("ignoredPhraseList", [] ),
ignoreProviders : new ConfigItem("ignoreProviders", false ),
};
class Config {
#configItems;
#configKeyPrefix;
constructor(configKeys, keyPrefix) {
this.#configItems = configKeys;
this.#configKeyPrefix = keyPrefix;
// Creates setter funcs in this object (config)
// So when the config.key value is changed it is also saved in localStorage
for (const key in this.#configItems) {
const configKey = this.#configItems[key];
const keyName = configKey.keyName;
const privateKeyName = `#${keyName}`;
Object.defineProperty(this, key, {
set: function (value) {
// Set the private value
this[privateKeyName] = value;
// Save it to persistent storage as well
this.#save(keyName, value);
},
get: function () {
// Check if value is saved in config object
if (this[privateKeyName] === undefined) {
// If not, load it from persistent storage, or use default value
this[privateKeyName] = this.#load(keyName) ?? configKey.defaultValue;
}
return this[privateKeyName];
},
});
}
}
#getFullKeyName(configKey) {
return `${this.#configKeyPrefix}${configKey}`;
}
#save(configKey, value) {
// Persist the value in LocalStorage
const fullKeyName = this.#getFullKeyName(configKey);
window.localStorage.setItem(fullKeyName, JSON.stringify(value));
}
#load(configKey) {
// Get the value we persisted, in localStorage
const fullKeyName = this.#getFullKeyName(configKey);
const item = window.localStorage.getItem(fullKeyName);
if (item != null) {
const parsedItem = JSON.parse(item);
return parsedItem;
}
}
};
const config = new Config(configItems, "vyneer-util.");
document.addEventListener(
"keypress",
function (e) {
let textarea = document.querySelector("#chat-input-control");
if (e.key === "Enter" && !e.altKey && foundPhraseOrNuke && config.preventEnter) {
e.preventDefault();
e.stopImmediatePropagation();
textarea.classList.add("alertAnim");
setTimeout(() => {
textarea.classList.remove("alertAnim");
}, 1000);
}
return false;
},
true
);
if (config.ignoreProviders) {
if (document.readyState !== "loading") {
injectScript();
} else {
document.addEventListener("DOMContentLoaded", injectScript);
}
} else {
GM.xmlHttpRequest({
method: "GET",
url: `https://vyneer.me/tools/providers`,
onload: (response) => {
if (response.status == 200) {
let data = JSON.parse(response.response);
if ("embeds" in data && "phrases" in data && "nukes" in data && "links" in data) {
EMBEDS_PROVIDER = data.embeds ?? EMBEDS_PROVIDER;
PHRASES_PROVIDER = data.phrases ?? PHRASES_PROVIDER;
NUKES_PROVIDER = data.nukes ?? NUKES_PROVIDER;
MUTELINKS_PROVIDER = data.links ?? MUTELINKS_PROVIDER;
}
} else {
console.error(`[ERROR] [dgg-utils] couldn't get providers - HTTP status code: ${response.status} - ${response.statusText}`);
}
if (document.readyState !== "loading") {
injectScript();
} else {
document.addEventListener("DOMContentLoaded", injectScript);
}
},
onerror: () => {
console.error(`[ERROR] [dgg-utils] couldn't get providers - HTTP error`);
if (document.readyState !== "loading") {
injectScript();
} else {
document.addEventListener("DOMContentLoaded", injectScript);
}
},
ontimeout: () => {
console.error(`[ERROR] [dgg-utils] couldn't get providers - HTTP timeout`);
if (document.readyState !== "loading") {
injectScript();
} else {
document.addEventListener("DOMContentLoaded", injectScript);
}
}
});
}
function injectScript() {
let chatlines = document.querySelector(".chat-lines");
let textarea = document.querySelector("#chat-input-control");
let scrollnotify = document.querySelector(".chat-scroll-notify");
let livePill = undefined;
try {
livePill = !window.parent.location.href.includes("embed")
? window.parent.document.querySelector("#host-pill-type")
: undefined
} catch (e) {
console.warn(`[WARNING] [dgg-utils] script might be running in cross-origin frame, can't get the live pill, the "change title on live" feature wont work - ${e}`);
}
let utilSettingsStyle = document.createElement("style");
let utilSettingsStyleString = `
#util-settings-btn {
width: 95%;
height: 32px;
color: #B9B9B9;
background-color: #030303;
margin-left: 2.5%;
}
#util-settings-btn:hover {
cursor: pointer;
border: 2px solid #B9B9B9;
}
#util-settings #util-settings-form {
margin: .9em 0;
}
#util-settings .form-group {
margin: .9em .9em;
display: block;
position: relative
}
#util-settings h4 {
font-size: 0.9em;
margin-bottom: .9em;
padding-left: .9em;
color: #494949;
text-transform: uppercase;
font-weight: 600
}
#util-settings label {
display: inline-block;
font-weight: normal;
max-width: 100%;
margin-bottom: .6em
}
#util-settings .checkbox label {
margin-bottom: 0;
font-weight: 400;
max-width: 100%;
cursor: pointer;
display: flex;
justify-items: center;
align-items: center
}
#util-settings .checkbox input {
margin: 0 .3em 0 0;
line-height: normal;
box-sizing: border-box;
padding: 0
}
#util-settings select {
border-radius: .25em;
padding: .3em;
width: 100%
}
#util-update-group {
display: flex;
justify-content: center;
}
#util-update-group a {
width: 75%;
text-align: center;
}
#util-update-group a.no-link:hover {
text-decoration: none;
}
`
utilSettingsStyle.innerHTML = utilSettingsStyleString;
utilSettingsStyle.id = "utilSettingsStyle";
document.head.appendChild(utilSettingsStyle);
let alertAnimationStyle = document.createElement("style");
let keyFrames = `
:root {
--flashing-color: #1f0000;
}
@keyframes bannedAlert {
0%,
50%,
100% {
background-color: #111;
}
25%,
75% {
background-color: var(--flashing-color);
}
}
.alertAnim {
animation: bannedAlert 1s;
}`;
alertAnimationStyle.innerHTML = keyFrames;
document.head.appendChild(alertAnimationStyle);
// make an observer to show an update message after the "connected" alert in chat
let updateObserver = new MutationObserver((mutations) => {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (node.matches('div[class="msg-chat msg-status "]')) {
if (
node
.querySelector('span[class="text"]')
.innerHTML.includes("Connected")
) {
// checking the scripts version
// we check the difference between the current install's version and the API
// if the API shows there's an update, show a message
const updateDataFunc = (data) => {
if (data) {
new DGGMsg(
`Hey! Looks like you're using an older version of d.gg utilities (v${GM_info.script.version}). You can download the latest version v${data.version} here - <a href="${data.link}" target="_blank">${data.link}</a>`,
"msg-info msg-historical",
""
);
chatlines.scrollTop = chatlines.scrollHeight;
}
};
updateCheck(updateDataFunc);
// show embeds on launch
if (config.embedsOnLaunch && EMBEDS_PROVIDER !== "disabled") {
embeds();
}
updateObserver.disconnect();
}
}
}
}
});
updateObserver.observe(chatlines, { childList: true });
// Add custom style rules to this
let settingsCss = "";
// making a button for message sending
let chatToolsArea = document.querySelectorAll(".chat-tools-group")[1];
let sendAnywayButton = document.createElement("a");
sendAnywayButton.id = "send-anyway-btn";
sendAnywayButton.className = "chat-tool-btn";
sendAnywayButton.title = "Send Anyway";
sendAnywayButton.style.display = "none";
let sendAnywayButton_i = document.createElement("i");
sendAnywayButton_i.className = "btn-icon";
sendAnywayButton_i.innerHTML = "✉️";
sendAnywayButton_i.style.fontStyle = "normal";
sendAnywayButton_i.style.fontSize = "larger";
sendAnywayButton_i.style.textAlign = "center";
sendAnywayButton_i.style.textShadow = "0 0 white";
sendAnywayButton.addEventListener("click", () => {
// this one to actually send the message
textarea.dispatchEvent(
new KeyboardEvent("keypress", {
key: "Enter",
keyCode: 13,
code: "Enter",
which: 13,
altKey: true,
})
);
// this one to update the text area
textarea.dispatchEvent(
new KeyboardEvent("keyup", {
key: "Enter",
keyCode: 13,
code: "Enter",
which: 13,
altKey: true,
})
);
});
// making a button for embeds
let embedsButton = document.createElement("a");
embedsButton.id = "embeds-btn";
embedsButton.className = "chat-tool-btn";
embedsButton.title = "Embeds";
let embedsButton_i = document.createElement("i");
embedsButton_i.className = "btn-icon";
if (config.embedIconStyle !== 1) {
embedsButton_i.innerHTML = "🎬";
} else {
embedsButton_i.style.backgroundImage = `url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8' standalone='no'%3F%3E%3Csvg width='25' height='25' viewBox='-25 -10 150 150' version='1.1' id='svg5' xml:space='preserve' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'%3E%3Cdefs id='defs2' /%3E%3Cpath style='opacity:1;fill:%23ffffff;fill-opacity:1;stroke-width:0.406658' d='m 92.631299,98.472455 c 0,3.664485 -3.18611,6.614595 -7.14375,6.614595 H 10.399791 c -3.9576372,0 -7.0776042,-3.01626 -7.0776042,-6.680745 0,-8.21058 0.06729,-51.199364 0.06729,-57.368996 L 92.635479,40.896992' id='lower' /%3E%3Crect style='opacity:1;fill:%23ffffff;fill-opacity:1;stroke-width:0.334081' id='upper' width='89.762489' height='14.542242' x='-6.0129457' y='22.639624' transform='matrix(0.96526009,-0.26129094,0.25636721,0.96657946,0,0)' /%3E%3C/svg%3E%0A")`;
}
embedsButton_i.style.fontStyle = "normal";
embedsButton_i.style.fontSize = "larger";
embedsButton_i.style.textAlign = "center";
switch (config.embedIconStyle) {
case 3:
embedsButton_i.style.filter = "saturate(0)";
break;
case 4:
embedsButton_i.style.color = "transparent";
embedsButton_i.style.textShadow = "0 0 white";
break;
}
let nativeEmbedsWs = undefined;
let nativeEmbedsReconnectCount = 0;
const nativeEmbedsConnect = () => {
nativeEmbedsWs = new WebSocket("wss://live.destiny.gg/ws");
nativeEmbedsWs.onmessage = (event) => {
nativeEmbedsReconnectCount = 0;
let data = JSON.parse(event.data);
if (data.type == "dggApi:embeds") {
localStorage.setItem(data.type, JSON.stringify(data.data));
}
}
nativeEmbedsWs.onclose = (event) => {
console.warn(`[WARNING] [dgg-utils] closed the native dgg embeds websocket connection, reconnecting in ${nativeEmbedsReconnectCount} sec - ${event.code}: ${event.reason}`);
setTimeout(() => {
switch (true) {
case nativeEmbedsReconnectCount == 0:
nativeEmbedsReconnectCount = 1;
break;
case nativeEmbedsReconnectCount > 0 && nativeEmbedsReconnectCount < 32:
nativeEmbedsReconnectCount *= 2;
break;
default:
break;
}
nativeEmbedsConnect();
}, nativeEmbedsReconnectCount*1000);
}
}
if (EMBEDS_PROVIDER === "native" && window.parent.location.href.includes("embed")) {
nativeEmbedsConnect();
}
// making an error alert
let chatWhispersArea = document.querySelectorAll(".chat-tools-group")[0];
let errorAlert = document.createElement("a");
errorAlert.id = "error-alert";
errorAlert.className = "chat-tool-btn";
errorAlert.title = "Can't connect to vyneer.me";
errorAlert.style.cursor = "unset";
errorAlert.style.display = "none";
let errorAlert_i = document.createElement("i");
errorAlert_i.className = "btn-icon";
errorAlert_i.innerHTML = "⚠️";
errorAlert_i.style.fontStyle = "normal";
errorAlert_i.style.fontSize = "larger";
errorAlert_i.style.textAlign = "center";
errorAlert_i.style.color = "red";
errorAlert_i.style.opacity = 1;
// making a button for the nuke alert
let nukeAlertButton = document.createElement("a");
nukeAlertButton.id = "nukes-btn";
nukeAlertButton.className = "chat-tool-btn";
nukeAlertButton.title = "Nukes";
nukeAlertButton.style.display = "none";
if (DEBUG) {
nukeAlertButton.style.display = "";
}
let nukeAlertButton_i = document.createElement("i");
nukeAlertButton_i.className = "btn-icon";
nukeAlertButton_i.innerHTML = "☢";
nukeAlertButton_i.style.fontStyle = "normal";
nukeAlertButton_i.style.fontSize = "larger";
nukeAlertButton_i.style.textAlign = "center";
nukeAlertButton_i.style.color = "yellow";
nukeAlertButton_i.style.opacity = 1;
// making a button for the mutelinks alert
let linksAlertButton = document.createElement("a");
linksAlertButton.id = "mutelinks-btn";
linksAlertButton.className = "chat-tool-btn";
linksAlertButton.title = "Mutelinks";
linksAlertButton.style.display = "none";
if (DEBUG) {
linksAlertButton.style.display = "inline-flex";
}
linksAlertButton.style.justifyContent = "center";
linksAlertButton.style.width = "auto";
linksAlertButton.style.cursor = "unset";
let linksAlertButton_i = document.createElement("i");
linksAlertButton_i.className = "btn-icon";
linksAlertButton_i.innerHTML = "🔗";
linksAlertButton_i.style.fontStyle = "normal";
linksAlertButton_i.style.fontSize = "larger";
linksAlertButton_i.style.textAlign = "center";
linksAlertButton_i.style.opacity = 1;
let linksAlertButton_span = document.createElement("span");
linksAlertButton_span.className = "btn-icon";
linksAlertButton_span.innerHTML = "";
linksAlertButton_span.style.opacity = 1;
linksAlertButton_span.style.left = "100%";
linksAlertButton_span.style.color = "#FFF7F9";
linksAlertButton_span.style.fontSize = "0.75em";
linksAlertButton_span.style.position = "absolute";
linksAlertButton_span.style.verticalAlign = "text-button";
linksAlertButton_span.style.marginLeft = "0.25em";
linksAlertButton_span.style.top = "4px";
// make a container for the custom buttons so that we could move em together
let utilitiesButtons = document.createElement("div");
// appending buttons to the right area on screen
sendAnywayButton.appendChild(sendAnywayButton_i);
embedsButton.appendChild(embedsButton_i);
errorAlert.appendChild(errorAlert_i);
nukeAlertButton.appendChild(nukeAlertButton_i);
linksAlertButton.appendChild(linksAlertButton_i);
linksAlertButton.appendChild(linksAlertButton_span);
if (EMBEDS_PROVIDER === "vyneer" || (window.parent.location.href.includes("embed") && EMBEDS_PROVIDER !== "disabled")) {
chatToolsArea.prepend(embedsButton);
}
if (PHRASES_PROVIDER === "vyneer" || NUKES_PROVIDER === "vyneer" || MUTELINKS_PROVIDER === "vyneer") {
chatToolsArea.prepend(sendAnywayButton);
}
utilitiesButtons.appendChild(errorAlert);
if (NUKES_PROVIDER === "vyneer") {
utilitiesButtons.appendChild(nukeAlertButton);
}
if (MUTELINKS_PROVIDER === "vyneer") {
utilitiesButtons.appendChild(linksAlertButton);
}
chatWhispersArea.appendChild(utilitiesButtons);
// creating the settings page
// make sure we only create the nanoscroller once
let settingsInit = false;
// there's like a billion layers here, very annoying and ugly
// this is the main one
let utilSettings = document.createElement("div");
utilSettings.id = "util-settings";
utilSettings.className = "chat-menu right";
document.querySelector("#chat").appendChild(utilSettings);
// making a button to open the settings menu
let settingsButton = document.createElement("button");
settingsButton.id = "util-settings-btn";
settingsButton.innerHTML = "d.gg utilities settings";
settingsButton.addEventListener("click", () => {
// it closes the vanilla chat settings menu first (with a click, to avoid doubleclicks later)
document.querySelector("#chat-settings-btn").click();
// show dgg util settings with a class change
utilSettings.classList.toggle("active");
// if we havent opened the dgg utils settings pane before, make it scrollable with the nanoscroller thing
if (!settingsInit) {
settingsInit = true;
}
})
// make sure we close the settings pane when we click on any of the other buttons in the bottom panel
document.querySelectorAll("#chat-emoticon-btn, #chat-whisper-btn, #chat-settings-btn, #chat-users-btn").forEach((el) => {
el.addEventListener("click", () => {
if (utilSettings.classList.contains("active")) {
utilSettings.classList.remove("active");
}
})
})
// make sure we close the settings pane when we click on the bottom panel itself
document.querySelector("#chat-tools-wrap").addEventListener("click", () => {
if (utilSettings.classList.contains("active")) {
utilSettings.classList.remove("active");
}
})
// make sure we close the settings pane when we click on chat
document.querySelector("#chat-output-frame").addEventListener("click", () => {
if (utilSettings.classList.contains("active")) {
utilSettings.classList.remove("active");
}
})
// append the button
document.querySelector("#chat-settings-form").appendChild(settingsButton);
// another layer...
let settingsAreaOuter = document.createElement("div");
settingsAreaOuter.className = "chat-menu-inner";
// create the toolbar
let utilToolbar = document.createElement("div");
utilToolbar.className = "toolbar";
let utilToolbarInner = document.createElement("h5");
let utilToolbarInnerTitle = document.createElement("span");
utilToolbarInnerTitle.innerHTML = `d.gg utilities v${GM_info.script.version}`;
utilToolbarInner.appendChild(utilToolbarInnerTitle);
// create the toolbar close button
let utilToolbarInnerClose = document.createElement("i");
utilToolbarInnerClose.className = "chat-menu-close";
// close the settings pane when clicking on the button
utilToolbarInnerClose.addEventListener("click", () => {
utilSettings.classList.remove("active");
})
utilToolbarInner.appendChild(utilToolbarInnerClose);
utilToolbar.appendChild(utilToolbarInner);
settingsAreaOuter.appendChild(utilToolbar);
// combined nanoscroller layer
let nano = document.createElement("div");
nano.className = "scrollable nano has-scrollbar";
nano.style.overflowY = "auto";
settingsAreaOuter.appendChild(nano);
// content layer
let nanoContent = document.createElement("div");
nanoContent.className = "content nano-content";
nanoContent.tabIndex = "0";
nanoContent.style = "right: -17px;";
nano.appendChild(nanoContent);
// finally, our settings area
let settingsArea = document.createElement("div");
settingsArea.id = "util-settings-form";
nanoContent.appendChild(settingsArea);
utilSettings.appendChild(settingsAreaOuter);
// making an update check wrapper
let updateCheckGroup = document.createElement("div");
updateCheckGroup.id = 'util-update-group';
const updateCheckText = document.createElement('a');
updateCheckText.role = "button";
updateCheckText.textContent = "Check for updates";
updateCheckGroup.append(updateCheckText);
const updateDataFunc = (data) => {
if (data) {
updateCheckText.href = data.link;
updateCheckText.target = '_blank';
updateCheckText.textContent = `New version found (${data.version}), click to update`;
updateCheckText.style.color = 'fuchsia';
updateCheckText.removeEventListener("click", updateClickFunc);
} else {
updateCheckText.textContent = 'No updates found :)';
updateCheckText.classList.toggle('no-link', true);
updateCheckText.style.color = 'green';
updateCheckText.removeEventListener("click", updateClickFunc);
setTimeout(() => {
updateCheckText.textContent = "Check for updates";
updateCheckText.classList.toggle('no-link', false);
updateCheckText.style.removeProperty('color');
updateCheckText.addEventListener("click", updateClickFunc);
}, 5000);
}
};
const updateClickFunc = () => {
updateCheck(updateDataFunc);
};
updateCheckText.addEventListener("click", updateClickFunc);
settingsArea.appendChild(updateCheckGroup);
let title = document.createElement("h4");
title.innerHTML = `Utilities General Settings`;
// appending it to the settings menu
settingsArea.appendChild(title);
// creating an always scroll down setting
let alwaysScrollDownGroup = document.createElement("div");
alwaysScrollDownGroup.className = "form-group checkbox";
let alwaysScrollDownLabel = document.createElement("label");
alwaysScrollDownLabel.innerHTML = "Always scroll down chat on button press";
alwaysScrollDownGroup.appendChild(alwaysScrollDownLabel);
let alwaysScrollDownCheck = document.createElement("input");
alwaysScrollDownCheck.name = "alwaysScrollDown";
alwaysScrollDownCheck.type = "checkbox";
alwaysScrollDownCheck.checked = config.alwaysScrollDown;
alwaysScrollDownCheck.addEventListener("change", () => config.alwaysScrollDown = alwaysScrollDownCheck.checked);
alwaysScrollDownLabel.prepend(alwaysScrollDownCheck);
// isUsername checks if the given element is a username element (can be usernames in messages themselves or in the list of current users)
function isUsername(element) {
return (
element.classList.contains("user") ||
element.classList.contains("chat-user")
);
}
function doubleClickCopyListener(event) {
const target = event.target;
if (!isUsername(target)) {
return;
}
const username = target.text || target.textContent;
// if the chat input has some text, and the last character isn't already a space
if (
textarea.value.length > 0 &&
textarea.value.charAt(textarea.value.length - 1) != " "
) {
textarea.value += " ";
}
textarea.value += `${username} `;
textarea.focus();
}
// creating a double click to copy setting
let doubleClickCopyGroup = document.createElement("div");
doubleClickCopyGroup.className = "form-group checkbox";
let doubleClickCopyLabel = document.createElement("label");
doubleClickCopyLabel.innerHTML =
"Double click username to append it to chat input";
doubleClickCopyGroup.appendChild(doubleClickCopyLabel);
let doubleClickCopyCheck = document.createElement("input");
doubleClickCopyCheck.name = "doubleClickCopy";
doubleClickCopyCheck.type = "checkbox";
doubleClickCopyCheck.checked = config.doubleClickCopy;
doubleClickCopyCheck.addEventListener("change", () => {
config.doubleClickCopy = doubleClickCopyCheck.checked;
window.removeEventListener("dblclick", doubleClickCopyListener);
if (config.doubleClickCopy) {
// if a username is double clicked copy it to the chat input
window.addEventListener("dblclick", doubleClickCopyListener);
}
});
if (config.doubleClickCopy) {
// if a username is double clicked copy it to the chat input
window.addEventListener("dblclick", doubleClickCopyListener);
}
doubleClickCopyLabel.prepend(doubleClickCopyCheck);
// =============================================================
// Icons and HTML elements for managing the DGG & embedded chats
// =============================================================
const DGG_CHAT_ICON = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1960 1960" fill="currentColor" style="vertical-align: baseline; filter: drop-shadow(1px 1px 1px #000)">
<g>
<path d="M0 980 l0 -980 980 0 980 0 0 980 0 980 -980 0 -980 0 0 -980z m1810 615 l0 -185 -117 0 -116 0 -116 123 c-64 67 -142 150 -175 185 l-59 62 291 0 292 0 0 -185z m-597 -30 l187 -194 0 -402 0 -401 -184 -191 -183 -192 -437 -3 -436 -2 0 790 0 790 433 0 433 0 187 -195z m597 -1230 l0 -185 -292 0 -291 0 24 27 c13 15 91 98 173 185 l150 158 118 0 118 0 0 -185z"/>
<path d="M670 980 l0 -550 65 0 65 0 0 550 0 550 -65 0 -65 0 0 -550z"/>
</g>
</svg>
`;
const TWITCH_CHAT_ICON = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 21" fill="currentColor" style="vertical-align: baseline; filter: drop-shadow(1px 1px 1px #000)">
<path d="M 5.8730469 2 C 5.5530469 2 5.2524531 2.1521094 5.0644531 2.4121094 L 2.1914062 6.375 C 2.0674063 6.546 2 6.7518906 2 6.9628906 L 2 19 C 2 19.552 2.448 20 3 20 L 7 20 L 7 22 C 7 22.552 7.448 23 8 23 L 9.5859375 23 C 9.8509375 23 10.104969 22.895031 10.292969 22.707031 L 12.707031 20.292969 C 12.894031 20.104969 13.149062 20 13.414062 20 L 16.585938 20 C 16.850938 20 17.104969 19.895031 17.292969 19.707031 L 21.707031 15.292969 C 21.895031 15.105969 22 14.850938 22 14.585938 L 22 3 C 22 2.448 21.552 2 21 2 L 5.8730469 2 z M 6 4 L 20 4 L 20 13 L 17 16 L 12 16 L 9 19 L 9 16 L 6 16 L 6 4 z M 12 7 C 11.448 7 11 7.448 11 8 L 11 11 C 11 11.552 11.448 12 12 12 C 12.552 12 13 11.552 13 11 L 13 8 C 13 7.448 12.552 7 12 7 z M 17 7 C 16.448 7 16 7.448 16 8 L 16 11 C 16 11.552 16.448 12 17 12 C 17.552 12 18 11.552 18 11 L 18 8 C 18 7.448 17.552 7 17 7 z"/>
</svg>
`;
const YOUTUBE_CHAT_ICON = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="2 4 26 22" fill="currentColor" style="vertical-align: baseline; filter: drop-shadow(1px 1px 1px #000)">
<path d="M 15 4 C 10.814 4 5.3808594 5.0488281 5.3808594 5.0488281 L 5.3671875 5.0644531 C 3.4606632 5.3693645 2 7.0076245 2 9 L 2 15 L 2 15.001953 L 2 21 L 2 21.001953 A 4 4 0 0 0 5.3769531 24.945312 L 5.3808594 24.951172 C 5.3808594 24.951172 10.814 26.001953 15 26.001953 C 19.186 26.001953 24.619141 24.951172 24.619141 24.951172 L 24.621094 24.949219 A 4 4 0 0 0 28 21.001953 L 28 21 L 28 15.001953 L 28 15 L 28 9 A 4 4 0 0 0 24.623047 5.0546875 L 24.619141 5.0488281 C 24.619141 5.0488281 19.186 4 15 4 z M 12 10.398438 L 20 15 L 12 19.601562 L 12 10.398438 z"/>
</svg>
`;
const RUMBLE_CHAT_ICON = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="1 0 20 20" fill="currentColor" style="vertical-align: baseline; filter: drop-shadow(1px 1px 1px #000)">
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.165 11.292c.843-.617.843-1.809 0-2.442a19.617 19.617 0 00-3.922-2.308 1.624 1.624 0 00-1.419.053 1.54 1.54 0 00-.536.474 1.462 1.462 0 00-.254.656 18.136 18.136 0 00-.13 4.584c.023.233.104.458.234.656s.308.364.518.485a1.614 1.614 0 001.404.1 18.68 18.68 0 004.105-2.25v-.008zm6.304-4.5a4.617 4.617 0 011.393 3.276 4.614 4.614 0 01-1.376 3.282c-3.23 3.241-7.376 5.509-11.93 6.525a4.859 4.859 0 01-3.422-.425 4.53 4.53 0 01-2.187-2.558C.556 12.559.765 7.659 2.104 3.309A4.491 4.491 0 014.177.66 4.834 4.834 0 017.582.11c4.47.983 8.67 3.5 11.887 6.683z" />
</svg>
`;
const KICK_CHAT_ICON = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="6 5 20 22" fill="currentColor" style="vertical-align: baseline; filter: drop-shadow(1px 1px 1px #000)">
<polygon fill-rule="evenodd" points="6.18 4.99 13.61 4.99 13.61 9.9 16 9.9 16 7.38 18.52 7.38 18.52 4.99 25.82 4.99 25.82 12.29 23.43 12.29 23.43 14.8 20.91 14.8 20.91 17.2 23.43 17.2 23.43 19.71 25.82 19.71 25.82 27.01 18.52 27.01 18.52 24.62 16 24.62 16 22.1 13.61 22.1 13.61 27.01 6.18 27.01 6.18 4.99"/>
</svg>
`;
const EMBED_BUTTON_STYLE= {
'display': 'flex',
'justify-content': 'center',
'align-items': 'center',
'height': '15px',
'width': '15px',
'margin-right': '5px'
};
const dggChatButton = document.createElement('a');
dggChatButton.id = 'dgg-chat-btn';
dggChatButton.addEventListener('click', handleDGGChatButtonClick);
Object.assign(dggChatButton.style, EMBED_BUTTON_STYLE);
dggChatButton.innerHTML = DGG_CHAT_ICON;
const twitchChatButton = document.createElement('a');
twitchChatButton.id = 'twitch-chat-btn';
twitchChatButton.addEventListener('click', handleTwitchChatButtonClick);
Object.assign(twitchChatButton.style, EMBED_BUTTON_STYLE);
twitchChatButton.innerHTML = TWITCH_CHAT_ICON;
const youtubeChatButton = document.createElement('a');
youtubeChatButton.id = 'yt-chat-btn';
youtubeChatButton.addEventListener('click', handleYoutubeChatButtonClick);
Object.assign(youtubeChatButton.style, EMBED_BUTTON_STYLE);
youtubeChatButton.innerHTML = YOUTUBE_CHAT_ICON;
const rumbleChatButton = document.createElement('a');
rumbleChatButton.id = 'rumble-chat-btn';
rumbleChatButton.addEventListener('click', handleRumbleChatButtonClick);
Object.assign(rumbleChatButton.style, EMBED_BUTTON_STYLE);
rumbleChatButton.innerHTML = RUMBLE_CHAT_ICON;
const embedChatButtonsContainer = document.createElement('div');
embedChatButtonsContainer.id = 'embed-chat-btns-container';
embedChatButtonsContainer.className += 'float-start';
Object.assign(embedChatButtonsContainer.style, {
'display': 'flex',
'flex-direction': 'row',
'justify-content': 'center',
'align-items': 'center',
'height': '100%',
'color': '#444444'
});
embedChatButtonsContainer.appendChild(dggChatButton);
embedChatButtonsContainer.appendChild(twitchChatButton);
embedChatButtonsContainer.appendChild(youtubeChatButton);
embedChatButtonsContainer.appendChild(rumbleChatButton);
// =========================================
// Functions for managing the embedded chats
// =========================================
const YOUTUBE_EMBED_RE = /^#youtube\/(.*)$/
const TWITCH_EMBED_RE = /^#twitch\/(.*)$/
const RUMBLE_EMBED_RE = /^#rumble\/(.*)$/
const STORAGE_STREAM_INFO_KEY = "dggApi:streamInfo";
const STORAGE_HOST_INFO_KEY = "dggApi:hosting";
let dggChatIFrame;
if (livePill != undefined) {
dggChatIFrame = window.parent.document.getElementById("chat-wrap").getElementsByTagName("iframe")[0];
}
let embedChatIFrame;
let embedChatActive = false;
function getYoutubeEmbedId() {
const match = YOUTUBE_EMBED_RE.exec(window.parent.location.hash);
return match ? match[1] : null;
}
function getTwitchEmbedId() {
const match = TWITCH_EMBED_RE.exec(window.parent.location.hash);
return match ? match[1] : null;
}
function getRumbleEmbedId() {
const match = RUMBLE_EMBED_RE.exec(window.parent.location.hash);
return match ? match[1] : null
}
function getYoutubeHostId() {
const hostInfo = JSON.parse(localStorage.getItem(STORAGE_HOST_INFO_KEY));
return hostInfo?.platform === 'youtube' ? hostInfo.id : null;
}
function getTwitchHostId() {
const hostInfo = JSON.parse(localStorage.getItem(STORAGE_HOST_INFO_KEY));
return hostInfo?.platform === 'twitch' ? hostInfo.id : null;
}
function getRumbleHostId() {
const hostInfo = JSON.parse(localStorage.getItem(STORAGE_HOST_INFO_KEY));
return hostInfo?.platform === 'rumble' ? hostInfo.id : null;
}
function getYoutubeLiveId() {
const streamInfo = JSON.parse(localStorage.getItem(STORAGE_STREAM_INFO_KEY));
return streamInfo?.streams?.youtube?.id;
}
// Copium
function getTwitchLiveId() {
const streamInfo = JSON.parse(localStorage.getItem(STORAGE_STREAM_INFO_KEY));
return streamInfo?.streams?.twitch?.id;
}
function getRumbleLiveId() {
const streamInfo = JSON.parse(localStorage.getItem(STORAGE_STREAM_INFO_KEY));
return streamInfo?.streams?.rumble?.id;
}
function getTwitchChatURL() {
const twitchEmbedId = getTwitchEmbedId() || getTwitchLiveId() || getTwitchHostId();
return twitchEmbedId ? `https://www.twitch.tv/embed/${twitchEmbedId}/chat?parent=www.destiny.gg&darkpopout` : null;
}
function getYoutubeChatURL() {
// if the user is embedding a video while the stream is live, the embedded id will be favored
const youtubeEmbedId = getYoutubeEmbedId() || getYoutubeLiveId() || getYoutubeHostId();
return youtubeEmbedId ? `https://www.youtube.com/live_chat?v=${youtubeEmbedId}&embed_domain=www.destiny.gg` : null;
}
function getRumbleChatURL() {
// if the user is embedding a video while the stream is live, the embedded id will be favored
let rumbleEmbedId = getRumbleEmbedId() || getRumbleLiveId() || getRumbleHostId();
if (!rumbleEmbedId) return null;
// remove the 'v' prefix if present, as it's technically not a part of the rumble embed's id
if (rumbleEmbedId[0] === 'v') {
rumbleEmbedId = rumbleEmbedId.slice(1);