forked from zimny-lech/CyTube-Plus
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
4866 lines (4327 loc) · 160 KB
/
main.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
/*
The MIT License (MIT)
//
Copyright (c) 2013-2014 Zimny Lech, 2022-2023 CyDJ developers
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
off the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import {config, icon, library} from '@fortawesome/fontawesome-svg-core';
import {faCamera} from '@fortawesome/free-solid-svg-icons';
import {intAnal} from './lib/analytics';
import {formatBadgeToHtml, USER_BADGES} from './lib/badges';
import {prepareMessage} from './lib/commands';
import {getChatCommands} from './lib/commandsV2';
import {CHANNEL_DATABASE} from './lib/database';
import {LOGOS} from './lib/logos';
import {initTwemoji} from './lib/twemoji';
config.autoA11y = true;
export const camera = icon({prefix: 'fas', iconName: 'camera'});
library.add(faCamera);
/* ----- STARTING CONFIGURATION - USER INTERFACE (UI) ----- */
// CONFIGURATION NOTES:
// In this section you can immediately enable and disable each option (set '1' to enable, '0' to
// disable) Every option marked as [&] requires additional configuration (see other sections below)
// WARNING! apostrophe sign (') in all text/html values must be prepend with "\" sign (e.g.
// "don\'t")
// FILTERS INSTALLATION: open 'Channel Settings' modal window, go to 'Edit' -> 'Chat Filters', click
// 'Prepare fonts filters' button, and import
// adds debugging bootan debug1
const UI_DEBUG = false;
// adds google analytics and cookies
const GAnalytics = false;
// default old Synchtube layout (player and playlist on the left)
const UI_DefaultSynchtube = true;
// [&] channel favicon
const UI_Favicon = true;
// [&] small channel logo/avatar in the top navbar
const UI_MiniLogo = true;
// [&] channel custom brand name
const UI_ChannelName = true;
// [&] additional header dropdown menu
const UI_HeaderDropMenu = true;
// removing 'Layout' menu from the header
const UI_RemoveLayoutMenu = true;
// [&] big channel logo inserted into MOTD
const UI_MOTDAutoLogo = true;
// [&] switchable MOTD tabs application for homepage-like channel header
const UI_MOTDTabs = false;
// deleting previous MOTD after accepting/loading script
const UI_MOTDDelete = false;
// [&] button displaying channel rules
const UI_RulesBtn = true;
// [&] imageboard-style attention bar (requires external application)
const UI_AttentionBar = false;
// [&] additional custom channel announcement
const UI_ChannelAnnouncement = false;
// full-width video title bar
const UI_FullTitleBar = true;
// YouTube/Dailymotion progress bar
const UI_ProgressBar = true;
// [&] full-width title bar icon
// [ REQUIRE: UI_FullTitleBar enabled ]
const UI_TitleIcon = true;
// [&] custom title bar description (default "Currently Playing:")
// [ REQUIRE: UI_FullTitleBar enabled ]
const UI_TitleBarDescription = true;
// [&] chat message after user joining
const UI_JoinText = true;
// [&] additional commands in the chat window
const UI_UserCommands = true;
// [&] special signs/avatars before every message for defined users
const UI_UserMarks = true;
// automatic squavatars (2-colored square avatars) before every message
const UI_Squavatars = false;
// [&] custom mark after username (default ":")
// [ REQUIRE: UI_UserMarks enabled ]
const UI_UsernameMark = true;
// [&] text added to random chat messages
const UI_MessagesSuffix = false;
// [&] custom sound for chat notifications
const UI_CustomPingSound = true;
// [&] chat sounds played after sending certain words
const UI_SoundFilters = false;
// text speaking after '!say' and '!mow' commands (english and polish)
const UI_ChatSpeak = false;
// [&] additional settings-independent emotes
const UI_IndependentEmotes = true;
// [&] additional settings-independent filters
const UI_IndependentFilters = true;
// button displaying box with clickable chat fonts
const UI_FontsBtn = true;
// [&] additional buttons in the fonts panel with unicode characters
// [ REQUIRE: INSTALLATION (see above) ]
const UI_UnicodeChars = false;
// button displaying box with clickable chat emotes
// [ REQUIRE: UI_FontsBtn enabled ]
const UI_EmotesBtn = false;
// [&] emotes panel pagination, display limited number of emotes at one time
const UI_GroupEmotes = false;
// button displaying modal window with chat commands help
// [ REQUIRE: UI_EmotesBtn enabled ]
const UI_CommandsBtn = true;
// [&] panel with messages and help for moderators
const UI_ModPanel = true;
// [&] custom captions for add, refresh, voteskip buttons, and welcome text
const UI_CustomCaptions = false;
// [&] additional player options
const UI_PlayerOptions = true;
// player transformation buttons
const UI_TransformationBtns = false;
// [&] box with embed additional media database
export const UI_ChannelDatabase = true;
// [&] box with embed galleries
const UI_ChannelGalleries = false;
// selector with player display modes
const UI_DisplayModeSel = true;
// [&] additional default channel theme
const UI_ChannelTheme = false;
// [&] possibility to embedding (displaying) images and .webm videos on the chat
const UI_EmbeddingMedia = true;
// embedded video preloaded controls
const UI_MediaControls = true;
// buttons with '/clear' and '/afk' functions
// [ REQUIRE: UI_EmbeddingMedia enabled ]
const UI_QuickCommandsBtns = true;
// additional volume buttons for YouTube player
const UI_VolumeBtns = true;
// [&] random background image for empty playlist row corner
const UI_EmptyCornerBackground = true;
// extended 'Get URLs' function
const UI_ExtendedGetURLs = true;
// default unchecking "Add as temporary" checkbox after loading for registered users
const UI_DefaultNonTemp = false;
// [&] custom channel footer
const UI_CustomFooter = false;
// [&] right-sided footer box
const UI_CustomRightFooter = false;
// displaying in the footer user visits number and current online time
const UI_UserStatistics = true;
// caching script emotes, additional media database and default gallery
const UI_ChannelCache = true;
// adds context menu with links
const UI_ContextMenu = true;
// adds easter egg
const UI_PartyButton = false;
// adds version
const UI_Version = true;
// adds hey and nay
const UI_RateButtons = true;
// moves emote list button
const UI_SpecialEmoteBtn = true;
// adds public voteskipping
const UI_PublicSkip = true;
// adds "add" test to help new users
const UI_ButtonIcons = true;
// adds snow (just an attempt on adding, i dont rly know how to make it work)
const UI_Snow = false;
// adds emoji to chat
const twemojiStuff = false;
// /////////////////////////////////////////////////////////////////////////////////////////////////
/* ----- DETAILED BASIC CONFIGURATION ----- */
// NOTES:
// a) values for 'MOTDAutoLogo_Mode': 1 = first logo; 2 = random logo; 3 = logo
// rotation; 7 = weekdays logos b) in 'SoundFilters_Array' use .ogg or .wav
// files, some browsers has problems with embedded .mp3 c) in 'ModPanel_Array'
// item leave empty first (username) field to make a message to all moderators
// d) in 'EmbeddingMedia_Images' and 'EmbeddingMedia_Videos' you can define
// acceptable file extensions
// use CSS syntax: e.g. 'a[href$=""]' defines acceptable end of an URL (file
// extension) you can also define URL fragments: 'a[href*=""]', or add
// excluding clause: '.not(\'a[href*=""]\'), etc.
/* -- single variables -- */
// TODO: Move all these into a file.
const Favicon_URL = 'https://cdn.7tv.app/emote/63997f8225d903e933e7b93b/1x.webp';
const MiniLogo_URL = 'https://cdn.7tv.app/emote/63997f8225d903e933e7b93b/1x.webp';
const ChannelName_Caption = 'CyDJ';
export const Version_Now = 'CyDJEdge7.20.24.0';
const HeaderDropMenu_Title = 'Information';
const MOTDAutoLogo_Mode = 1;
const MOTDAutoLogo_Interval = 20;
const RulesBtn_Caption = 'Read Channel Rules';
const AttentionBar_URL =
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/letmedofuck.png';
const ChannelAnnouncement_Title = 'CyDJ Alert';
const TitleIcon_URL = 'https://cdn.7tv.app/emote/62881948adc5e81118c9c42e/2x.webp';
const TitleBarDescription_Caption = 'Now Playing:';
const JoinText_Message = 'hello!';
const UsernameMark_Char = '';
const MessagesSuffix_Text = '~xD';
const MessagesSuffix_Percentage = 10;
const CustomPingSound_URL = 'https://github.com/ItMePeachy/PeachyRoom/raw/master/misc/squeak.mp3';
const PlayerHiding_URL = 'https://c.tenor.com/Q6UjBrnSzvQAAAAC/anime-uh.gif';
const GroupEmotes_Number = 100;
const Snow_URL = 'https://dl.dropboxusercontent.com/s/cvxizo3lax3xlrg/snowcss.css';
const HeaderDropMenu_Array = [
['CyDJ Rooms', ''],
['Main Room', 'https://cytu.be/r/cydj'],
['Second Room', 'https://cytu.be/r/secretfbimeeting'],
['Baked Live Room', 'https://baked.live/tv/cydj'],
['Test Room', 'https://cytu.be/r/testplacelilroc'],
['Test Room 2', 'https://cytu.be/r/emptyroomtestplace'],
['Test Room 3', 'https://cytu.be/r/xqcPeepo'],
['Experiments', 'https://cytu.be/r/cydjrewrite'],
['Community Related', ''],
['CyDJ Discord', 'https://discord.gg/g8tCGSc2bx'],
['Camellia Discord', 'https://discord.gg/camellia'],
['Credits', ''],
[
'CyTube FAQ',
'https://github.com/calzoneman/sync/wiki/Beginner%27s-Guide-and-FAQ',
],
['CyTube Source', 'https://github.com/calzoneman/sync'],
['CyDJ Source', 'https://github.com/papertek/CyDJ'],
['CyDJ Bot Source', 'https://github.com/airforce270/CytubeBot'],
];
const MOTDAutoLogo_Array = [
'https://github.com/papertek/CyDJ/raw/beta/images/cydjnormal.jpg',
];
const MOTDTabs_Array = [
['Home', 'Welcome to CyDJ!'],
['Playlist', 'Playlist tab.<br /><br />We watched this, that and this.'],
[
'Schedule',
'Schedule:<br /><br /><ul><li>Monday: ...</li><li>Tuesday: ...</li><li>Wendesday: ...</li><li>Thursday: ...</li><li>Friday: ...</li><li>Saturday: ...</li><li>Sunday: ...</li></ul>',
],
['Contact', 'Contact:<br /><br />Email - ...<br />Skype - ...'],
];
const SoundFilters_Array = {
'oh no our table': 'https://github.com/papertek/CyDJ/raw/beta/misc/ohnoourtable.wav',
'our table': 'https://github.com/papertek/CyDJ/raw/beta/misc/ohnoourtable.wav',
};
const ModPanel_Array = [
[
'',
'<h4>Access to user reports <em><a href="https://docs.google.com/spreadsheets/d/1oZ6pNneah7VpkYyZ6JEPCdWH-RW9toImmMNU0002ab4/edit#gid=1081291779" target="_blank">here</a>.</em></h4>',
],
[
'',
'<h4>Access to bot commands <em><a href="https://github.com/airforce270/cytubebot#commands" target="_blank">here</a>.</em></h4>',
],
['', 'To ban someone type <code>/ban (user)</code>'],
['', 'To kick someone type <code>/kick (user)</code>'],
[
'',
'To IpBan someone type <code>/ipban (user)</code> (Use this when dealing with alts!)',
],
[
'',
'To shadow mute someone type <code>/smute (user)</code> (This allows them to keep on talking without disturbing other people)',
],
['', 'To mute someone type <code>/mute (user)</code>'],
['', 'To unmute someone type <code>/unmute (user)</code>'],
['', 'To clear chat type <code>/clear</code>'],
['', 'To remove a users queue type <code>/clean (user)</code>'],
[
'',
'To remove specific titles in the queue type <code>/cleantitle (title)</code>',
],
[
'',
'To kick anons type <code>/kickanons</code> (only useful when people dont have a guest account)',
],
[
'',
'To ban a specific range of ips type <code>/ipban (user) range (reason)</code>',
],
[
'',
'The same as above but an even more wider area of ips <code>/ipban (user) wrange (reason)</code>',
],
[
'',
'Drinks! <code>/d (message)</code> ~ Drinks are just an asthetic for you or other people',
],
[
'',
'Numbered Drinks usage <code>/d{number} (message)</code> ~ A number specific type of drink command',
],
['', 'Big scary text <code>/say (message)</code>'],
['', 'Poll command <code>/poll {title},{option1},{option2},...</code>'],
[
'',
'Poll command (but hides poll results) <code>/hpoll {title},{option1},{option2},...</code>',
],
[
'',
'To temporary insert to the playlist any website instead of media files, click "Embed a custom frame" button in the playlist controls section. Then paste example code to the textarea: <code><i><iframe src="URL_of_your_page"></iframe></i></code>, and add.',
],
];
const CustomCaptions_Array = {
'add': 'Add',
'refresh': 'Refresh',
'voteskip': 'Skip',
'welcome': 'Hi',
};
const UnicodeChars_Array = [
'★', '☆', '▲', '▼', '♥', '♪', '♿', '⚒', '♕', '✉', '☏', '♠', '→',
'☑', '☒', '✡', '☪', '✝', '☭', '☯', 'Ⓐ', '☕', '♨', '¥', '©', '∞',
];
const ChannelGalleries_Array = [
['Anime pictures', 'http://imgur.com/a/SjwJb/embed'],
['Historical photos', 'http://imgur.com/a/vnwC2/embed'],
];
/* -- HTML/CSS -- */
const MOTDTabs_CSS = {
'padding': '20px',
'color': 'white',
'background-color': 'black',
};
const RulesBtn_HTML =
'<ol><li>You want to write on the chat? Enter temporary nickname into <b>Guest Login</b> input and click enter.</li><li>You want to register a nick? Click <b>Account -> Profile</b> on the top of the channel, and fill the registration form. You don\'t need an email to register.</li><li>Troll skipping = immediate kick.</li><li>Don\'t be annoying.</li><li>Do not one man spam.</li><li>Do not encourage chat wars or harass/target people.</li><li>Queueing blatant NSFW videos such as porn/hentai/gore is strictly not allowed, doing so will result in an ip ban.</li><li>Queuing the same video but in different link variants is not allowed.</li><li>Mods have the right to skip a video if its overplayed.</li><li><b>These rules are subject to common sense.</b></li></ol>';
const ChannelAnnouncement_HTML =
'Please join the <a href="https://discord.gg/g8tCGSc2bx" target="_blank">Discord</a> for news regarding CyDJ.';
const EmbeddingMedia_Images =
'a[href$=".jpg"], a[href$=".jpg:large"], a[href$=".jpeg"], a[href$=".JPEG"], a[href$=".JPG"], a[href$=".png"], a[href$=".PNG"], a[href$=".tiff"], a[href$=".TIFF"], a[href$=".webp"], a[href$=".WEBP"], a[href$=".gif"], a[href$=".GIF"]';
const EmbeddingMedia_Videos =
'a[href$=".webm"], a[href$=".mp4"], a[href$=".MP4"], a[href$=".mov"], a[href$=".MOV"], a[href$=".mp3"], a[href$=".MP3"], a[href$=".wav"], a[href$=".WAV"], a[href$=".ogg"], a[href$=".OGG"], a[href$=".m4a"], a[href$=".M4A"]';
const CustomFooter_HTML = 'This is custom footer.';
const CustomRightFooter_HTML = '';
// /////////////////////////////////////////////////////////////////////////////////////////////////
/* ----- THEMES CONFIGURATION ----- */
const ChannelThemeURL = 'https://papertek.github.io/CyDJ/deploy/beta/css/DJDefault.css';
const ThemesCSS = [
[
'Dark Mode (red)',
'https://papertek.github.io/CyDJ/deploy/beta/css/RedDarkMode.css',
],
[
'Classic',
'https://papertek.github.io/CyDJ/deploy/beta/css/twitchclassic.css',
],
[
'Old DJ',
'https://papertek.github.io/CyDJ/deploy/beta/css/OldDJ.css',
],
[
'Stars',
'https://papertek.github.io/CyDJ/deploy/beta/css/stars.css',
],
[
'Black Cat',
'https://papertek.github.io/CyDJ/deploy/beta/css/blackcat.css',
],
[
'U.U.F.O',
'https://papertek.github.io/CyDJ/deploy/beta/css/UUFO.css',
],
];
const EmptyCornerBackground = [
/* 'https://static-cdn.jtvnw.net/emoticons/v2/emotesv2_a054f4001b6d4f098e7969c988debd18/default/light/2.0',
'https://cdn.betterttv.net/emote/5dfc5d868608fb0da4120b59/2x',
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/main/891194776798498826%20(1).gif',
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/main/small.png',
'https://cdn.7tv.app/emote/60d2c62291b6751bc1e05add/4x.webp',
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/main/JohnJamSmall.gif',
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/main/mud.png',
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/main/xso.png',
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/main/pacific.gif',
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/main/pushing%20ass.png', */
];
// /////////////////////////////////////////////////////////////////////////////////////////////////
/* ----- INDEPENDENT EMOTES AND FILTERS CONFIGURATION ----- */
// NOTES ABOUT INDEPENDENT EMOTES:
// Every item has 4 attributes, respectively: chat code, image URL, image width,
// image height. Warning: due to conflict with RegExp, do not use square
// brackets or use proper "\\[" and "\\]" codes.
const IndependentEmotes = [
[
':awesome:',
'https://dl.dropboxusercontent.com/s/gz1k8oto90n16v6/awesome.png',
35,
35,
],
[
':love:',
'https://dl.dropboxusercontent.com/s/fr9131zgnai0kix/heart.png',
35,
35,
],
[
':skeet:',
'https://raw.githubusercontent.com/papertek/CyDJ/beta/images/main/skeet.gif',
35,
35,
],
];
// NOTES AND DEFAULT FILTERS EXAMPLES:
// If you use regular expression, you must put it between // signs with /g flag to change all
// occurences:
//
// a) [mq]text[/mq] - fast scrolling text
// b) [mq0]text[/mq0] - slow scrolling text
// c) [imgur]suok1xr.jpg[/imgur] - imgur picture
// d) [drop]7mrz85gl29eiiks/logo.png[/drop] - dropbox picture
// e) [minus/i5]ig0qs6fvWvgBu.jpg[/minus] - minus.com picture
// f) [vi/b]1r8ih4t1.vichan.png[/vi] - vichan /b/ imageboard picture (you can use other boards too)
const IndependentFilters = [
{
before: /\[mq\](.*?)\[\/mq\]/g,
after: '<marquee scrollamount="10" behavior="scroll">$1</marquee>',
},
{
before: /\[mq0\](.*?)\[\/(mq0|mq)\]/g,
after: '<marquee scrollamount="5" behavior="alternate">$1</marquee>',
},
{
before: /\[mqp\](.*?)\[\/(mqp|mq)\]/g,
after: '<marquee scrollamount="10" behavior="alternate">$1</marquee>',
},
{
before: /\[mqr\](.*?)\[\/(mqr|mq)\]/g,
after: '<marquee scrollamount="20" behavior="alternate">$1</marquee>',
},
{
before: /\[mqk\](.*?)\[\/(mqk|mq)\]/g,
after: '<marquee scrollamount="30" behavior="alternate">$1</marquee>',
},
{
before: /\[imgur\](.*?)\[\/(i|imgur)\]/g,
after:
'<a href="http://i.imgur.com/$1" target="_blank"><img src="http://i.imgur.com/$1" style="max-width:160px"></a>',
},
{
before: /\[drop\](.*?)\[\/(d|drop)\]/g,
after: '<a href="https://dl.dropboxusercontent.com/s/$1" target="_blank">' +
'<img src="https://dl.dropboxusercontent.com/s/$1" style="max-width:160px"></a>',
},
{
before: /\[minus\/(.*?)\](.*?)\[\/(m|minus)\]/g,
after: '<a href="http://$1.minus.com/$2" target="_blank">' +
'<img src="http://$1.minus.com/$2" style="max-width:160px"></a>',
},
{
before: /\[vi\/(.*?)\](.*?)\[\/(v|vi)\]/g,
after: '<a href="https://pl.vichan.net/$1/src/$2" target="_blank">' +
'<img src="https://pl.vichan.net/$1/src/$2" style="max-width:160px"></a>',
},
];
// /////////////////////////////////////////////////////////////////////////////////////////////////
/* ----- END OF CONFIGURATION, DO NOT CHANGE ANYTHING BELOW ----- */
/* ----- Initial channel options ----- */
// /////////////////////////////////////////////////////////////////////////////////////////////////
// reload script after unexpected re-connection or script URL change
let /** @type {boolean} */ LOADED = 'LOADED' in window;
if (LOADED) {
location.reload();
}
/* ----- getting and setting channel options ----- */
const defplayer = UI_DefaultSynchtube ? 'left' : 'right';
const defuserlist = UI_DefaultSynchtube ? 'right' : 'left';
const defqueue = UI_DefaultSynchtube ? 'left' : 'right';
const DEFTHEME =
(UI_ChannelTheme && ChannelThemeURL !== '') ? ChannelThemeURL : '/css/themes/slate.css';
const USERCONFIG = {
'player': getOrDefault(CHANNEL.name + '_player', defplayer),
'userlist': getOrDefault(CHANNEL.name + '_userlist', defuserlist),
'queue': getOrDefault(CHANNEL.name + '_queue', defqueue),
'qsize': getOrDefault(CHANNEL.name + '_qsize', 'wide'),
'main': getOrDefault(CHANNEL.name + '_main', 'top'),
'motd': getOrDefault(CHANNEL.name + '_motd', 'top'),
'logo': getOrDefault(CHANNEL.name + '_logo', 'no'),
'logourl': getOrDefault(CHANNEL.name + '_logourl', ''),
'logoht': getOrDefault(CHANNEL.name + '_logoht', 250),
'header': getOrDefault(CHANNEL.name + '_header', 'detached'),
'css': getOrDefault(CHANNEL.name + '_css', 'no'),
'csscode': getOrDefault(CHANNEL.name + '_csscode', ''),
'modhash': getOrDefault(CHANNEL.name + '_modhash', ''),
};
let USERTHEME = getOrDefault(CHANNEL.name + '_theme', DEFTHEME);
let FLUID = getOrDefault(CHANNEL.name + '_fluid', false);
let LAYOUTBOX = getOrDefault(CHANNEL.name + '_layoutbox', true);
let SOUNDSLVL = getOrDefault(CHANNEL.name + '_soundslvl', 3);
let EMBEDIMG = getOrDefault(CHANNEL.name + '_embedimg', true);
let EMBEDVID = getOrDefault(CHANNEL.name + '_embedvid', true);
let AUTOVID = getOrDefault(CHANNEL.name + '_autovid', true);
let USERVISITS = getOrDefault(CHANNEL.name + '_visits', 0);
// standard item description in the player header
let DEFDESCR = true;
// admin chat functions panel visibility
let CHATFUNC = true;
// additional command occuring in the chat message
let COMMAND = false;
// chat sounds not disabled by user
let VOICES = false;
// emotes have been loaded into emotes panel
let EMOTES = false;
// auto clearing messages window
let CLEARING = false;
// enabled anti-AFK function
let ANTIAFK = false;
// chat sounds panel visibility
let SOUNDSPANEL = false;
// playlist pinned to player
let PINNED = false;
// expanded playlist view
let FULLPL = false;
// minimized layout
let MINIMIZED = false;
// channel database has been loaded
let CHANDB = false;
// channel galleries have been loaded
let GALLERY = false;
// channel galleries have been viewed by user
let GALLVIS = false;
// using altered 'formatChatMessage' built-in function
let ALTERCHATFORMAT = true;
// previous read of a current item time for the progress bar
let PREVTIME = 0;
// timestamp of the last adding random item from the channel database
let LASTADD = 1;
// user minutes online
let USERONLINE = 0;
// number of background changes for the drop it
let DROPBGCHANGE = 1;
// list of users with muted chat sounds by user
const MUTEDVOICES = [];
// array of links added from channel database by user
const ADDEDLINKS = [];
const WEBKIT = 'webkitRequestAnimationFrame' in window;
const SOUNDSVALUES = [0, 0.1, 0.2, 0.4, 0.7, 1];
const SPEAKLINK = 'http://webanywhere.cs.washington.edu/cgi-bin/espeak/getsound.pl';
const DROPIT = new Audio('https://github.com/papertek/CyDJ/raw/beta/misc/dropit.wav');
const HEY = new Audio('https://github.com/papertek/CyDJ/raw/master/misc/hey.wav');
const NAY = new Audio('https://github.com/ItMePeachy/PeachyRoom/raw/beta/misc/scream.mp3');
CHATSOUND.volume = 0.4;
function preloadAudio() {
const audioButtons = document.querySelectorAll('button[data-type=\'audio\']');
for (const audioButton of audioButtons) {
const preloader = new Audio();
// use bind to link the audio button to the function
preloader.addEventListener('loadeddata', enableAudioButton.bind(audioButton), true);
// trigger the download
preloader.src = audioButton.getAttribute('data-url');
}
}
document.body.addEventListener('load', preloadAudio, true);
window.onload = preloadAudio();
// /////////////////////////////////////////////////////////////////////////////////////////////////
/* ----- Global functions ----- */
// /////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Toggle elements visibility.
*
* @param {JQuery<HTMLElement>} div
*/
function toggleDiv(div) {
if ($(div).css('display') === 'none') {
$(div).show();
} else {
$(div).hide();
}
}
/**
* Refresh player.
*/
function refreshPlayer() {
// PLAYER.type = '';
// PLAYER.id = '';
socket.emit('playerReady');
}
/**
* Add link to playlist.
*
* @param {string} link
* @param {string} stand
*/
function addToPlaylist(link, stand) {
const parsed = parseMediaLink(link);
if (parsed['id'] != null) {
socket.emit(
'queue',
{id: parsed['id'], pos: stand, type: parsed['type'], temp: $('.add-temp').prop('checked')});
}
}
// /**
// * Get text content from inner HTML.
// *
// * @param {string} html
// * @return {string}
// */
// function getText(html) {
// const div = document.createElement('div');
// div.innerHTML = html;
// return div.textContent || div.innerText;
// }
let modalOuter;
let modalDialog;
let modalContent;
let modalHead;
let modalBody;
let modalFooter;
/**
* Create modal window.
*
* @param {string} title
*/
function createModal(title) {
modalOuter = $('<div class="modal fade" />').appendTo($('body'));
modalDialog = $('<div class="modal-dialog" />').appendTo(modalOuter);
modalContent = $('<div class="modal-content" />').appendTo(modalDialog);
modalHead = $('<div class="modal-header" />').appendTo(modalContent);
$('<button class="close" data-dismiss="modal" aria-hidden="true" />')
.html('×')
.appendTo(modalHead);
$('<h3 />').text(title).appendTo(modalHead);
modalBody = $('<div class="modal-body" />').appendTo(modalContent);
modalFooter = $('<div class="modal-footer" />').appendTo(modalContent);
modalOuter.on('hidden', () => {
outer.remove();
unhidePlayer();
});
modalOuter.modal();
}
/**
* Layout elements settings.
*
* @param {string} a
*/
function playerLocation(a) {
$('#pinup-btn').show();
if (a === 'left') {
$('#videowrap').after($('#chatwrap').detach());
normalPlayer();
normalChat();
setTimeout(refreshPlayer(), 1000);
} else if (a === 'right') {
$('#videowrap').before($('#chatwrap').detach());
normalPlayer();
normalChat();
setTimeout(refreshPlayer(), 1000);
} else if (a === 'center') {
$('#videowrap').after($('#chatwrap').detach());
$('#videowrap, #chatwrap').removeClass().addClass('col-lg-8 col-lg-offset-2 col-md-12');
fitPlayer();
fitChat(200);
$('#pinup-btn').hide();
setTimeout(refreshPlayer(), 1000);
}
}
function userlistLocation(a) {
if (a === 'left') {
$('#userlist').css('float', 'left');
} else {
$('#userlist').css('float', 'right');
}
}
function queueLocation(a) {
$('#pinup-btn').show();
if (a === 'right') {
$('#rightpane').before($('#leftpane').detach());
} else if (a === 'left') {
$('#rightpane').after($('#leftpane').detach());
} else if (a === 'center') {
$('#rightpane')
.after($('#leftpane').detach())
.removeClass()
.addClass('col-md-8 col-md-offset-2 col-md-12');
$('#leftpane').removeClass().addClass('col-md-8 col-md-offset-2 col-md-12');
$('#pinup-btn').hide();
}
const b = (a === 'right') ? 'left' : 'right';
$('#playlistrow').css('background-position', b + ' bottom');
}
function queueSize(a) {
if (USERCONFIG.queue !== 'center') {
if (a === 'wide') {
$('#leftpane').removeClass().addClass('col-lg-5 col-md-5');
$('#rightpane').removeClass().addClass('col-lg-7 col-md-7');
} else if (a === 'narrow') {
$('#leftpane').removeClass().addClass('col-lg-7 col-md-7');
$('#rightpane').removeClass().addClass('col-lg-5 col-md-5');
}
}
}
function mainLocation(a) {
if (a === 'top') {
$('#main').before($('#titlerow').detach()).after($('#playlistrow').detach());
} else if (a === 'bottom') {
$('#main').before($('#playlistrow').detach()).before($('#titlerow').detach());
}
$('#main').after($('#chatpanel').detach());
}
function motdLocation(a) {
if (a === 'top') {
$('#zerorow').after($('#announcements').detach()).after($('#motdrow').detach());
} else if (a === 'bottom') {
$('#resizewrap').before($('#motdrow').detach()).before($('#announcements').detach());
}
}
/** @param {string} logo */
function logoInsert(logo) {
if (logo !== 'no') {
const link = (logo !== 'user') ? LOGOS.get(logo).url : USERCONFIG.logourl;
const height = (logo !== 'user') ? LOGOS.get(logo).height : USERCONFIG.logoht;
azukirow.css({
'min-height': `${height}px`,
'background-image': `url("${link}")`,
});
} else if (logo === 'no') {
azukirow.css({
'min-height': '5px',
'background-image': '',
});
}
}
function headerMode(a) {
$('.navbar-fixed-top').unbind();
if (a === 'fixed') {
$('.navbar-fixed-top').css({'position': 'fixed', 'top': '0px'});
$('#mainpage').css('margin-top', '0px');
} else if (a === 'detached') {
$('.navbar-fixed-top').css('position', 'inherit');
$('#mainpage').css('margin-top', '-72px');
} else if (a === 'mouseover') {
$('.navbar-fixed-top')
.css({'position': 'fixed', 'top': '-40px'})
.on('mouseover', () => $('.navbar-fixed-top').css('top', '0px'))
.on('mouseout', () => $('.navbar-fixed-top').css('top', '-40px'));
$('#mainpage').css('margin-top', '-40px');
}
}
function customCSS(a) {
$('#usercss').remove();
if (a === 'yes') {
$('head').append(`<style id="usercss" type="text/css">${USERCONFIG.csscode}</style>`);
}
}
/**
* Set global layout according to user preferences.
*/
function setLayout() {
playerLocation(USERCONFIG.player);
userlistLocation(USERCONFIG.userlist);
queueLocation(USERCONFIG.queue);
queueSize(USERCONFIG.qsize);
mainLocation(USERCONFIG.main);
motdLocation(USERCONFIG.motd);
logoInsert(USERCONFIG.logo);
headerMode(USERCONFIG.header);
customCSS(USERCONFIG.css);
}
/**
* Fit player height.
*/
function fitPlayer() {
const videoWidth = $('#videowrap').width();
const videoHeight = Math.floor(parseInt(videoWidth) * 9 / 16 + 1);
$('#ytapiplayer').width(videoWidth).height(videoHeight);
}
/**
* Fit chat height.
*
* @param {string} a
*/
function fitChat(a) {
let VH;
if (a === 'auto') {
const VW = $('#messagebuffer').width();
VH = Math.floor(parseInt(VW) * 9 / 16 + 1);
} else {
VH = a;
}
$('#messagebuffer').height(VH);
$('#userlist').height(VH);
}
// display mode helper functions
function bigPlayer() {
$('#videowrap').removeClass().addClass('col-lg-12 col-md-12');
fitPlayer();
}
function bigChat() {
$('#chatwrap').removeClass().addClass('col-lg-12 col-md-12');
fitChat('auto');
}
function normalPlayer() {
$('#videowrap').removeClass().addClass('col-lg-7 col-md-7');
fitPlayer();
}
function normalChat() {
const c = (PINNED && USERCONFIG.qsize === 'wide') ? 'col-lg-7 col-md-7' : 'col-lg-5 col-md-5';
$('#chatwrap').removeClass().addClass(c);
fitChat(338);
}
/**
* Set display mode.
*
* @param {string} a
*/
function setMode(a) {
$('#main').show();
pinupbtn.hide();
modesel.find('option[value=\'chMode\'], option[value=\'rMode\']').show();
if (PINNED) {
modesel.find('option[value=\'chMode\']').hide();
}
if (a === 'syMode') {
$('#videowrap, #videowrap p, #videowrap div, #chatwrap, #rightpane, #pinup-btn').show();
$('#config-btn, #configbtnwrap br, #pinup-btn').show();
$('#min-layout').parent().show();
normalPlayer();
const c = (PINNED && USERCONFIG.qsize === 'wide') ? 'col-lg-7 col-md-7' : 'col-lg-5 col-md-5';
$('#chatwrap').removeClass().addClass(c);
const VW = $('#messagebuffer').width();
const VH = Math.floor(parseInt(VW) * 9 / 16 + 1);
const H = parseInt(VH) - $('#chatline').outerHeight() - 1;
$('#messagebuffer').height(H);
$('#userlist').height(H);
if (USERCONFIG.player === 'center') {
playerLocation('center');
}
if (PINNED) {
pinUp();
}
} else if (a === 'kMode') {
$('#videowrap').show();
if (PINNED) {
$('#rightpane').hide();
} else {
$('#chatwrap').hide();
}
$('#fontspanel, #emotespanel').hide();
bigPlayer();
} else if (a === 'chMode') {
$('#chatwrap').show();
if (WEBKIT) {
$('#videowrap').hide();
} else {
$('#videowrap div, #videowrap p').hide();
$('#ytapiplayer').width(1).height(1);
}
bigChat();
} else if (a === 'rMode') {
if (WEBKIT) {
$('#main').hide();
} else {
if (PINNED) {
$('#rightpane').hide();
} else {
$('#chatwrap').hide();
}
$('#videowrap div, #videowrap p').hide();
$('#ytapiplayer').width(1).height(1);
}
if (!PINNED) {
$('#min-layout').parent().show();
}
}
}
/**
* Fix layout after changing media.
*/
function setModeAfterVideoChange() {
const m = modesel.val();
if (m === 'syMode' || m === 'chMode' || m === 'rMode') {
setMode(m);
}
}
/**
* Change welcome text.
*/
function changeWelcomeText() {
if (CLIENT.rank > 0) {
$('#welcome').html($('#welcome').html().replace(/Welcome/, CustomCaptions_Array['welcome']));
}
}
/**
* Set MOTD.
*/