forked from teclamat/drmng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkong_ng.user.js
4861 lines (4681 loc) · 255 KB
/
kong_ng.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name DotD Raids Manager Next Gen
// @namespace tag://kongregate
// @description Makes managing raids a lot easier
// @author Mutik
// @version 2.0.24
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// @include http://www.kongregate.com/games/5thPlanetGames/dawn-of-the-dragons*
// @include *50.18.191.15/kong/?DO_NOT_SHARE_THIS_LINK*
// @connect 50.18.191.15
// @connect prnt.sc
// @hompage http://mutik.erley.org
// ==/UserScript==
//best loop atm: for(var i=0, l=obj.length; i<l; ++i) - for with caching and pre-increment
if(window.location.host == "www.kongregate.com") {
if(window.top == window.self) {
function main() {
window.DEBUG = false;
window.DRMng = {
version: {major: '2', minor: '0', rev: '24', name: 'DotD Raids Manager next gen'},
Util: {
// Sets or Destroys css Style in document head
// if 'content' is null, css with given ID is removed
cssStyle: function(id,content) {
let s = document.getElementById(id);
if (content !== null) {
if (!s) {
s = document.createElement('style');
s.setAttribute('type', 'text/css');
s.setAttribute('id', id);
document.head.appendChild(s);
}
s.innerHTML = content;
}
else if (s) s.parentNode.removeChild(s);
},
copyFields: function(src,dst,fields) {
for (let i = 0, l = fields.length; i < l; ++i)
if (src.hasOwnProperty(fields[i])) dst[fields[i]] = src[fields[i]];
return dst;
},
getQueryVariable: function(v,s) {
let query = String(s || window.location.search.substring(1));
if (query.indexOf('?') > -1) query = query.substring(query.indexOf('?') + 1);
let vars = query.split('&');
let i = vars.length;
while(i--) {
let pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == v) return decodeURIComponent(pair[1]);
}
return '';
},
crc32: function(str) {
let i, c, crcTable = [];
for (i = 0, c = i; i < 256; ++i, c = i) {
for(let k =0; k < 8; k++) c = ((c&1)?(0xEDB88320^(c>>>1)):(c>>>1));
crcTable[i] = c;
}
let crc = 0 ^ (-1);
for (i = 0; i < str.length; ++i) crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
return ((crc^(-1))>>>0).toString(16);
},
getRaidFromUrl: function(url, poster) {
let r = { createtime: new Date().getTime(), poster: poster || ''}, cnt = 0, i;
let reg = /[?&]([^=]+)=([^?&]+)/ig, p = url.replace(/&/gi, '&').replace(/kv_&/gi, '&kv_').replace(/http:?/gi, '');
while ((i = reg.exec(p)) !== null) {
switch (i[1]) {
case 'kv_raid_id': case 'raid_id': r.id = i[2]; cnt++; break;
case 'kv_difficulty': case 'difficulty':r.diff = parseInt(i[2]); cnt++; break;
case 'kv_raid_boss': case 'raid_boss': r.boss = i[2]; cnt++; break;
case 'kv_hash': case 'hash': r.hash = i[2]; cnt++; break;
case 'kv_serverid': case 'serverid': r.sid = parseInt(i[2]); break;
}
}
if (cnt < 4) return null;
r.pid = r.sid === 2 ? 0 : 1;
return r;
},
getShortNum: function(num, p) {
p = p || 4;
if (isNaN(num) || num < 0) return num;
if (num >= 1000000000000) return (num / 1000000000000).toPrecision(p) + 't';
if (num >= 1000000000) return (num / 1000000000).toPrecision(p) + 'b';
if (num >= 1000000) return (num / 1000000).toPrecision(p) + 'm';
if (num >= 1000) return (num / 1000).toPrecision(p) + 'k';
return num + ''
},
getShortNumK: function(num, p) {
p = p || 4;
if (isNaN(num) || num < 0) return num;
if (num >= 1000000000000) return (num / 1000000000000).toPrecision(p) + 'q';
if (num >= 1000000000) return (num / 1000000000).toPrecision(p) + 't';
if (num >= 1000000) return (num / 1000000).toPrecision(p) + 'b';
if (num >= 1000) return (num / 1000).toPrecision(p) + 'm';
return num.toPrecision(p) + 'k'
},
getRand: function(i) {
return Math.round(Math.random()*(i+.5));
},
deRomanize: function(roman) {
let lut = {I:1, V:5, X:10, L:50, C:100, D:500, M:1000};
let arabic = 0, i = roman.length;
while (i--) {
if (lut[roman[i]] < lut[roman[i+1]]) arabic -= lut[roman[i]];
else arabic += lut[roman[i]];
}
return arabic;
},
Gate: {
lightShot: function(link, id) {
link = link.replace(/prntscr.com/,'prnt.sc');
let data = { eventName: 'DRMng.lightShot', url: link, method: 'GET', id: id, timeout: 10000 };
DRMng.postMessage(data);
},
lightShotCb: function(e) {
let d = JSON.parse(e.data);
let i = document.getElementById(d.id);
let l = /og:image.+?content="(.+?)"/.exec(d.responseText);
if (l) {
l = l[1];
if (i) {
i.setAttribute('src', l);
i.setAttribute('alt', l);
i.removeAttribute('id');
}
}
else if (i) i.parentNode.removeChild(i);
setTimeout(DRMng.Alliance.scrollToBottom.bind(DRMng.Alliance), 10);
}
},
hResize: {
ev: null,
regPanes: [],
regSide: [],
regLeft: false,
regRight: false,
pane: null,
rect: null,
x: 0,
y: 0,
left: false,
right: false,
redraw: false,
clicked: null,
calc: function(e) {
if (this.pane === null) return false;
this.rect = this.pane.getBoundingClientRect();
this.x = e.clientX - this.rect.left;
this.left = this.regLeft && this.x < 6;
this.right = this.regRight && this.x >= this.rect.width - 6;
return true;
},
findPane: function(e) {
let p = e.target, idx;
while (p && p.nodeName !== 'BODY') {
idx = this.regPanes.indexOf(p.id);
if (idx > -1) {
this.pane = p;
if (this.regSide[idx]) {
this.regLeft = true;
this.regRight = false;
}
else {
this.regLeft = false;
this.regRight = true;
}
break;
}
p = p.parentNode;
}
},
onMouseDown: function(e) {
this.findPane(e);
if (this.calc(e)) this.onDown(e);
},
onDown: function(e) {
let isResizing = this.left || this.right;
if (isResizing) e.preventDefault();
this.clicked = {
x: this.x,
cx: e.clientX,
w: this.rect.width,
isResizing: isResizing,
left: this.left,
right: this.right
}
},
hold: false,
resetHold: function() {
this.hold = false;
},
onMove: function(e) {
if (this.hold) return;
if (this.clicked === null) {
this.findPane(e);
this.hold = true;
setTimeout(this.resetHold.bind(this),500);
}
this.onMoveProgress(e);
},
onMoveProgress: function(e) {
if(!this.calc(e)) return;
this.ev = e;
this.redraw = true;
},
onUp: function() {
if (this.pane) {
let p = this.pane;
switch(p.id) {
case 'chat_container':
let w = parseInt(p.style.width.replace('px',''));
DRMng.Config.local.kong.chatWidth =
DRMng.Config.local.alliance.sbs ? parseInt((w-7)/2) : w;
DRMng.Config.saveLocal();
DRMng.Kong.setHeaderWidth();
break;
case 'DRMng_main':
DRMng.Config.local.scriptWidth = parseInt(p.style.width.replace('px',''));
DRMng.Config.saveLocal();
break;
}
}
this.clicked = null;
this.pane = null;
},
animate: function() {
requestAnimationFrame(this.animate.bind(this));
if (!this.redraw) return;
this.redraw = false;
if (this.clicked && this.clicked.isResizing) {
if (this.clicked.right)
this.pane.style.width = parseInt(Math.max(this.x, 200)) + 'px';
if (this.clicked.left) {
this.pane.style.width =
parseInt(Math.max(this.clicked.cx - this.ev.clientX + this.clicked.w, 200)) + 'px';
}
return;
}
if (this.pane) {
if (this.right || this.left) this.pane.style.cursor = 'ew-resize';
else this.pane.style.cursor = 'default';
}
},
init: function() {
document.addEventListener('mousemove', this.onMove.bind(this));
document.addEventListener('mouseup', this.onUp.bind(this));
this.animate();
}
}
},
Gestures: {
Kiss: {
smittenAdjective: ['smitten','enamored','infatuated','taken','in love','inflamed'],
getSmittenAdjective: function() { return this.smittenAdjective[DRMng.Util.getRand(5)]; },
generate: function() {
let txt = '';
switch(DRMng.Util.getRand(8)) {
case 0: txt = '@from gives @who a puckered kiss on the lips.'; break;
case 1: txt = '@from plants a gentle kiss on the cheek of @who.'; break;
case 2: txt = '@from kisses @who... might have used tongue on that one.'; break;
case 3: case 4: txt = '@from seems ' + this.getSmittenAdjective() + ' with @who.'; break;
default: txt = '@from tickles the lips of @who with a sensual kiss.'; break;
}
return txt;
}
},
Poke: {
pokeBodyPlace: ['on the cheek', 'on the navel', 'in the nose', 'in the belly button',
'in the rib cage', 'in a really ticklish spot', 'square on the forehead',
'with a wet willy in the ear', 'on the arm', 'on the shoulder',
'on the chest', 'on the leg', 'in the face', 'on the neck', 'in the stomach',
'up the butt'],
getPokeBodyPlace: function() { return this.pokeBodyPlace[DRMng.Util.getRand(14)]; },
generate: function() {
let txt = '';
switch(DRMng.Util.getRand(6)) {
case 0: txt = '@from with a tickling finger of doom, pokes @who '; break;
case 1: txt = '@from jumps out from the shadows and prods @who '; break;
case 2: txt = '@from playfully pokes @who '; break;
case 3: txt = '@from cheerfully pokes @who '; break;
case 4: txt = '@from gleefully pokes @who '; break;
case 5: txt = '@from pokes @who repeatedly '; break;
default: txt = '@from, with index finger stern and pointy, pokes @who '; break;
}
return txt + this.getPokeBodyPlace() + '.';
}
},
Hit: {
strikeAction: ['clobber', 'subdue', 'hit', 'bash', 'pound', 'pelt', 'hammer', 'wallop',
'swat', 'punish', 'pummel', 'strike', 'beat'],
leapingAction: ['vaults', 'surges', 'hurdles', 'bounds', 'pounces', 'storms', 'leaps',
'bolts', 'stampedes', 'sprints', 'dashes', 'charges', 'lunges'],
aimModifier: ['a well placed', 'a pin-point accurate', 'a targeted', 'an aimed', 'a',
'a', 'a', 'a', 'a', 'a', 'a'],
wrestlingMove: [' haymaker punch', ' kitchen sink to the midsection', ' jumping DDT',
' cross body attack', ' flying forearm', ' low dropkick',
' jumping thigh kick', ' roundhouse', ' left and right hook combo',
' jab and middle kick combo', ' spinning backfist and shin kick combo',
' delayed backbrain wheel kick',
' somersault kick to an uppercut combo', ' jab to the face',
' stomping hook punch', ' palm thrust to the solar plexus',
' shin kick', ' side headbutt', ' fast lowerbody roundhouse kick',
' fast upperbody roundhouse kick', 'n uppercut palm strike',
'n uppercut to midsection jab combo', ' downward chop'],
meal: ['midmorning snack', 'midnight snack', 'supper', 'breakfast', 'brunch',
'2 o\'clock tea time', 'midafternoon snack', 'lunch'],
throwAction: ['tosses', 'propels', 'throws', 'catapults', 'hurls', 'launches'],
crying: ['shouting', 'screaming', 'hollering', 'yelling', 'crying out'],
sportsWeapon: ['cricket paddle', 'lacrosse stick', 'hockey stick', 'croquet mallet',
'baseball bat', 'yoga ball', 'barbell', 'folding lawn chair', 'caber',
'shot put', 'bowling ball', 'lantern', 'tennis racket'],
midsectionStrikePlace: ['midsection', 'solar plexus', 'chest', 'abdomen', 'sternum'],
randomItemWeapon: ['a giant frozen trout', 'an inflatable duck', 'a waffle iron',
'a sponge brick', 'a board of education',
'an unidentified implement of mayhem and destruction',
'a rubber ducky *SQUEAK*', 'a rolling pin', 'a tire iron',
'a sock full of oranges', 'a slinky, a slink [fun for a girl or a boy]',
'a chinese finger puzzle', 'a whip of wet noodles',
'a humungous spicey italian meatstick', 'a giant garlic dill',
'an ACME hammer of pain'],
withDescriptors: ['with lightning reflexes, ', 'with finesse and poise, ',
'with mediocre skill, ', 'with half-cocked attitude, ',
'with fervor and oomph, ', 'with vitality and gusto, ',
'with ambition and enthusiasm, ', '', '', '', ''],
strikeActionVerb: ['clobbers', 'subdues', 'hits', 'bashes', 'pounds', 'pelts', 'hammers',
'wallops', 'swats', 'punishes', 'pummels', 'strikes', 'assaults',
'beats'],
generate: function() {
let txt = '';
switch(DRMng.Util.getRand(7)) {
case 0: txt = '@from attempts to ' + this.strikeAction[DRMng.Util.getRand(12)] + ' @who but fails...'; break;
case 1: txt = '@from ' + this.leapingAction[DRMng.Util.getRand(12)] + ' towards @who and lands ' + this.aimModifier[DRMng.Util.getRand(10)] + this.wrestlingMove[DRMng.Util.getRand(20)] + '.'; break;
case 2: txt = '@from takes what\'s left of ' + this.meal[DRMng.Util.getRand(7)] + ', ' + this.throwAction[DRMng.Util.getRand(5)] + ' it towards @who ' + this.crying[DRMng.Util.getRand(4)] + ', \'FOOD FIGHT\'!'; break;
case 4: txt = '@from rolls up a magazine planting a blow upside the head of @who.'; break;
case 5: txt = '@from hits @who on the head with a frying pan.'; break;
case 6: txt = '@from plants a ' + this.sportsWeapon[DRMng.Util.getRand(12)] + ' to the ' + this.midsectionStrikePlace[DRMng.Util.getRand(4)] + ' of @who.'; break;
default: txt = '@from pulls out ' + this.randomItemWeapon[DRMng.Util.getRand(15)] + ' and ' + this.withDescriptors[DRMng.Util.getRand(10)] + this.strikeActionVerb[DRMng.Util.getRand(13)] + ' @who with it.'; break;
}
return txt;
}
},
Slap: {
slapWeapon: ['white glove', 'rubber chicken', 'well placed backhand', 'failing Euryino',
'piece of moldy pizza', 'big dildo', 'loaf of french bread',
'smile of devious pleasure', 'dead >0))>-<', 'left over chicken drumstick',
'limp and slightly dirty french fry', 'brick of moldy cheese', 'tickle me Elmo',
'grilled cheese'],
targetAction: ['deals', 'aims', 'inflicts', 'releases', 'dispatches', 'discharges', 'delivers',
'unleashes'],
sassySynonym: ['an audacious', 'an impudent', 'a bold', 'an overbold', 'an arrant', 'a brassy',
'a sassy'],
place: [['side', '\'s head.'], ['face', '.'], ['cheek', '.']],
leapingAction: ['vaults', 'surges', 'hurdles', 'bounds', 'pounces', 'storms', 'leaps', 'bolts',
'stampedes', 'sprints', 'dashes', 'charges', 'lunges'],
leadSpeed: [' sudden', ' spry', 'n abrupt', 'n energetic', ' hasty', 'n agile',
'n accelerated', ' quick'],
generate: function() {
let txt = '';
switch(DRMng.Util.getRand(2)) {
case 0: txt = '@from slaps @who with a ' + this.slapWeapon[DRMng.Util.getRand(13)] + '.'; break;
case 1:
let place = this.place[DRMng.Util.getRand(2)];
txt = '@from ' + this.targetAction[DRMng.Util.getRand(7)] + ' ' + this.sassySynonym[DRMng.Util.getRand(6)] + ' slap to the ' + place[0] + ' of @who' + place[1];
break;
default: txt = '@from ' + this.leapingAction[DRMng.Util.getRand(12)] + ' forward and with a ' + this.slapWeapon[DRMng.Util.getRand(13)] + ', deals a' + this.leadSpeed[DRMng.Util.getRand(7)] + ' slap to @who.';
}
return txt;
}
}
},
Config: {
local: {
kong: {
kongSlimHeader: false,
chatWidth: 250
},
server: 'Elyssa',
sortBy: 'hp',
scriptWidth: 300,
visited: { kasan: [], elyssa: [] },
raidData: {},
raidKeys: [],
filterData: {},
tiersData: {},
filterString: { kasan: '', elyssa: '' },
filterRaids: { kasan: {}, elyssa: {} },
hardFilter: { kasan: [], elyssa: [] },
checkSums: {
raidData: '',
filterData: '',
tiersData: '',
},
alliance: {
enabled: false,
channel: '',
pass: '',
sbs: false
}
},
remote: {},
loadLocal: function() {
let data = localStorage['DRMng'];
if (data) {
data = JSON.parse(data);
let keys = Object.keys(this.local);
for (let i = 0; i < keys.length; ++i)
if (data.hasOwnProperty(keys[i])) this.local[keys[i]] = data[keys[i]];
keys = Object.keys(data);
for (let i = 0; i < keys.length; ++i)
if (!this.local.hasOwnProperty(keys[i])) this.local[keys[i]] = data[keys[i]];
}
else this.saveLocal();
this.local.raidKeys = Object.keys(this.local.raidData);
// fixes for early testers, remove later
if (this.local.visited.elyssa === undefined) this.local.visited = { kasan: [], elyssa: [] };
if (this.local.filterString.elyssa === undefined) this.local.filterString = { kasan: '', elyssa: '' };
this.saveLocal();
},
saveLocal: function() {
localStorage['DRMng'] = JSON.stringify(this.local);
}
},
Kong: {
killScripts: function() {
let scr = document.getElementsByTagName('script');
let counter = 0;
for (let i=0; i<scr.length; ++i) if(scr[i].src.indexOf('google') > 0) {
scr[i].parentNode.removeChild(scr[i]);
counter++;
}
console.info('[DRMng] {Kong} Removed unnecesary \<script\> tags (%d)', counter);
},
killAds: function() {
if(typeof kong_ads === 'object') {
console.info("[DRMng] {Kong} Killed 'kong_ads'!");
window.kong_ads = { displayAd: function(){} };
}
else setTimeout(DRMng.Kong.killAds, 50);
},
killBumper: function() {
if(typeof bumper === 'object') {
console.info("[DRMng] {Kong} Killed 'bumper'!");
window.bumper = { requestAd: function(){} };
}
else setTimeout(DRMng.Kong.killBumper, 50);
},
killFBlike: function() {
let like = document.getElementById('quicklinks_facebook');
if(like) {
console.info("[DRMng] {Kong} Killed 'FB like'!");
like.parentNode.removeChild(like);
}
else setTimeout(DRMng.Kong.killFBlike, 1000);
},
killDealSpot: function() {
let ds = document.getElementById('dealspot_banner_holder');
if (ds) {
console.info("[DRMng] {Kong} Killed 'DealSpot'!");
ds.parentNode.removeChild(ds);
}
else setTimeout(DRMng.Kong.killDealSpot, 1000);
},
addReloadButton: function() {
let li = document.createElement('li');
li.className = 'spritegame';
//li.innerHTML = '<a onclick="activateGame();">Reload</a>';
li.innerHTML = '<a onclick="DRMng.postGameMessage(\'gameReload\');">Reload Game</a>';
li.style.backgroundPosition = '0 -280px';
li.style.cursor = 'pointer';
document.getElementById('quicklinks').appendChild(li);
li = document.createElement('li');
li.className = 'spritegame';
li.innerHTML = '<a onclick="DRMng.postGameMessage(\'chatReload\');">Reload Chat</a>';
li.style.backgroundPosition = '0 -280px';
li.style.cursor = 'pointer';
document.getElementById('quicklinks').appendChild(li);
li = document.createElement('li');
li.className = 'spritegame';
li.innerHTML = '<a onclick="DRMng.Kong.hideWorldChat(this)">Hide WC</a>';
li.style.backgroundPosition = '0 -280px';
li.style.cursor = 'pointer';
document.getElementById('quicklinks').appendChild(li);
},
addSlimButton: function() {
// set body class name on script load
if (DRMng.Config.local.kong.kongSlimHeader) document.body.className += ' slim';
// configure new button
let li = document.createElement('li');
let a = document.createElement('a');
a.href = '';
a.id = 'DRMng_KongSlimHeader';
a.innerHTML = DRMng.Config.local.kong.kongSlimHeader ? 'Full' : 'Slim';
// configure switching event
a.addEventListener('click', function(e){
e.preventDefault();
let isSlim = !DRMng.Config.local.kong.kongSlimHeader;
document.getElementById('DRMng_KongSlimHeader').innerHTML = isSlim ? 'Full' : 'Slim';
let bodyClass = document.body.className;
DRMng.Config.local.kong.kongSlimHeader = isSlim;
DRMng.Config.saveLocal();
if (isSlim) bodyClass += ' slim';
else bodyClass = bodyClass.replace(/\sslim/g,'');
document.body.className = bodyClass;
return false;
});
// append new button to nav
li.appendChild(a);
document.getElementById('nav_welcome_box').appendChild(li);
},
addSbsChatContainer: function() {
let chat = document.getElementById('chat_window');
if (chat) {
let sbs = document.createElement('div');
sbs.setAttribute('id', 'alliance_chat_sbs');
sbs.setAttribute('style', 'display: none');
sbs.addEventListener('click', DRMng.Alliance.sbsEvent);
document.getElementById('chat_tab_pane').appendChild(sbs);
}
else setTimeout(this.addSbsChatContainer.bind(this), 10);
},
modifyElement: function() {
if (Element && Element.Methods && Element._insertionTranslations) {
Element._insertionTranslations.after = function (a, b) {
let c = a.parentNode; c && c.insertBefore(b, a.nextSibling)
};
Element.Methods.remove = function (a) {
a = $(a); let b = a.parentNode; b && b.removeChild(a);
return a
};
Element.addMethods(Element.Methods);
console.info("[DRMng] {Kong} Element patched!");
}
else setTimeout(this.modifyElement, 50);
},
modifyChatDialogue: function() {
if (ChatDialogue && ChatDialogue.prototype) {
ChatDialogue.DRM_MESSAGE_TEMPLATE = new Template(
'<p class="#{classNames}">' +
'<span class="timestamp">#{timestamp}</span>' +
'<span username="#{username}" class="username truncate #{userClassNames}">#{prefix}#{username}</span>' +
'<span class="#{characterClassNames}">#{characterName}</span>' +
'<span class="separator">: </span><span class="message hyphenate">#{message}</span>' +
'</p>'
);
ChatDialogue.DRM_RAID_TEMPLATE = new Template(
'<p class="raid #{classNames}">' +
'<span class="timestamp">#{timestamp}<span>#{raidInfo}</span></span>' +
'<span class="extraid">#{extRaidInfo}</span>' +
'<span username="#{username}" class="username truncate #{userClassNames}">#{prefix}#{username}</span>' +
'<span class="#{characterClassNames}">#{characterName}</span>' +
'<span class="separator">#{separator}</span><span class="message hyphenate">#{message}</span>' +
'</p>'
);
ChatDialogue.DRM_SCRIPT_TEMPLATE = new Template(
'<div class="#{classNames}" style="#{customStyle}">#{message}</div>'
);
ChatDialogue.prototype.displayUnsanitizedMessage = function (a, b, c, d) {
//console.info("user:",a,"extInfo:",d);
c || (c = {});
d || (d = {});
let active_room = this._holodeck.chatWindow().activeRoom();
let allow_mutes = active_room && !active_room.canUserModerate(active_room.self()) || d.whisper;
if (!allow_mutes || !this._user_manager.isMuted(a)) {
let e = !d.non_user ? ["chat_message_window_username"] : ["chat_message_window_undecorated_username"],
f = a == this._user_manager.username(),
g = [],
h = d["private"] ? "To " : ( d["whisper"] ? "From " : "" );
// helper booleans
let isWhisp = !!h;
//isGuild = !isWhisp && d.room.type === 'guild',
//isGame = !isWhisp && d.room.type === 'game';
c["class"] && g.push(c["class"]);
f && e.push("is_self");
// proper timestamp handling
if (!d.timestamp || !d.history) d.timestamp = new Date().getTime();
d.formatted_timestamp = new Date(d.timestamp).format("mmm d, HH:MM");
let raid = /(^.*?)(https?...www.kongregate.com.+?kv_action_type.raidhelp.+?)(\s[\s\S]*$|$)/.exec(b);
let rData = null, cData = {};
if (raid) {
rData = DRMng.Util.getRaidFromUrl(raid[2], a);
if (rData) {
let server = DRMng.Config.local.server.toLowerCase();
b = raid[1] + raid[3];
g.push(['n', 'h', 'l', 'nm'][rData.diff - 1]);
g.push(rData.id);
DRMng.Config.local.visited[server].indexOf(rData.id) !== -1 && g.push('visited');
cData.link = raid[2];
let rInfo = DRMng.Config.local.raidData[rData.boss];
let dName = [];
dName.push(['N', 'H', 'L', 'NM'][rData.diff - 1]);
dName.push(rInfo ? rInfo.sName : rData.boss.replace(/_/g, ' ').toUpperCase());
cData.displayName = dName.join(' ');
cData.extInfo = rInfo ?
(rInfo.maxPlayers === 90000 ?
'WR/ER' :
'FS ' + DRMng.Util.getShortNumK(rInfo.hp[rData.diff - 1]*1000/rInfo.maxPlayers)) :
'';
//if (isGame && !h) setTimeout(DRMng.Raids.checkAndSend, 1000 + Math.random() * 2000, rData);
}
}
else {
let reg = /(https?\S+[^,\s])/g, l, link, start, end;
while (l = reg.exec(b)) {
link = /\.(jpe?g|png|gif)$/.test(l[1])
? '<img src="' + l[1] + '" alt="'+ l[1] +'" onclick="window.open(this.src)">'
: '<a href="' + l[1] + '" target="_blank">' + l[1].replace(/^https?:\/\//,'') + '</a>';
start = b.substr(0, reg.lastIndex - l[1].length);
end = b.slice(reg.lastIndex);
b = start + link + end;
reg.lastIndex += link.length - l[1].length;
}
}
if (raid && rData)
a = ChatDialogue.DRM_RAID_TEMPLATE.evaluate({
prefix: h,
username: a,
separator: b ? ': ' : '',
message: b ? ('<br>' + b) : b,
raidInfo: '<a href="'+cData.link+'" onclick="DRMng.Raids.joinOne({id:\''+rData.id+'\',hash:\''+rData.hash+'\',boss:\''+rData.boss+'\'});return false;">'+cData.displayName+'</a>',
extRaidInfo: cData.extInfo,
classNames: g.join(" "),
userClassNames: e.join(" "),
characterClassNames: d.characterName ? 'guildname truncate' : '',
characterName: d.characterName || '',
timestamp: d.formatted_timestamp
});
else
a = ChatDialogue.DRM_MESSAGE_TEMPLATE.evaluate({
prefix: h,
username: a,
message: b,
classNames: g.join(" "),
userClassNames: e.join(" "),
characterClassNames: d.characterName ? 'guildname truncate' : '',
characterName: d.characterName || '',
timestamp: d.formatted_timestamp
});
//console.log(a);
this.insert(a, null, {timestamp: d.timestamp});
this._messages_count++
}
};
ChatDialogue.prototype.serviceMessage = function (msg, isRaidInfo) {
isRaidInfo = isRaidInfo || null;
msg = ChatDialogue.DRM_SCRIPT_TEMPLATE.evaluate({
message: msg,
classNames: 'script' + (isRaidInfo ? ' raidinfo' : ''),
customStyle: isRaidInfo ? ('background-image: linear-gradient( rgba(0, 0, 0, 0.5), rgba(250, 250, 250, 0.9) 100px ), url(https://5thplanetdawn.insnw.net/dotd_live/images/bosses/' + isRaidInfo + '.jpg);') : ''
});
let d = this, e = this._message_window_node;
let node = document.createElement('div');
node.className = 'chat-message';
node.innerHTML = msg;
e.appendChild(node);
setTimeout(d.scrollToBottom.bind(d),10);
//this.insert(msg, null, {timestamp: new Date().getTime()});
this._messages_count++
};
ChatDialogue.prototype.displayMessage = function (a, b, c, d) {
this.displayUnsanitizedMessage(a, b, c, d)
};
ChatDialogue.prototype.receivedPrivateMessage = function (a) {
if (a.data.success) this.displayUnsanitizedMessage(a.data.from, a.data.message + ' <a class="reply_link" onclick="holodeck.insertPrivateMessagePrefixFor(\'' + a.data.from + '\');return false;" href="#">(reply)</a>', {"class": "whisper received_whisper"}, {whisper: true});
else this.kongBotMessage(a.data.to + " cannot be reached. Please try again later.");
};
ChatDialogue.prototype.sameTimestamps = function (a, b) {
a = new Date(a); b = new Date(b);
return a.getYear() === b.getYear() && a.getMonth() === b.getMonth() && a.getDay() === b.getDay() && a.getHours() === b.getHours() && a.getMinutes() === b.getMinutes()
};
ChatDialogue.prototype.insert = function (a, b, c) {
let d = this, e = this._message_window_node, f = this._holodeck;
f.scheduleRender(function () {
let g = e.getHeight();
//var h = g + e.scrollTop + ChatDialogue.SCROLL_FUDGE >= e.scrollHeight;
// removed scroll fudge
let h = g + e.scrollTop >= e.scrollHeight;
let r = true; //0 !== g && h;
f.scheduleRender(function () {
if ("string" == typeof a || a instanceof String)a = $j("<div/>", {html: a, "class": "chat-message"});
if (c && c.timestamp) {
let f = $j(e).children(".chat-message").filter(function () {
return $j(this).data("timestamp") > c.timestamp
});
0 < f.length ? ($j(a).data(c).insertBefore(f.first()), r = !1) : $j(a).data(c).appendTo(e)
} else $j(a).appendTo(e);
r && d.scrollToBottom();
b && b()
})
})
};
console.info("[DRMng] {Kong} ChatDialogue patched!");
}
else setTimeout(this.modifyChatDialogue, 50);
},
modifyChatRoom: function() {
if (ChatRoom && ChatRoom.prototype) {
ChatRoom.prototype.receivedMessage = function (a) {
//console.log("ReceivedMessage:",a.data);
this.isActive() || this._unread_message_node.show();
this.checkUserForModeration(a.data.user.username);
// magic shortcut! displayMessage -> displayUnsanitizedMessage,
// (eliminate double unnecessary function call)
this._chat_dialogue.displayUnsanitizedMessage(a.data.user.username, a.data.message, {}, {
characterName: a.data.user.variables.game_character_name,
timestamp: a.data.timestamp,
// if message belongs to history load routine
history: a.data.history,
// some room info (name,type) needed,
// to properly identify room to which message belongs
room: { name: this._room.name, type: this._room.type }
})
};
console.info("[DRMng] {Kong} ChatRoom patched!");
}
else setTimeout(this.modifyChatRoom, 50);
},
modifyFayeEvent: function() {
if (FayeEventDispatcher && FayeEventDispatcher.prototype) {
FayeEventDispatcher.prototype.message = function (a, b) {
this.checkDuplicateMessage(b) || this._holodeckEventDispatcher.fire({
type: KonduitEvent.ROOM_MESSAGE,
data: {
history: b.history,
message: b.text,
timestamp: b.timestamp * 1000,
room: a,
user: FayeUserTransformer.transformUser(b)
}
})
};
console.info("[DRMng] {Kong} FayeEventDispatcher patched!");
}
else setTimeout(this.modifyFayeEvent, 50);
},
modifyFayeHistory: function() {
if (FayeHistoryService && FayeHistoryService.prototype) {
FayeHistoryService.prototype.fetchHistory = function (a, b, c) {
let d = this;
this._makeAjaxRequest(a, b, c).then(function (b) {
$j.each(b.history, function (b, c) {
c.push(true);
d.trigger("message", a, FayeMessageTransformer.transform(c))
});
d.trigger("history", a, b.history.length)
})
};
console.info("[DRMng] {Kong} FayeHistory patched!");
}
else setTimeout(this.modifyFayeHistory, 50);
},
modifyFayeTransformer: function() {
if (FayeMessageTransformer && typeof FayeMessageTransformer.transform === 'function') {
FayeMessageTransformer.transform = function (a) {
return {
version: a[0],
kuid: a[1],
uuid: a[2],
text: a[3],
timestamp: a[4],
user_id: a[5],
username: a[6],
character_name: a[7],
level: a[8],
admin: 0 <= a[10].indexOf("a"),
developer: 0 <= a[10].indexOf("d"),
mobile: 0 <= a[10].indexOf("m"),
premium: 0 <= a[10].indexOf("p"),
guid: a[9],
history: a[12] || false
}
};
console.info("[DRMng] {Kong} FayeTransformer patched!");
}
else setTimeout(this.modifyFayeTransformer, 50);
},
modifyHolodeck: function() {
if (Holodeck && Holodeck.prototype) {
Holodeck.prototype.processChatCommand = function(a,d) {
var b = ((a.match(/^\/([^\s]+)/) || [])[1] || "").toLowerCase();
if (this._chat_commands[b]) {
var c = d ? DRMng.Alliance : this;
return void 0 === this._chat_commands[b].detect(function (b) {
return !1 === b(c, a)
})
}
return !0
};
console.info("[DRMng] {Kong} Holodeck patched!");
}
else setTimeout(this.modifyHolodeck, 50);
},
addChatCommand: function(cmd, call) {
cmd = typeof cmd === 'object' ? cmd : [cmd];
for (let i = 0; i < cmd.length; ++i) holodeck.addChatCommand(cmd[i],call);
},
addChatCommands: function() {
if (holodeck && holodeck.ready) {
/* Gestures Commands */
this.addChatCommand(['kiss','hit','poke','slap'],function(a,b) {
let tmp = /^\/(kiss|hit|poke|slap) (\w+)$/.exec(b),
from = DRMng.UM.user.name,
who = tmp[2],
alliance = !(a instanceof Holodeck),
chat = alliance ? a : a.activeDialogue();
if (from && who && chat && tmp[1]) {
let mode = tmp[1].charAt(0).toUpperCase() + tmp[1].slice(1),
gesture = `** ${DRMng.Gestures[mode].generate()
.replace('@from',from)
.replace('@who',who)} **`;
//console.debug(`[DRMng] {Gesture} ${alliance?'Alliance':'Kong'} chat: ${gesture}`);
if (alliance) DRMng.Alliance.send(gesture);
else chat._holodeck.filterOutgoingMessage(gesture, chat._onInputFunction);
}
return false;
});
// TODO: /perc
/*1 : Brown/Grey<br>\
4k : Brown/Grey/Green<br>\
6k : Grey/Green<br>\
10k : Grey/Green/Blue<br>\
14k : Green/Blue<br>\
16k : Green/Blue/Purple<br>\
18k : Blue/Purple<br>\
22k : Blue/Purple/Orange<br>\
24k : Purple/Orange<br>\
30k : Orange<br>\
33k : Orange/Red (more orange)<br>\
36k : Orange/Red (more red)<br>\
50k : Orange/Red (even more red)<br>\
70k : Red<br>\
80k : Red/Bronze<br>\
90k : Red/Bronze<br>\
100k : ???<br>\
110k : Bronze/Silver<br>\
120k : Bronze/Silver<br>\
130k : Bronze/Silver<br>\
140k : Silver<br>\
150k : Silver/Gold<br>\
160k : Silver/Gold<br>\
170k : Silver/Gold";
* */
this.addChatCommand(['reload','reloaf','relaod','rl'],function(a,b){
let type = /^\/\w+\s?(.*)$/.exec(b);
type = type ? type[1] : '';
switch (type) {
case 'game':
DRMng.postGameMessage('gameReload');
break;
case 'chat':
DRMng.postGameMessage('chatReload');
break;
default:
window.activateGame();
}
return false;
});
this.addChatCommand('clear',function(a,b){
if (a instanceof Holodeck) holodeck._active_dialogue.clear();
else a.clear();
return false;
});
this.addChatCommand('kill',function(a,b){
let k = /^\/kill\s?(.*)$/.exec(b);
switch (k[1]) {
case 'game':
DRMng.postGameMessage('killGame');
break;
case 'chat':
DRMng.postGameMessage('killChat');
break;
default:
document.getElementById('gameiframe').src = "";
}
return false;
});
this.addChatCommand('wiki',function(a,b){
let l = /^\/wiki (.+)$/.exec(b);
if (l) window.open(`http://dotd.wikia.com/wiki/Special:Search?search=${l[1]}`);
return false;
});
this.addChatCommand('enc',function(a,b){
let l = /^\/enc (.+)$/.exec(b);
if (l) window.open(`http://mutik.erley.org/enc/#task=src_${encodeURI(`"${l[1]}"`)}`);
return false;
});
this.addChatCommand(['raid','rd'],function(a,b){
console.log("ChatCmdCtx:", a);
let raid = /^\/(raid|rd) (.+)$/.exec(b);
let chat = (a instanceof Holodeck) ? a.activeDialogue() : a;
if (raid) {
raid = raid[2].toLowerCase();
let keys = DRMng.Config.local.raidKeys,
data = DRMng.Config.local.raidData,
found = [], i, len;
for (i = 0, len = keys.length; i < len; ++i) {
if (keys[i].indexOf(raid) > -1 ||
data[keys[i]].fName.toLowerCase().indexOf(raid) > -1)
found.push([keys[i], data[keys[i]].fName]);
}
if (found.length > 1) {
let raidPicker = '';
for (i = 0, len = found.length; i < len; ++i)
raidPicker += `<br><span class="DRMng_info_picker ${found[i][0]}">${found[i][1]} (${found[i][0]})</span>`;
chat && chat.serviceMessage('Multiple results found, pick one:' + raidPicker);
}
else if (found.length === 1)
chat && chat.serviceMessage(DRMng.UI.raidInfo(found[0][0]), data[found[0][0]].banner);
else chat && chat.serviceMessage('No info found matching ' + raid);
}
else chat && chat.serviceMessage('Wrong /raid or /rd syntax');
return false;
});
console.info("[DRMng] {Kong} Chat commands added!");
//setTimeout(this.killScripts());
}
else setTimeout(this.addChatCommands.bind(this), 50);
},
moveChatOptions: function() {
let src = document.getElementById('chat_actions_container');
let dst = document.getElementById('chat_room_tabs');
if (src && dst) dst.appendChild(src);
else setTimeout(this.moveChatOptions.bind(this), 50);
},
modifyKongEngine: function() {
this.modifyHolodeck();
this.modifyChatRoom();
this.modifyChatDialogue();
this.modifyFayeEvent();
this.modifyFayeTransformer();
this.modifyFayeHistory();
this.modifyElement();
this.addChatCommands();
setTimeout(this.moveChatOptions.bind(this), 500);
},
setHeaderWidth: function() {
document.getElementById('header').style.width = document.getElementById('maingame').offsetWidth + 'px';
},
hideWorldChat: function(el) {
if (el) {
if (el.innerHTML === 'Hide WC') {
el.innerHTML = 'Show WC';
document.getElementById('game').style.width = '760px';
}
else {
el.innerHTML = 'Hide WC';
document.getElementById('game').style.width = '1025px';
}
}
return false;
},
killIframes: function() {
let ifr = document.querySelectorAll('iframe');
if (ifr) {
for (let i = 0; i < ifr.length; ++i)
if (ifr[i].id !== 'gameiframe') ifr[i].parentNode.removeChild(ifr[i]);
console.info("[DRMng] {Kong} All redundant iframes killed!");
if (document.querySelector('iframe#gameiframe') === null) {
console.info("Game needs forced loading!");
DRMng.Kong.forceGameLoad();
}
}
else setTimeout(DRMng.Kong.killIframes, 1000);
},
forceGameLoad: function() {
let game = document.getElementById('game');
console.info("Trying to force game loading");
if (typeof activateGame === 'function' && game) {
console.info("Running activateGame...");
activateGame();
}
else setTimeout(DRMng.Kong.forceGameLoad, 250);
},
CSS: {
rules: {},
elem: null,
add: function(alias, name, value) {
this.rules[alias] = {name: name, value: value};
this.compile(this.rules[alias]);
},
del: function(alias) {
if (this.rules[alias] !== undefined) delete this.rules[alias];
this.compile();
},
rpl: function(alias, name, value) {
if (this.rules[alias] !== undefined) delete this.rules[alias];
this.rules[alias] = {name: name, value: value};