forked from MCherrey/DubX-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeta.js
executable file
·2254 lines (2076 loc) · 109 KB
/
beta.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 Q PUBLIC LICENSE version 1.0
Copyright (C) 1999-2005 Trolltech AS, Norway.
Everyone is permitted to copy and distribute this license document.
The intent of this license is to establish freedom to share and change the software regulated by this license under the open source model.
This license applies to any software containing a notice placed by the copyright holder saying that it may be distributed under the terms of the Q Public License version 1.0. Such software is herein referred to as the Software. This license covers modification and distribution of the Software, use of third-party application programs based on the Software, and development of free software which uses the Software.
Granted Rights
1. You are granted the non-exclusive rights set forth in this license provided you agree to and comply with any and all conditions in this license. Whole or partial distribution of the Software, or software items that link with the Software, in any form signifies acceptance of this license.
2. You may copy and distribute the Software in unmodified form provided that the entire package, including - but not restricted to - copyright, trademark notices and disclaimers, as released by the initial developer of the Software, is distributed.
3. You may make modifications to the Software and distribute your modifications, in a form that is separate from the Software, such as patches. The following restrictions apply to modifications:
a. Modifications must not alter or remove any copyright notices in the Software.
b. When modifications to the Software are released under this license, a non-exclusive royalty-free right is granted to the initial developer of the Software to distribute your modification in future versions of the Software provided such versions remain available under these terms in addition to any other license(s) of the initial developer.
4. You may distribute machine-executable forms of the Software or machine-executable forms of modified versions of the Software, provided that you meet these restrictions:
a. You must include this license document in the distribution.
b. You must ensure that all recipients of the machine-executable forms are also able to receive the complete machine-readable source code to the distributed Software, including all modifications, without any charge beyond the costs of data transfer, and place prominent notices in the distribution explaining this.
c. You must ensure that all modifications included in the machine-executable forms are available under the terms of this license.
5. You may use the original or modified versions of the Software to compile, link and run application programs legally developed by you or by others.
6. You may develop application programs, reusable components and other software items that link with the original or modified versions of the Software. These items, when distributed, are subject to the following requirements:
a. You must ensure that all recipients of machine-executable forms of these items are also able to receive and use the complete machine-readable source code to the items without any charge beyond the costs of data transfer.
b. You must explicitly license all recipients of your items to use and re-distribute original and modified versions of the items in both machine-executable and source code forms. The recipients must be able to do so without any charges whatsoever, and they must be able to re-distribute to anyone they choose.
c. If the items are not available to the general public, and the initial developer of the Software requests a copy of the items, then you must supply one.
Limitations of Liability
In no event shall the initial developers or copyright holders be liable for any damages whatsoever, including - but not restricted to - lost revenue or profits or other direct, indirect, special, incidental or consequential damages, even if they have been advised of the possibility of such damages, except to the extent invariable law, if any, provides otherwise.
No Warranty
The Software and this license document are provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Choice of Law
This license is governed by the Laws of Norway. Disputes shall be settled by Oslo City Court.
*/ /* global Dubtrack, emojify, _ */
var hello_run;
if (!hello_run && Dubtrack.session.id) {
hello_run = true;
var our_version = '03.05.10 - New Theme BetterDubtrack';
//Ref 1: Variables
var options = {
let_autovote: false,
let_split_chat: false,
let_fs: false,
let_medium_disable: false,
let_warn_redirect: false,
let_afk: false,
let_active_afk: true,
let_chat_window: false,
let_css: false,
let_hide_avatars: false,
let_nicole: false,
let_betterDubtrack: false,
let_show_timestamps: false,
let_video_window: false,
let_twitch_emotes: false,
let_emoji_preview: false,
let_spacebar_mute: false,
let_autocomplete_mentions: false,
let_mention_notifications: false,
let_downdub_chat_notifications: false,
let_updub_chat_notifications: false,
let_grab_chat_notifications: false,
let_dubs_hover: false,
let_custom_mentions: false,
let_snow: false,
draw_general: false,
draw_userinterface: false,
draw_settings: false,
draw_customize: false,
draw_contact: false,
draw_social: false,
draw_chrome: false
};
$('html').addClass('dubx');
//Ref 1.1
$('.player_sharing').append('<span class="icon-history eta_tooltip_t" onmouseover="hello.eta();" onmouseout="hello.hide_eta();"></span>');
$('.player_sharing').append('<span class="icon-mute snooze_btn" onclick="hello.snooze();" onmouseover="hello.snooze_tooltip();" onmouseout="hello.hide_snooze_tooltip();"></span>');
$('.icon-mute.snooze_btn:after').css({"content": "1", "vertical-align": "top", "font-size": "0.75rem", "font-weight": "700"});
//Ref 2: Options
var hello = {
gitRoot: 'https://rawgit.com/sinfulBA/DubX-Script/master',
//Ref 2.1: Initialize
personalize: function() {
$('.isUser').text(Dubtrack.session.get('username'));
},
slide: function() {
$('.for_content').slideToggle('fast');
},
//Ref 2.2: Initialize
initialize: function() {
var li = '<div class="for" onclick="hello.slide();"><img src="'+hello.gitRoot+'/params/params.svg" alt=""></div>';
var html = [
'<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css">',
'<link rel="stylesheet" type="text/css" href="'+hello.gitRoot+'/css/asset.css">',
'<div class="for_content" style="display:none;">',
'<span class="for_content_ver">DubX Settings</span>',
'<span class="for_content_version" onclick="hello.drawAll();" title="Collapse/Expand Menus">'+our_version+'</span>',
'<ul class="for_content_ul">',
'<li class="for_content_li" onclick="hello.drawSection(this)">',
'<p class="for_content_c">',
'General',
'<i class="fi-minus"></i>',
'</p>',
'</li>',
'<ul class="draw_general">',
'<li onclick="hello.snow();" class="for_content_li for_content_feature snow">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Snow</p>',
'</li>',
'<li onclick="hello.autovote();" class="for_content_li for_content_feature autovote">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Autovote</p>',
'</li>',
'<li onclick="hello.afk(event);" class="for_content_li for_content_feature afk">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p onclick="hello.createAfkMessage();" class="for_content_edit" style="display: inline-block;color: #878c8e;font-size: .85rem;font-weight: bold;float: right;"><i class="fi-pencil"></i></p>',
'<p class="for_content_p">AFK Autorespond</p>',
'</li>',
'<li onclick="hello.optionTwitchEmotes();" class="for_content_li for_content_feature twitch_emotes">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Emotes</p>',
'</li>',
'<li onclick="hello.optionEmojiPreview();" class="for_content_li for_content_feature emoji_preview">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Autocomplete Emoji</p>',
'</li>',
'<li onclick="hello.optionMentions();" class="for_content_li for_content_feature autocomplete_mentions">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">DubX Autocomplete Mentions</p>',
'</li>',
'<li onclick="hello.customMentions(event);" class="for_content_li for_content_feature custom_mentions">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p onclick="hello.createCustomMentions();" class="for_content_edit" style="display: inline-block;color: #878c8e;font-size: .85rem;font-weight: bold;float: right;"><i class="fi-pencil"></i></p>',
'<p class="for_content_p">Custom Mention Triggers</p>',
'</li>',
'<li onclick="hello.mentionNotifications();" class="for_content_li for_content_feature mention_notifications">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Notification on Mentions</p>',
'</li>',
'<li onclick="hello.grabInfoWarning(); hello.showDubsOnHover();" class="for_content_li for_content_feature dubs_hover">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Show Dub info on Hover</p>',
'</li>',
'<li onclick="hello.downdubChat();" class="for_content_li for_content_feature downdub_chat">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Downdubs in Chat (Mod Only)</p>',
'</li>',
'<li onclick="hello.updubChat();" class="for_content_li for_content_feature updub_chat">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Updubs in Chat</p>',
'</li>',
'<li onclick="hello.grabChat();" class="for_content_li for_content_feature grab_chat">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Grabs in Chat</p>',
'</li>',
'</ul>',
'<li class="for_content_li" onclick="hello.drawSection(this)">',
'<p class="for_content_c">',
'User Interface',
'<i class="fi-minus"></i>',
'</p>',
'</li>',
'<ul class="draw_userinterface">',
'<li onclick="hello.fs();" class="for_content_li for_content_feature fs">',
'<p class="for_content_off"><i class="fi-arrows-out"></i></p>',
'<p class="for_content_p">Fullscreen Video</p>',
'</li>',
'<li onclick="hello.split_chat();" class="for_content_li for_content_feature split_chat">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Split Chat</p>',
'</li>',
'<li onclick="hello.video_window();" class="for_content_li for_content_feature video_window">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Hide Chat</p>',
'</li>',
'<li onclick="hello.chat_window();" class="for_content_li for_content_feature chat_window">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Hide Video</p>',
'</li>',
'<li onclick="hello.hide_avatars();" class="for_content_li for_content_feature hide_avatars">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Hide Avatars</p>',
'</li>',
'<li onclick="hello.medium_disable();" class="for_content_li for_content_feature medium_disable">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Hide Background</p>',
'</li>',
'</ul>',
'<li class="for_content_li" onclick="hello.drawSection(this)">',
'<p class="for_content_c">',
'Settings',
'<i class="fi-minus"></i>',
'</p>',
'</li>',
'<ul class="draw_settings">',
'<li onclick="hello.spacebar_mute();" class="for_content_li for_content_feature spacebar_mute">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Spacebar Mute</p>',
'</li>',
'<li onclick="hello.show_timestamps();" class="for_content_li for_content_feature show_timestamps">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Show Timestamps</p>',
'</li>',
'<li onclick="hello.warn_redirect();" class="for_content_li for_content_feature warn_redirect">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Warn On Navigation</p>',
'</li>',
'</ul>',
'<li class="for_content_li" onclick="hello.drawSection(this)">',
'<p class="for_content_c">',
'Customize',
'<i class="fi-minus"></i>',
'</p>',
'</li>',
'<ul class="draw_customize">',
'<li onclick="hello.nicole();" class="for_content_li for_content_feature nicole">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Plug.dj Theme</p>',
'</li>',
'<li onclick="hello.betterDubtrack();" class="for_content_li for_content_feature betterDubtrack">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">BetterDubtrack Theme</p>',
'</li>',
'<li onclick="hello.css_for_the_world();" class="for_content_li for_content_feature css">',
'<p class="for_content_off"><i class="fi-x"></i></p>',
'<p class="for_content_p">Community Theme</p>',
'</li>',
'<li onclick="hello.css_modal();" class="for_content_li for_content_feature">',
'<p class="for_content_off"><i class="fi-unlink"></i></p>',
'<p class="for_content_p">Custom CSS</p>',
'</li>',
'<li onclick="hello.medium_modal();" class="for_content_li for_content_feature">',
'<p class="for_content_off"><i class="fi-unlink"></i></p>',
'<p class="for_content_p">Custom Background</p>',
'</li>',
'</ul>',
'<li class="for_content_li" onclick="hello.drawSection(this)">',
'<p class="for_content_c">',
'Contact',
'<i class="fi-minus"></i>',
'</p>',
'</li>',
'<ul class="draw_contact">',
'<li onclick="hello.report_modal();" class="for_content_li for_content_feature report">',
'<p class="for_content_off"><i class="fi-comments"></i></p>',
'<p class="for_content_p">Bug Report</p>',
'</li>',
'</ul>',
'<li class="for_content_li" onclick="hello.drawSection(this)">',
'<p class="for_content_c">',
'Social',
'<i class="fi-minus"></i>',
'</p>',
'</li>',
'<ul class="draw_social">',
'<li class="for_content_li for_content_feature">',
'<a href="https://www.facebook.com/DubXScript" target="_blank" style="color: #878c8e;">',
'<p class="for_content_off"><i class="fi-social-facebook"></i></p>',
'<p class="for_content_p">Like Us on Facebook</p>',
'</a>',
'</li>',
'<li class="for_content_li for_content_feature">',
'<a href="https://twitter.com/DubXScript" target="_blank" style="color: #878c8e;">',
'<p class="for_content_off"><i class="fi-social-twitter"></i></p>',
'<p class="for_content_p">Follow Us on Twitter</p>',
'</a>',
'</li>',
'<li class="for_content_li for_content_feature">',
'<a href="https://github.com/sinfulBA/DubX-Script" target="_blank" style="color: #878c8e;">',
'<p class="for_content_off"><i class="fi-social-github"></i></p>',
'<p class="for_content_p">Fork Us on Github</p>',
'</a>',
'</li>',
'<li class="for_content_li for_content_feature">',
'<a href="https://dubx.net" target="_blank" style="color: #878c8e;">',
'<p class="for_content_off"><i class="fi-link"></i></p>',
'<p class="for_content_p">Our Website</p>',
'</a>',
'</li>',
'<li class="for_content_li for_content_feature">',
'<a href="https://dubx.net/donate.html" target="_blank" style="color: #878c8e;">',
'<p class="for_content_off"><i class="fi-pricetag-multiple"></i></p>',
'<p class="for_content_p">Donate</p>',
'</a>',
'</li>',
'</ul>',
'<li class="for_content_li" onclick="hello.drawSection(this)">',
'<p class="for_content_c">',
'Chrome Extension',
'<i class="fi-minus"></i>',
'</p>',
'</li>',
'<ul class="draw_chrome">',
'<li class="for_content_li for_content_feature">',
'<a href="https://chrome.google.com/webstore/detail/dubx/oceofndagjnpebjmknefoelcpcnpcedm/reviews" target="_blank" style="color: #878c8e;">',
'<p class="for_content_off"><i class="fi-like"></i></p>',
'<p class="for_content_p">Give Us a Rating</p>',
'</a>',
'</li>',
'</ul>',
'</ul>',
'</div>'
].join('');
$('.header-right-navigation').append(li);
$('body').prepend(html);
$('.for_content').perfectScrollbar();
$.getScript('https://rawgit.com/loktar00/JQuery-Snowfall/master/src/snowfall.jquery.js');
hello.dubs = {
upDubs: [],
downDubs: [],
grabs: []
};
},
sectionList: ['draw_general','draw_userinterface','draw_settings','draw_customize','draw_contact','draw_social','draw_chrome'],
drawSection: function(el) {
$(el).next('ul').slideToggle('fast');
var sectionClass = $(el).next('ul').attr('class');
var clicked = $(el).find('.for_content_c i');
if(clicked.hasClass('fi-minus')){
clicked.removeClass('fi-minus').addClass('fi-plus');
hello.option(sectionClass,'false');
options[sectionClass] = 'false';
}
else{
clicked.removeClass('fi-plus').addClass('fi-minus');
hello.option(sectionClass,'true');
options[sectionClass] = 'true';
}
},
drawAll: function() {
var allClosed = true;
for(var i = 0; i < hello.sectionList.length; i++) {
if($('.'+hello.sectionList[i]).css('display') === 'block'){
allClosed = false;
}
}
if(allClosed) {
for(var i = 0; i < hello.sectionList.length; i++) {
$('.'+hello.sectionList[i]).slideDown('fast');
$('.'+hello.sectionList[i]).prev('li').find('i').removeClass('fi-plus').addClass('fi-minus');
hello.option(hello.sectionList[i], 'true');
options[hello.sectionList[i]] = 'true';
}
}
else {
for(var i = 0; i < hello.sectionList.length; i++) {
$('.'+hello.sectionList[i]).slideUp();
$('.'+hello.sectionList[i]).prev('li').find('i').removeClass('fi-minus').addClass('fi-plus');
hello.option(hello.sectionList[i],'false');
options[hello.sectionList[i]] = 'false';
}
}
},
//Ref 2.3.1: Input
input: function(title,content,placeholder,confirm,maxlength) {
var textarea = '', confirmButton = '';
if (placeholder) {
var mx = maxlength || 999;
textarea = '<textarea class="input" type="text" placeholder="'+placeholder+'" maxlength="'+ mx +'">'+content+'</textarea>';
}
if (confirm) {
confirmButton = '<div class="'+confirm+' confirm"><p>Okay</p></div>';
}
var onErr = [
'<div class="onErr">',
'<div class="container">',
'<div class="title">',
'<h1>'+title+'</h1>',
'</div>',
'<div class="content">',
'<p>'+content+'</p>',
textarea,
'</div>',
'<div class="control">',
'<div class="cancel" onclick="hello.closeErr();">',
'<p>Cancel</p>',
'</div>',
confirmButton,
'</div>',
'</div>',
'</div>'
].join('');
$('body').prepend(onErr);
},
on: function(selector) {
$(selector + ' .for_content_off i').replaceWith('<i class="fi-check"></i>');
},
off: function(selector) {
$(selector + ' .for_content_off i').replaceWith('<i class="fi-x"></i>');
},
closeErr: function() {
$('.onErr').remove();
},
option: function(selector,value) {
localStorage.setItem(selector,value);
},
advance_vote: function() {
$('.dubup').click();
},
voteCheck: function (obj) {
if (obj.startTime < 2) {
hello.advance_vote();
}
},
snow: function() {
if (!options.let_snow) {
options.let_snow = true;
hello.option('snow','true');
hello.on('.snow');
$(document).snowfall({
round: true,
shadow: true,
flakeCount: 50,
minSize: 1,
maxSize: 5,
minSpeed: 5,
maxSpeed: 5
});
} else {
options.let_snow = false;
hello.option('snow','false');
hello.off('.snow');
$(document).snowfall('clear');
}
},
autovote: function() {
if (!options.let_autovote) {
options.let_autovote = true;
var song = Dubtrack.room.player.activeSong.get('song');
var dubCookie = Dubtrack.helpers.cookie.get('dub-' + Dubtrack.room.model.get("_id"));
var dubsong = Dubtrack.helpers.cookie.get('dub-song');
if(!Dubtrack.room || !song || song.songid !== dubsong) {
dubCookie = false;
}
//Only cast the vote if user hasn't already voted
if(!$('.dubup, .dubdown').hasClass('voted') && !dubCookie) {
hello.advance_vote();
}
hello.option('autovote','true');
hello.on('.autovote');
Dubtrack.Events.bind("realtime:room_playlist-update", hello.voteCheck);
} else {
options.let_autovote = false;
hello.option('autovote','false');
hello.off('.autovote');
Dubtrack.Events.unbind("realtime:room_playlist-update", hello.voteCheck);
}
},
split_chat: function() {
if (!options.let_split_chat) {
options.let_split_chat = true;
$('.chat-main').addClass('splitChat');
hello.option('split_chat', 'true');
hello.on('.split_chat');
} else {
options.let_split_chat = false;
$('.chat-main').removeClass('splitChat');
hello.option('split_chat','false');
hello.off('.split_chat');
}
},
eta: function() {
var time = 4;
var current_time = parseInt($('#player-controller div.left ul li.infoContainer.display-block div.currentTime span.min').text());
var booth_duration = parseInt($('.queue-position').text());
var booth_time = (booth_duration * time - time) + current_time;
if (booth_time >= 0) {
$('.eta_tooltip_t').append('<div class="eta_tooltip" style="position: absolute;font: 1rem/1.5 proxima-nova,sans-serif;display: block;left: -33px;cursor: pointer;border-radius: 1.5rem;padding: 8px 16px;background: #fff;font-weight: 700;font-size: 13.6px;text-transform: uppercase;color: #000;opacity: .8;text-align: center;z-index: 9;">ETA: '+booth_time+' minutes</div>');
} else {
$('.eta_tooltip_t').append('<div class="eta_tooltip" style="position: absolute;font: 1rem/1.5 proxima-nova,sans-serif;display: block;left: -33px;cursor: pointer;border-radius: 1.5rem;padding: 8px 16px;background: #fff;font-weight: 700;font-size: 13.6px;text-transform: uppercase;color: #000;opacity: .8;text-align: center;z-index: 9;">You\'re not in the queue</div>');
}
},
hide_eta: function() {
$('.eta_tooltip').remove();
},
snooze_tooltip: function() {
$('.snooze_btn').append('<div class="snooze_tooltip" style="position: absolute;font: 1rem/1.5 proxima-nova,sans-serif;display: block;left: -33px;cursor: pointer;border-radius: 1.5rem;padding: 8px 16px;background: #fff;font-weight: 700;font-size: 13.6px;text-transform: uppercase;color: #000;opacity: .8;text-align: center;z-index: 9;">Mute current song</div>');
},
hide_snooze_tooltip: function() {
$('.snooze_tooltip').remove();
},
report_content: function() {
var content = $('.input').val();
if(!content || content.trim(' ').length === 0) return;
var user = Dubtrack.session.get('username');
var id = Dubtrack.session.get("_id");
var href = location.href;
var woosh = [
' *Username*: '+user+' | ',
' *Identification*: '+id+' | ',
' *Location*: `'+location+'` | ',
' *Content*: '+content+' | '
].join('');
$.ajax({
type: 'POST',
url: 'https://hooks.slack.com/services/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',
data: 'payload={"username": "Incoming Bug Report", "text": "'+woosh+'", "icon_emoji": ":bug:"}',
crossDomain: true
});
$('.report').replaceWith('<li onclick="" class="for_content_li for_content_feature report"><p class="for_content_off"><i class="fi-check"></i></p><p class="for_content_p">Bug Report</p></li>');
},
report_modal: function() {
hello.input('Bug Report:','','Please only report bugs for DubX, not Dubtrack. \nBe sure to give a detailed description of the bug, and a way to replicate it, if possible.','confirm-for36','999');
$('.confirm-for36').click(hello.report_content);
$('.confirm-for36').click(hello.closeErr);
},
fs: function() {
var elem = document.querySelector('.playerElement iframe');
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
},
medium_disable: function() {
if (!options.let_medium_disable) {
options.let_medium_disable = true;
$('.backstretch').hide();
$('.medium').hide();
hello.option('medium_disable','true');
hello.on('.medium_disable');
} else {
options.let_medium_disable = false;
$('.backstretch').show();
$('.medium').show();
hello.option('medium_disable','false');
hello.off('.medium_disable');
}
},
warn_redirect: function() {
if(!options.let_warn_redirect) {
options.let_warn_redirect = true;
window.onbeforeunload = function(e) {
return '';
};
hello.option('warn_redirect','true');
hello.on('.warn_redirect');
} else {
options.let_warn_redirect = false;
window.onbeforeunload = null;
hello.option('warn_redirect','false');
hello.off('.warn_redirect');
}
},
afk_chat_respond: function(e) {
var content = e.message;
var user = Dubtrack.session.get('username');
if (content.indexOf('@'+user) >-1 && Dubtrack.session.id !== e.user.userInfo.userid) {
if (options.let_active_afk) {
if (localStorage.getItem('customAfkMessage')) {
var customAfkMessage = localStorage.getItem('customAfkMessage');
$('#chat-txt-message').val('[AFK] '+customAfkMessage);
} else {
$('#chat-txt-message').val("[AFK] I'm not here right now.");
}
Dubtrack.room.chat.sendMessage();
options.let_active_afk = false;
setTimeout(function() {
options.let_active_afk = true;
}, 180000);
}
}
},
saveAfkMessage: function() {
var customAfkMessage = $('.input').val();
hello.option('customAfkMessage', customAfkMessage);
$('.onErr').remove();
},
createAfkMessage: function() {
var current = localStorage.getItem('customAfkMessage');
hello.input('Custom AFK Message',current,'I\'m not here right now.','confirm-for315','255');
$('.confirm-for315').click(hello.saveAfkMessage);
},
afk: function(e) {
if(e.target.className === 'for_content_edit' || e.target.className === 'fi-pencil') return;
if (!options.let_afk) {
options.let_afk = true;
Dubtrack.Events.bind("realtime:chat-message", this.afk_chat_respond);
hello.on('.afk');
} else {
options.let_afk = false;
Dubtrack.Events.unbind("realtime:chat-message", this.afk_chat_respond);
hello.off('.afk');
}
},
customMentions: function(e) {
if(e && e.target && (e.target.className === 'for_content_edit' || e.target.className === 'fi-pencil')) return;
if (!options.let_custom_mentions) {
options.let_custom_mentions = true;
Dubtrack.Events.bind("realtime:chat-message", this.customMentionCheck);
hello.on('.custom_mentions');
} else {
options.let_custom_mentions = false;
Dubtrack.Events.unbind("realtime:chat-message", this.customMentionCheck);
hello.off('.custom_mentions');
}
},
customMentionCheck: function(e) {
var content = e.message.toLowerCase();
if (options.let_custom_mentions) {
if (localStorage.getItem('custom_mentions')) {
var customMentions = localStorage.getItem('custom_mentions').toLowerCase().split(',');
if(Dubtrack.session.id !== e.user.userInfo.userid && customMentions.some(function(v) { return content.indexOf(v.trim(' ')) >= 0; })){
Dubtrack.room.chat.mentionChatSound.play();
}
}
}
},
createCustomMentions: function() {
var current = localStorage.getItem('custom_mentions');
hello.input('Custom Mention Triggers (separate by comma)',current,'separate, custom triggers, by, comma, :heart:','confirm-for315','255');
$('.confirm-for315').click(hello.saveCustomMentions);
},
saveCustomMentions: function() {
var customMentions = $('.input').val();
hello.option('custom_mentions', customMentions);
$('.onErr').remove();
},
chat_window: function() {
if(!options.let_chat_window) {
options.let_chat_window = true;
$('head').append('<link class="chat_window_link" rel="stylesheet" type="text/css" href="'+hello.gitRoot+'/css/options/chat_window.css">');
hello.option('chat_window','true');
hello.on('.chat_window');
} else {
options.let_chat_window = false;
$('.chat_window_link').remove();
hello.option('chat_window','false');
hello.off('.chat_window');
}
},
css_modal: function() {
var current = localStorage.getItem('css') || "";
hello.input('CSS',current,'https://example.com/example.css','confirm-for313','999');
$('.confirm-for313').click(hello.css_import);
},
css_import: function() {
$('.css_import').remove();
var css_to_import = $('.input').val();
hello.option('css',css_to_import);
if (css_to_import && css_to_import !== '') {
$('head').append('<link class="css_import" href="'+css_to_import+'" rel="stylesheet" type="text/css">');
}
$('.onErr').remove();
},
css_run: function() {
if (localStorage.getItem('css') !== null) {
var css_to_load = localStorage.getItem('css');
$('head').append('<link class="css_import" href="'+css_to_load+'" rel="stylesheet" type="text/css">');
}
},
css_for_the_world: function() {
if (!options.let_css) {
options.let_css = true;
var location = Dubtrack.room.model.get('roomUrl');
$.ajax({
type: 'GET',
url: 'https://api.dubtrack.fm/room/'+location,
}).done(function(e) {
var content = e.data.description;
var url = content.match(/(@dubx=)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/);
if(!url) return;
var append = url[0].split('@dubx=');
$('head').append('<link class="css_world" href="'+append[1]+'" rel="stylesheet" type="text/css">');
});
hello.option('css_world','true');
hello.on('.css');
} else {
options.let_css = false;
$('.css_world').remove();
hello.option('css_world','false');
hello.off('.css');
}
},
hide_avatars: function() {
if(!options.let_hide_avatars) {
options.let_hide_avatars = true;
$('head').append('<link class="hide_avatars_link" rel="stylesheet" type="text/css" href="'+hello.gitRoot+'/css/options/hide_avatars.css">');
hello.option('hide_avatars','true');
hello.on('.hide_avatars');
} else {
options.let_hide_avatars = false;
$('.hide_avatars_link').remove();
hello.option('hide_avatars','false');
hello.off('.hide_avatars');
}
},
nicole: function() {
if (!options.let_nicole) {
options.let_nicole = true;
$('head').append('<link class="nicole_css" href="'+hello.gitRoot+'/themes/PlugTheme.css" rel="stylesheet" type="text/css">');
hello.option('nicole', 'true');
hello.on('.nicole');
} else {
options.let_nicole = false;
$('.nicole_css').remove();
hello.option('nicole','false');
hello.off('.nicole');
}
},
betterDubtrack: function() {
if (!options.let_betterDubtrack) {
options.let_betterDubtrack = true;
$('head').append('<link class="betterDubtrack_css" href="'+hello.gitRoot+'/themes/BetterDubtrack.css" rel="stylesheet" type="text/css">');
hello.option('betterDubtrack', 'true');
hello.on('.betterDubtrack');
} else {
options.let_betterDubtrack = false;
$('.betterDubtrack_css').remove();
hello.option('betterDubtrack','false');
hello.off('.betterDubtrack');
}
},
medium_modal: function() {
hello.input('Link an image file:','It is recommended a .jpg file is used','https://example.com/example.jpg','confirm-for314','999');
$('.confirm-for314').click(hello.medium_import);
},
medium_import: function() {
var content = $('.input').val();
localStorage.setItem('medium',content);
$('.medium').remove();
$('body').append('<div class="medium" style="width: 100vw;height: 100vh;z-index: -999998;position: fixed; background: url('+content+');background-size: cover;top: 0;"></div>');
$('.onErr').remove();
},
medium_load: function() {
if (localStorage.getItem('medium') !== null) {
var content = localStorage.getItem('medium');
$('body').append('<div class="medium" style="width: 100vw;height: 100vh;z-index: -999998;position: fixed; background: url('+content+');background-size: cover;top: 0;"></div>');
}
},
show_timestamps: function() {
if(!options.let_show_timestamps) {
options.let_show_timestamps = true;
$('head').append('<link class="show_timestamps_link" rel="stylesheet" type="text/css" href="'+hello.gitRoot+'/css/options/show_timestamps.css">');
hello.option('show_timestamps','true');
hello.on('.show_timestamps');
} else {
options.let_show_timestamps = false;
$('.show_timestamps_link').remove();
hello.option('show_timestamps','false');
hello.off('.show_timestamps');
}
},
video_window: function() {
if(!options.let_video_window) {
options.let_video_window = true;
$('head').append('<link class="video_window_link" rel="stylesheet" type="text/css" href="'+hello.gitRoot+'/css/options/video_window.css">');
hello.option('video_window','true');
hello.on('.video_window');
} else {
options.let_video_window = false;
$('.video_window_link').remove();
hello.option('video_window','false');
hello.off('.video_window');
}
},
// jQuery's getJSON kept returning errors so making my own with promise-like
// structure and added optional Event to fire when done so can hook in elsewhere
getJSON : (function (url, optionalEvent, headers) {
var doneEvent;
function GetJ(_url, _cb){
var xhr = new XMLHttpRequest();
xhr.open('GET', _url);
if(headers) {
for (var property in headers) {
if (headers.hasOwnProperty(property)) {
xhr.setRequestHeader(property, headers[property]);
}
}
}
xhr.send();
xhr.onload = function() {
var resp = xhr.responseText;
if (typeof _cb === 'function') { _cb(resp); }
if (optionalEvent) { document.body.dispatchEvent(doneEvent); }
};
}
if (optionalEvent){ doneEvent = new Event(optionalEvent); }
var done = function(cb){
new GetJ(url, cb);
};
return { done: done };
}),
/**
* pings for the existence of var/function for 5 seconds until found
* runs callback once found and stop pinging
* @param {variable} waitingFor Your global function, variable, etc
* @param {Function} cb Callback function
*/
whenAvailable : function(waitingFor, cb) {
var interval = 100; // ms
var currInterval = 0;
var limit = 50; // how many intervals
var check = function () {
if (waitingFor && typeof cb === "function") {
console.log("available", waitingFor);
cb();
} else if (currInterval < limit) {
currInterval++;
console.log('waiting for', waitingFor);
window.setTimeout(check, interval);
}
};
window.setTimeout(check, interval);
},
emoji : {
// example of the new emojify url
template: function(id) { return emojify.defaultConfig.img_dir+'/'+encodeURI(id)+'.png'; },
},
twitch : {
template: function(id) { return "//static-cdn.jtvnw.net/emoticons/v1/" + id + "/3.0"; },
specialEmotes: [],
emotes: {},
chatRegex : new RegExp(":([-_a-z0-9]+):", "ig")
},
bttv : {
template: function(id) { return "//cdn.betterttv.net/emote/" + id + "/3x"; },
emotes: {},
chatRegex : new RegExp(":([&!()\\-_a-z0-9]+):", "ig")
},
tasty : {
template: function(id) { return hello.tasty.emotes[id].url; },
emotes: {}
},
shouldUpdateAPIs : function(apiName){
var self = this;
var day = 86400000; // milliseconds
var today = Date.now();
var lastSaved = parseInt(localStorage.getItem(apiName+'_api_timestamp'));
return isNaN(lastSaved) || today - lastSaved > day * 5 || !localStorage[apiName +'_api'];
},
/**************************************************************************
* Loads the twitch emotes from the api.
* http://api.twitch.tv/kraken/chat/emoticon_images
*/
loadTwitchEmotes: function(){
var self = hello;
var savedData;
// if it doesn't exist in localStorage or it's older than 5 days
// grab it from the twitch API
if (self.shouldUpdateAPIs('twitch')) {
console.log('Dubx','twitch','loading from api');
var twApi = new self.getJSON('//api.twitch.tv/kraken/chat/emoticon_images', 'twitch:loaded', {'Client-ID': '5vhafslpr2yqal6715puzysmzrntmt8'});
twApi.done(function(data){
var json = JSON.parse(data);
if(json.error && json.error.length > 0) {
hello.input('Twitch Emote Error', 'There was an error loading twitch emotes. Please clear your cache and try again.', null, 'twitch-emote-info');
$('.twitch-emote-info').click(hello.closeErr);
localStorage.removeItem('twitch_api');
return;
}
localStorage.setItem('twitch_api_timestamp', Date.now().toString());
localStorage.setItem('twitch_api', data);
self.processTwitchEmotes(json);
});
} else {
console.log('Dubx','twitch','loading from localstorage');
savedData = JSON.parse(localStorage.getItem('twitch_api'));
if(savedData.error && savedData.error.length > 0) {
console.log('twitch:malformed json - reloading');
return self.loadTwitchEmotes();
}
self.processTwitchEmotes(savedData);
savedData = null; // clear the var from memory
var twEvent = new Event('twitch:loaded');
document.body.dispatchEvent(twEvent);
}
},
loadBTTVEmotes: function(){
var self = hello;
var savedData;
// if it doesn't exist in localStorage or it's older than 5 days
// grab it from the bttv API
if (self.shouldUpdateAPIs('bttv')) {
console.log('Dubx','bttv','loading from api');
var bttvApi = new self.getJSON('//api.betterttv.net/2/emotes', 'bttv:loaded');
bttvApi.done(function(data){
localStorage.setItem('bttv_api_timestamp', Date.now().toString());
localStorage.setItem('bttv_api', data);
self.processBTTVEmotes(JSON.parse(data));
});
} else {
console.log('Dubx','bttv','loading from localstorage');
savedData = JSON.parse(localStorage.getItem('bttv_api'));
self.processBTTVEmotes(savedData);
savedData = null; // clear the var from memory
var twEvent = new Event('bttv:loaded');
document.body.dispatchEvent(twEvent);
}
},
loadTastyEmotes: function(){
var self = hello;
var savedData;
console.log('Dubx','tasty','loading from api');
// since we control this API we should always have it load from remote
var tastyApi = new self.getJSON(hello.gitRoot + '/emotes/tastyemotes.json', 'tasty:loaded');
tastyApi.done(function(data){
localStorage.setItem('tasty_api', data);
self.processTastyEmotes(JSON.parse(data));
});
},
processTwitchEmotes: function(data) {
var self = hello;
data.emoticons.forEach(function(el,i,arr){
var _key = el.code.toLowerCase();
// move twitch non-named emojis to their own array
if (el.code.indexOf('\\') >= 0) {
self.twitch.specialEmotes.push([el.code, el.id]);
return;
}
if (emojify.emojiNames.indexOf(_key) >= 0) {
return; // do nothing so we don't override emoji
}
if (!self.twitch.emotes[_key]){
// if emote doesn't exist, add it
self.twitch.emotes[_key] = el.id;
} else if (!self.twitch.emotes[_key] || el.emoticon_set === null){
// if emote doesn't exist, add it
// OR override if it's a global emote (null set = global emote)
self.twitch.emotes[_key] = el.id;
}
});
self.twitchJSONSLoaded = true;
self.emojiEmotes = emojify.emojiNames.concat(Object.keys(self.twitch.emotes));
},
processBTTVEmotes: function(data){
var self = hello;
data.emotes.forEach(function(el,i,arr){
var _key = el.code.toLowerCase();
if (el.code.indexOf(':') >= 0) {
return; // don't want any emotes with smileys and stuff
}
if (emojify.emojiNames.indexOf(_key) >= 0) {
return; // do nothing so we don't override emoji
}
if (el.code.indexOf('(') >= 0) {
_key = _key.replace(/([()])/g, "");
}
self.bttv.emotes[_key] = el.id;
});
self.bttvJSONSLoaded = true;
self.emojiEmotes = self.emojiEmotes.concat(Object.keys(self.bttv.emotes));
},
processTastyEmotes: function(data) {
var self = hello;
self.tasty.emotes = data.emotes;
var tastyEmotesKeys = Object.keys(self.tasty.emotes);
tastyEmotesKeys = tastyEmotesKeys.map(function(key){
var keyLC = key.toLowerCase();
if (emojify.emojiNames.indexOf(keyLC) >= 0 || emojify.emojiNames.indexOf(key) >= 0) {
// don't want to override emojify emojis
var newKey = keyLC + '_tasty';
// add new key
self.tasty.emotes[newKey] = self.tasty.emotes[key];
// delete old key
delete self.tasty.emotes[key];
delete self.tasty.emotes[keyLC];
return newKey;
} else {
return key;
}
});