forked from DubPlus/DubPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdubplus.js
3730 lines (2993 loc) · 116 KB
/
dubplus.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
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";
var _waitFor = _interopRequireDefault(require("./utils/waitFor.js"));
var _preload = _interopRequireDefault(require("./utils/preload.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
/$$$$$$$ /$$
| $$__ $$ | $$ /$$
| $$ \ $$ /$$ /$$| $$$$$$$ | $$
| $$ | $$| $$ | $$| $$__ $$ /$$$$$$$$
| $$ | $$| $$ | $$| $$ \ $$|__ $$__/
| $$ | $$| $$ | $$| $$ | $$ | $$
| $$$$$$$/| $$$$$$/| $$$$$$$/ |__/
|_______/ \______/ |_______/
https://github.com/DubPlus/DubPlus
MIT License
Copyright (c) 2017 DubPlus
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 of 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.
*/
var modal = require('./utils/modal.js');
var init = require('./lib/init.js');
var css = require('./utils/css.js');
function errorModal(errorMsg) {
// probably should make a modal with inline styles
// or a smaller css file with just modal styles so
// we're not loading the whole css for just a modal
css.load('/css/dubplus.css');
modal.create({
title: 'Dub+ Error',
content: errorMsg
});
}
/* globals Dubtrack */
if (!window.dubplus) {
(0, _preload.default)(); // checking to see if these items exist before initializing the script
// instead of just picking an arbitrary setTimeout and hoping for the best
var checkList = ['QueUp.session.id', 'QueUp.room.chat', 'QueUp.Events', 'QueUp.room.player', 'QueUp.helpers.cookie', 'QueUp.room.model', 'QueUp.room.users'];
var _dubplusWaiting = new _waitFor.default(checkList, {
seconds: 10
}); // 10sec should be more than enough
_dubplusWaiting.then(function () {
init();
$('.dubplus-waiting').remove();
}).fail(function () {
if (!QueUp.session.id) {
errorModal('You\'re not logged in. Please login to use Dub+.');
} else {
$('.dubplus-waiting span').text('Something happed, refresh and try again');
}
});
} else {
if (!QueUp.session.id) {
errorModal('You\'re not logged in. Please login to use Dub+.');
} else {
errorModal('Dub+ is already loaded');
}
}
},{"./lib/init.js":4,"./utils/css.js":40,"./utils/modal.js":42,"./utils/preload.js":46,"./utils/waitFor.js":47}],2:[function(require,module,exports){
"use strict";
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/* global emojify */
var GetJSON = require('../utils/getJSON.js');
var settings = require("../lib/settings.js"); // IndexedDB wrapper for increased quota compared to localstorage (5mb to 50mb)
!function () {
function e(t, o) {
return n ? void (n.transaction("s").objectStore("s").get(t).onsuccess = function (e) {
var t = e.target.result && e.target.result.v || null;
o(t);
}) : void setTimeout(function () {
e(t, o);
}, 100);
}
var t = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
if (!t) return void console.error("indexDB not supported");
var n,
o = {
k: "",
v: ""
},
r = t.open("d2", 1);
r.onsuccess = function (e) {
n = this.result;
}, r.onerror = function (e) {
console.error("indexedDB request error"), console.log(e);
}, r.onupgradeneeded = function (e) {
n = null;
var t = e.target.result.createObjectStore("s", {
keyPath: "k"
});
t.transaction.oncomplete = function (e) {
n = e.target.db;
};
}, window.ldb = {
get: e,
set: function set(e, t) {
o.k = e, o.v = t, n.transaction("s", "readwrite").objectStore("s").put(o);
}
};
}();
var prepEmoji = {};
prepEmoji.emoji = {
template: function template(id) {
return emojify.defaultConfig.img_dir + '/' + encodeURI(id) + '.png';
}
};
prepEmoji.twitch = {
template: function template(id) {
return "//static-cdn.jtvnw.net/emoticons/v1/" + id + "/3.0";
},
specialEmotes: [],
emotes: {},
chatRegex: new RegExp(":([-_a-z0-9]+):", "ig")
};
prepEmoji.bttv = {
template: function template(id) {
return "//cdn.betterttv.net/emote/" + id + "/3x";
},
emotes: {},
chatRegex: new RegExp(":([&!()\\-_a-z0-9]+):", "ig")
};
prepEmoji.tasty = {
template: function template(id) {
return this.emotes[id].url;
},
emotes: {}
};
prepEmoji.frankerFacez = {
template: function template(id) {
return "//cdn.frankerfacez.com/emoticon/" + id + "/1";
},
emotes: {},
chatRegex: new RegExp(":([-_a-z0-9]+):", "ig")
};
prepEmoji.shouldUpdateAPIs = function (apiName, callback) {
var day = 86400000; // milliseconds in a day
// if api return an object with an error then we should try again
ldb.get(apiName + '_api', function (savedItem) {
if (savedItem) {
var parsed = JSON.parse(savedItem);
if (typeof parsed.error !== 'undefined') {
callback(true);
}
}
var today = Date.now();
var lastSaved = parseInt(localStorage.getItem(apiName + '_api_timestamp')); // Is the lastsaved not a number for some strange reason, then we should update
// are we past 5 days from last update? then we should update
// does the data not exist in localStorage, then we should update
callback(isNaN(lastSaved) || today - lastSaved > day * 5 || !savedItem);
});
};
/**************************************************************************
* Loads the twitch emotes from the api.
* http://api.twitch.tv/kraken/chat/emoticon_images
*/
prepEmoji.loadTwitchEmotes = function () {
var savedData; // if it doesn't exist in localStorage or it's older than 5 days
// grab it from the twitch API
this.shouldUpdateAPIs('twitch', function (update) {
if (update) {
console.log('dub+', 'twitch', 'loading from api');
var twApi = new GetJSON('//cdn.jsdelivr.net/gh/Jiiks/BetterDiscordApp/data/emotedata_twitch_global.json', 'twitch:loaded');
twApi.done(function (data) {
var json = JSON.parse(data);
var twitchEmotes = {};
for (var emote in json.emotes) {
if (!twitchEmotes[emote]) {
// if emote doesn't exist, add it
twitchEmotes[emote] = json.emotes[emote].image_id;
}
}
localStorage.setItem('twitch_api_timestamp', Date.now().toString());
ldb.set('twitch_api', JSON.stringify(twitchEmotes));
prepEmoji.processTwitchEmotes(twitchEmotes);
});
} else {
ldb.get('twitch_api', function (data) {
console.log('dub+', 'twitch', 'loading from IndexedDB');
savedData = JSON.parse(data);
prepEmoji.processTwitchEmotes(savedData);
savedData = null; // clear the var from memory
var twEvent = new Event('twitch:loaded');
window.dispatchEvent(twEvent);
});
}
});
};
prepEmoji.loadBTTVEmotes = function () {
var savedData; // if it doesn't exist in localStorage or it's older than 5 days
// grab it from the bttv API
this.shouldUpdateAPIs('bttv', function (update) {
if (update) {
console.log('dub+', 'bttv', 'loading from api');
var bttvApi = new GetJSON('//api.betterttv.net/3/cached/emotes/global', 'bttv:loaded');
bttvApi.done(function (data) {
var json = JSON.parse(data);
var bttvEmotes = {};
json.forEach(function (e) {
if (!bttvEmotes[e.code]) {
// if emote doesn't exist, add it
bttvEmotes[e.code] = e.id;
}
});
localStorage.setItem('bttv_api_timestamp', Date.now().toString());
ldb.set('bttv_api', JSON.stringify(bttvEmotes));
prepEmoji.processBTTVEmotes(bttvEmotes);
});
} else {
ldb.get('bttv_api', function (data) {
console.log('dub+', 'bttv', 'loading from IndexedDB');
savedData = JSON.parse(data);
prepEmoji.processBTTVEmotes(savedData);
savedData = null; // clear the var from memory
var twEvent = new Event('bttv:loaded');
window.dispatchEvent(twEvent);
});
}
});
};
prepEmoji.loadTastyEmotes = function () {
var _this = this;
console.log('dub+', 'tasty', 'loading from api'); // since we control this API we should always have it load from remote
var tastyApi = new GetJSON(settings.srcRoot + '/emotes/tastyemotes.json', 'tasty:loaded');
tastyApi.done(function (data) {
ldb.set('tasty_api', JSON.stringify(data));
_this.processTastyEmotes(JSON.parse(data));
});
};
prepEmoji.loadFrankerFacez = function () {
var savedData; // if it doesn't exist in localStorage or it's older than 5 days
// grab it from the frankerfacez API
this.shouldUpdateAPIs('frankerfacez', function (update) {
if (update) {
console.log('dub+', 'frankerfacez', 'loading from api');
var frankerFacezApi = new GetJSON('//api.frankerfacez.com/v1/emoticons?per_page=200&private=off&sort=count-desc', 'frankerfacez:loaded');
frankerFacezApi.done(function (data) {
var frankerFacez = JSON.parse(data);
localStorage.setItem('frankerfacez_api_timestamp', Date.now().toString());
ldb.set('frankerfacez_api', data);
prepEmoji.processFrankerFacez(frankerFacez);
});
} else {
ldb.get('frankerfacez_api', function (data) {
console.log('dub+', 'frankerfacez', 'loading from IndexedDB');
savedData = JSON.parse(data);
prepEmoji.processFrankerFacez(savedData);
savedData = null; // clear the var from memory
var twEvent = new Event('frankerfacez:loaded');
window.dispatchEvent(twEvent);
});
}
});
};
prepEmoji.processTwitchEmotes = function (data) {
for (var code in data) {
if (data.hasOwnProperty(code)) {
var _key = code.toLowerCase(); // move twitch non-named emojis to their own array
if (code.indexOf('\\') >= 0) {
this.twitch.specialEmotes.push([code, data[code]]);
continue;
}
if (emojify.emojiNames.indexOf(_key) >= 0) {
continue; // do nothing so we don't override emoji
}
if (!this.twitch.emotes[_key]) {
// if emote doesn't exist, add it
this.twitch.emotes[_key] = data[code];
}
}
}
this.twitchJSONSLoaded = true;
this.emojiEmotes = emojify.emojiNames.concat(Object.keys(this.twitch.emotes));
};
prepEmoji.processBTTVEmotes = function (data) {
for (var code in data) {
if (data.hasOwnProperty(code)) {
var _key = code.toLowerCase();
if (code.indexOf(':') >= 0) {
continue; // don't want any emotes with smileys and stuff
}
if (emojify.emojiNames.indexOf(_key) >= 0) {
continue; // do nothing so we don't override emoji
}
if (code.indexOf('(') >= 0) {
_key = _key.replace(/([()])/g, "");
}
this.bttv.emotes[_key] = data[code];
}
}
this.bttvJSONSLoaded = true;
this.emojiEmotes = this.emojiEmotes.concat(Object.keys(this.bttv.emotes));
};
prepEmoji.processTastyEmotes = function (data) {
this.tasty.emotes = data.emotes;
this.tastyJSONLoaded = true;
this.emojiEmotes = this.emojiEmotes.concat(Object.keys(this.tasty.emotes));
};
prepEmoji.processFrankerFacez = function (data) {
var _iterator = _createForOfIteratorHelper(data.emoticons),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var emoticon = _step.value;
var code = emoticon.name;
var _key = code.toLowerCase().replace('~', '-');
if (code.indexOf(':') >= 0) {
continue; // don't want any emotes with smileys and stuff
}
if (emojify.emojiNames.indexOf(_key) >= 0) {
continue; // do nothing so we don't override emoji
}
if (code.indexOf('(') >= 0) {
_key = _key.replace(/([()])/g, "");
}
this.frankerFacez.emotes[_key] = emoticon.id;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
this.frankerfacezJSONLoaded = true;
this.emojiEmotes = this.emojiEmotes.concat(Object.keys(this.frankerFacez.emotes));
};
module.exports = prepEmoji;
},{"../lib/settings.js":8,"../utils/getJSON.js":41}],3:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.makeList = exports.PreviewListManager = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var debugAC = false;
function log() {
if (debugAC) {
console.log.apply(console, arguments);
}
}
/**
* Populates the popup container with a list of items that you can click/enter
* on to autocomplete items in the chat box
* @param {Array} acArray the array of items to be added. Each item is an object:
* {
* src : full image src,
* text : text for auto completion,
* cn : css class name for to be concat with '-preview',
* alt : OPTIONAL, to add to alt and title tag
* }
*/
var makeList = function makeList(acArray) {
function makePreviewContainer(cn) {
var d = document.createElement('li');
d.className = cn;
return d;
}
function makeImg(src, altText) {
var i = document.createElement('img');
i.src = src;
if (altText) {
i.title = altText;
i.alt = altText;
}
var div = document.createElement('div');
div.className = "ac-image";
div.appendChild(i);
return div;
}
function makeNameSpan(name) {
var s = document.createElement('span');
s.textContent = name;
s.className = "ac-text"; // autocomplete text
return s;
}
function makeEnterSpan() {
var s = document.createElement('span');
s.textContent = 'press enter to select';
s.className = "ac-list-press-enter"; // autocomplete text
return s;
}
function makeLi(info, i) {
var container = makePreviewContainer("preview-item " + info.cn + "-previews");
var span = makeNameSpan(info.text);
var img;
if (info.alt) {
img = makeImg(info.src, info.alt);
} else {
img = makeImg(info.src);
}
container.appendChild(img);
container.appendChild(span);
if (i === 0) {
container.appendChild(makeEnterSpan());
container.classList.add('selected');
}
container.tabIndex = -1;
return container;
}
var aCp = document.getElementById('autocomplete-preview');
aCp.innerHTML = "";
var frag = document.createDocumentFragment();
acArray.forEach(function (val, i) {
frag.appendChild(makeLi(val, i));
});
aCp.appendChild(frag);
aCp.classList.add('ac-show');
};
exports.makeList = makeList;
function isElementInView(el, container) {
var rect = el.getBoundingClientRect();
var outerRect = container.getBoundingClientRect();
return rect.top >= outerRect.top && rect.bottom <= outerRect.bottom;
}
/**
* previewList
*
* In this JS file should only exist what's necessary to populate the
* autocomplete preview list that popups up for emojis and mentions
*
* It also binds the events that handle navigating through the list
* and also placing selected text into the chat
*/
var PreviewListManager = /*#__PURE__*/function () {
function PreviewListManager(data) {
_classCallCheck(this, PreviewListManager);
this._data = data || {
start: 0,
end: 0,
selected: ""
};
}
_createClass(PreviewListManager, [{
key: "data",
get: function get() {
return this._data;
},
set: function set(newData) {
if (newData) {
this._data = newData;
}
}
}, {
key: "selected",
set: function set(text) {
if (text) {
this._data.selected = text;
}
}
}, {
key: "repl",
value: function repl(str, start, end, newtext) {
return str.substring(0, start - 1) + newtext + str.substring(end);
}
}, {
key: "updateChatInput",
value: function updateChatInput() {
log("inUpdate", this._data);
var inputText = $("#chat-txt-message").val();
var updatedText = this.repl(inputText, this._data.start, this._data.end, this._data.selected) + " ";
$('#autocomplete-preview').empty().removeClass('ac-show');
$("#chat-txt-message").val(updatedText).focus();
}
}, {
key: "doNavigate",
value: function doNavigate(diff) {
// get the current index of selected element within the nodelist collection of previews
var displayBoxIndex = $('.preview-item.selected').index(); // calculate new index position with given argument
displayBoxIndex += diff;
var oBoxCollection = $(".ac-show li"); // remove "press enter to select" span
$('.ac-list-press-enter').remove(); // if new index is greater than total length then we reset back to the top
if (displayBoxIndex >= oBoxCollection.length) {
displayBoxIndex = 0;
} // if at the top and index becomes negative, we wrap down to end of array
if (displayBoxIndex < 0) {
displayBoxIndex = oBoxCollection.length - 1;
}
var cssClass = "selected";
var enterToSelectSpan = '<span class="ac-list-press-enter">press enter or tab to select</span>';
oBoxCollection.removeClass(cssClass).eq(displayBoxIndex).addClass(cssClass).append(enterToSelectSpan);
var pvItem = document.querySelector('.preview-item.selected');
var acPreview = document.querySelector('#autocomplete-preview');
var isInView = isElementInView(pvItem, acPreview);
log("isInView", isInView);
var align = diff === 1 ? false : true;
if (!isInView) {
pvItem.scrollIntoView(align);
}
}
}, {
key: "updater",
value: function updater(e) {
log(e.target, e);
this._data.selected = $(e.target).find('.ac-text').text();
this.updateChatInput();
}
}, {
key: "init",
value: function init() {
var _this = this;
var acUL = document.createElement('ul');
acUL.id = "autocomplete-preview";
$('.pusher-chat-widget-input').prepend(acUL);
$(document.body).on('click', '.preview-item', function (e) {
return _this.updater(e);
});
}
}, {
key: "stop",
value: function stop() {
// the garbade collector should clean up the event listener added in init
$('#autocomplete-preview').remove();
}
}]);
return PreviewListManager;
}();
exports.PreviewListManager = PreviewListManager;
},{}],4:[function(require,module,exports){
(function (PKGINFO){(function (){
"use strict";
var _loadModules = _interopRequireDefault(require("./loadModules.js"));
var _snooze = _interopRequireDefault(require("../modules/snooze.js"));
var _eta = _interopRequireDefault(require("../modules/eta.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var css = require('../utils/css.js');
var menu = require('./menu.js');
module.exports = function () {
window.dubplus = JSON.parse(PKGINFO); // load our main CSS
css.load('/css/dubplus.css'); // add a 'global' css class just in case we need more specificity in our css
$('html').addClass('dubplus'); // Get the opening html for the menu
var menuString = menu.beginMenu(); // load all our modules into the 'dubplus' global object
// it also builds the menu dynamically
// returns an object to be passed to menu.finish
var menuObj = (0, _loadModules.default)(); // finalize the menu and add it to the UI
menu.finishMenu(menuObj, menuString); // run non-menu related items here:
(0, _snooze.default)();
(0, _eta.default)();
};
}).call(this)}).call(this,'{"name":"DubPlus","version":"0.3.2","description":"Dub+ - A simple script/extension for Dubtrack.fm and QueUp.net","author":"DubPlus","license":"MIT","homepage":"https://dub.plus","browserslist":["> 1%","last 2 versions"]}')
},{"../modules/eta.js":22,"../modules/snooze.js":34,"../utils/css.js":40,"./loadModules.js":5,"./menu.js":7}],5:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var options = require('../utils/options.js');
var dubPlus_modules = require('../modules/index.js');
var settings = require("../lib/settings.js");
var menu = require('../lib/menu.js');
var menuObj = {
'General': '',
'User Interface': '',
'Settings': '',
'Customize': ''
};
/**
* Loads all the modules and initliazes them
*/
var loadAllModules = function loadAllModules() {
// window.dubplus was created in the init module
dubPlus_modules.forEach(function (mod) {
// add each module to the new global object
window.dubplus[mod.id] = mod; // add the toggleAndSave function as a member of each module
window.dubplus[mod.id].toggleAndSave = options.toggleAndSave; // check stored settings for module's initial state
mod.optionState = settings.options[mod.id] || false; // This is run only once, when the script is loaded.
// put anything you want ALWAYS run on Dub+ script load here
if (typeof mod.init === 'function') {
mod.init.call(mod);
} // if module's localStorage option state is ON, we turn it on!
if (mod.optionState && typeof mod.turnOn === 'function') {
mod.turnOn.call(mod);
}
var _extraIcon = null; // if module has a defined .extra {function} but does not define the .extraIcon {string}
// then we use 'pencil' as the default icon
if (typeof mod.extra === 'function' && !mod.extraIcon) {
_extraIcon = 'pencil';
} // generate the html for the menu option and add it to the
// appropriate category
menuObj[mod.category] += menu.makeOptionMenu(mod.moduleName, {
id: mod.id,
desc: mod.description,
state: mod.optionState,
extraIcon: mod.extraIcon || _extraIcon,
cssClass: mod.menuCssClass || '',
altIcon: mod.altIcon || null
});
});
return menuObj;
};
var _default = loadAllModules;
exports.default = _default;
},{"../lib/menu.js":7,"../lib/settings.js":8,"../modules/index.js":29,"../utils/options.js":45}],6:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var options = require('../utils/options.js');
/**
* Handles the toggling of the menu sections
* @param {Element} currentSection The pure DOM element of menu header
* @return {undefined}
*/
var toggleMenuSection = function toggleMenuSection(currentSection) {
var menuSec = currentSection.nextElementSibling;
var icon = currentSection.children[0];
var menuName = currentSection.textContent.trim().replace(" ", "-").toLowerCase();
var closedClass = 'dubplus-menu-section-closed';
var isClosed = $(menuSec).toggleClass(closedClass).hasClass(closedClass);
if (isClosed) {
// menu is closed
$(icon).removeClass('fa-angle-down');
$(icon).addClass('fa-angle-right');
options.saveOption('menu', menuName, 'closed');
} else {
// menu is open
$(icon).removeClass('fa-angle-right');
$(icon).addClass('fa-angle-down');
options.saveOption('menu', menuName, 'open');
}
};
/**
* Traverses up the dubplus menu DOM tree until it finds a match to a corresponding function
* @param {Element} target DOM Element
* @return {Object} our module or null
*/
var traverseMenuDOM = function traverseMenuDOM(target) {
// if we've reached the dubplus-menu container then we've gone too far
if (!target || $(target).hasClass('dubplus-menu')) {
return null;
} // to handle the opening/closings of our sections
if ($(target).hasClass('dubplus-menu-section-header')) {
toggleMenuSection(target);
return null;
} // check if a module exists matching current ID
var module = window.dubplus[target.id];
if (!module) {
// recursively try until we get a hit or reach our menu container
return traverseMenuDOM(target.parentElement);
} else {
return module;
}
};
/**
* Click event handler for the whole menu, delegating events to their proper function
* @param {object} ev the click event object
* @return {undefined}
*/
var menuDelegator = function menuDelegator(ev) {
var mod = traverseMenuDOM(ev.target);
if (!mod) {
return;
} // if clicking on the "extra-icon", run module's "extra" function
if ($(ev.target).hasClass('extra-icon') && mod.extra) {
mod.extra.call(mod);
return;
}
if (mod.turnOn && mod.turnOff) {
var newOptionState;
if (!mod.optionState) {
newOptionState = true;
mod.turnOn.call(mod);
} else {
newOptionState = false;
mod.turnOff.call(mod);
}
mod.optionState = newOptionState;
options.toggleAndSave(mod.id, newOptionState);
return;
}
if (mod.go) {
// .go is used for modules that never save state, like fullscreen
mod.go.call(mod);
}
};
var _default = function _default() {
var dpMenu = document.querySelector('.dubplus-menu'); // add event listener to the main menu and delegate
dpMenu.addEventListener('click', menuDelegator); // hide/show the menu when you click on the icon in the top right
document.querySelector('.dubplus-icon').addEventListener('click', function () {
$(dpMenu).toggleClass('dubplus-menu-open');
});
};
exports.default = _default;
},{"../utils/options.js":45}],7:[function(require,module,exports){
'use strict';
var _menuEvents = _interopRequireDefault(require("./menu-events.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var settings = require('./settings.js');
var css = require('../utils/css.js');
// this is used to set the state of the contact menu section
var arrow = "down";
var isClosedClass = "";
if (settings.menu.contact === "closed") {
isClosedClass = "dubplus-menu-section-closed";
arrow = "right";
} // the contact section is hardcoded and setup up here
var contactSection = "\n <div id=\"dubplus-contact\" class=\"dubplus-menu-section-header\">\n <span class=\"fa fa-angle-".concat(arrow, "\"></span>\n <p>Contact</p>\n </div>\n <ul class=\"dubplus-menu-section ").concat(isClosedClass, "\">\n <li class=\"dubplus-menu-icon\">\n <span class=\"fa fa-bug\"></span>\n <a href=\"https://discord.gg/XUkG3Qy\" class=\"dubplus-menu-label\" target=\"_blank\">Report bugs on Discord</a>\n </li>\n <li class=\"dubplus-menu-icon\">\n <span class=\"fa fa-reddit-alien\"></span>\n <a href=\"https://www.reddit.com/r/DubPlus/\" class=\"dubplus-menu-label\" target=\"_blank\">Reddit</a>\n </li>\n <li class=\"dubplus-menu-icon\">\n <span class=\"fa fa-facebook\"></span>\n <a href=\"https://facebook.com/DubPlusScript\" class=\"dubplus-menu-label\" target=\"_blank\">Facebook</a>\n </li>\n <li class=\"dubplus-menu-icon\">\n <span class=\"fa fa-twitter\"></span>\n <a href=\"https://twitter.com/DubPlusScript\" class=\"dubplus-menu-label\" target=\"_blank\">Twitter</a>\n </li>\n </ul>");
module.exports = {
beginMenu: function beginMenu() {
// load font-awesome icons from CDN to be used in the menu
css.loadExternal('https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'); // add icon to the upper right corner
var menuIcon = "<div class=\"dubplus-icon\"><img src=\"".concat(settings.srcRoot, "/images/dubplus.svg\" alt=\"\"></div>");
document.querySelector('.header-right-navigation').insertAdjacentHTML('beforeend', menuIcon); // make the menu
var dp_menu_html = "\n <section class=\"dubplus-menu\">\n <p class=\"dubplus-menu-header\">Dub+ Options</p>";
return dp_menu_html;
},
finishMenu: function finishMenu(menuObj, menuString) {
// dynamically create our menu from strings provided by each module
for (var category in menuObj) {
var fixed = category.replace(" ", "-").toLowerCase();
var menuSettings = settings.menu[fixed];
var id = 'dubplus-' + fixed;
var arrow = "down";
var isClosedClass = "";
if (menuSettings === "closed") {
isClosedClass = "dubplus-menu-section-closed";
arrow = "right";
}
menuString += "\n <div id=\"".concat(id, "\" class=\"dubplus-menu-section-header\">\n <span class=\"fa fa-angle-").concat(arrow, "\"></span>\n <p>").concat(category, "</p>\n </div>\n <ul class=\"dubplus-menu-section ").concat(isClosedClass, "\">");
menuString += menuObj[category];
menuString += '</ul>';
} // contact section last, is already fully formed, not dynamic
menuString += contactSection; // final part of the menu string
menuString += '</section>'; // add it to the DOM
document.body.insertAdjacentHTML('beforeend', menuString); // initialize our click event delegator
(0, _menuEvents.default)();
},
makeOptionMenu: function makeOptionMenu(menuTitle, options) {
var defaults = {
id: '',
// will be the ID selector for the menu item
desc: '',
// will be used for the "title" attribute
state: false,
// whether the menu item is on/off
extraIcon: null,
// define the extra icon if an option needs it (like AFK, Custom Mentions)
cssClass: '',
// adds extra CSS class(es) if desired,
altIcon: null // use a font-awesome icon instead of the switch
};
var opts = Object.assign({}, defaults, options);
var _extra = '';
var _state = opts.state ? 'dubplus-switch-on' : '';
if (opts.extraIcon) {
_extra = "<span class=\"fa fa-".concat(opts.extraIcon, " extra-icon\"></span>");
} // default icon on the left of each menu item is the switch
var mainCssClass = "dubplus-switch";
var mainIcon = "\n <div class=\"dubplus-switch-bg\">\n <div class=\"dubplus-switcher\"></div>\n </div>"; // however, if an "altIcon" is provided, then we use that instead
if (opts.altIcon) {
mainCssClass = "dubplus-menu-icon";
mainIcon = "<span class=\"fa fa-".concat(opts.altIcon, "\"></span>");
}
return "\n <li id=\"".concat(opts.id, "\" class=\"").concat(mainCssClass, " ").concat(_state, " ").concat(opts.cssClass, " title=\"").concat(opts.desc, "\">\n ").concat(_extra, "\n ").concat(mainIcon, "\n <span class=\"dubplus-menu-label\">").concat(menuTitle, "</span>\n </li>");
}
};
},{"../utils/css.js":40,"./menu-events.js":6,"./settings.js":8}],8:[function(require,module,exports){
(function (_RESOURCE_SRC_){(function (){
"use strict";
var defaults = {
// this will store all the on/off states
options: {},
// this will store the open/close state of the menu sections
menu: {
"general": "open",
"user-interface": "open",
"settings": "open",
"customize": "open",
"contact": "open"
},
// this will store custom strings for options like custom css, afk message, etc
custom: {}
};
var savedSettings = {};
var _storageRaw = localStorage.getItem('dubplusUserSettings');
if (_storageRaw) {
savedSettings = JSON.parse(_storageRaw);
}
var exportSettings = $.extend({}, defaults, savedSettings); // this is stored in localStorage but we don't want that, we always want it fresh
exportSettings.srcRoot = _RESOURCE_SRC_;
module.exports = exportSettings;
}).call(this)}).call(this,'https://cdn.jsdelivr.net/gh/DubPlus/DubPlus')
},{}],9:[function(require,module,exports){
"use strict";