forked from magicoflolis/Userscript-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
3030 lines (3003 loc) · 99.3 KB
/
Copy pathmain.js
File metadata and controls
3030 lines (3003 loc) · 99.3 KB
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
// TODO: Add polish (pl)
// #region Console
const dbg = (...msg) => {
const dt = new Date();
console.debug(
'[%cMagic Userscript+%c] %cDBG',
'color: rgb(29, 155, 240);',
'',
'color: rgb(255, 212, 0);',
`[${dt.getHours()}:${('0' + dt.getMinutes()).slice(-2)}:${('0' + dt.getSeconds()).slice(-2)}]`,
...msg
);
};
const err = (...msg) => {
console.error(
'[%cMagic Userscript+%c] %cERROR',
'color: rgb(29, 155, 240);',
'',
'color: rgb(249, 24, 128);',
...msg
);
for (const ex of msg) {
if (typeof ex === 'object' && 'cause' in ex && typeof alert !== 'undefined') {
alert(`[Magic Userscript+] (${ex.cause}) ${ex.message}`);
}
}
};
const info = (...msg) => {
console.info(
'[%cMagic Userscript+%c] %cINF',
'color: rgb(29, 155, 240);',
'',
'color: rgb(0, 186, 124);',
...msg
);
};
const log = (...msg) => {
console.log(
'[%cMagic Userscript+%c] %cLOG',
'color: rgb(29, 155, 240);',
'',
'color: rgb(219, 160, 73);',
...msg
);
};
// #endregion
let cfg = {};
let ghMsg = null;
/** @type { import("../typings/UserJS.d.ts").safeSelf } */
function safeSelf() {
if (userjs.safeSelf) {
return userjs.safeSelf;
}
const g = globalThis;
const safe = {
XMLHttpRequest: g.XMLHttpRequest,
createElement: g.document.createElement.bind(g.document),
createElementNS: g.document.createElementNS.bind(g.document),
createTextNode: g.document.createTextNode.bind(g.document),
setTimeout: g.setTimeout,
clearTimeout: g.clearTimeout
};
userjs.safeSelf = safe;
return safe;
}
// Lets highlight me :)
const authorID = 166061;
// Some UserJS I personally enjoy
const goodUserJS = [
423001,
376510,
23840,
40525,
6456,
'https://github.com/TagoDR/MangaOnlineViewer/raw/master/Manga_OnlineViewer.user.js',
'https://github.com/jesus2099/konami-command/raw/master/INSTALL-USER-SCRIPT.user.js',
'https://github.com/TagoDR/MangaOnlineViewer/raw/master/dist/Manga_OnlineViewer_Adult.user.js'
];
// Unsupport webpages for each engine
const engineUnsupported = {
greasyfork: ['pornhub.com'],
sleazyfork: ['pornhub.com'],
openuserjs: [],
github: []
};
const getUAData = () => {
if (typeof userjs.isMobile !== 'undefined') {
return userjs.isMobile;
}
try {
const { platform, mobile } = navigator.userAgentData ?? {};
userjs.isMobile =
/Mobile|Tablet/.test(navigator.userAgent ?? '') ||
mobile ||
/Android|Apple/.test(platform ?? '');
} catch (ex) {
err({ cause: 'getUAData', message: ex.message });
userjs.isMobile = false;
}
return userjs.isMobile;
};
const isMobile = getUAData();
const isGM = typeof GM !== 'undefined';
const winLocation = window.top.location;
const META_START_COMMENT = '// ==UserScript==';
const META_END_COMMENT = '// ==/UserScript==';
const TLD_EXPANSION = ['com', 'net', 'org', 'de', 'co.uk'];
const APPLIES_TO_ALL_PATTERNS = [
'http://*',
'https://*',
'http://*/*',
'https://*/*',
'http*://*',
'http*://*/*',
'*',
'*://*',
'*://*/*',
'http*'
];
const builtinList = {
local: /localhost|router|gov|(\d+\.){3}\d+/,
finance:
/school|pay|bank|money|cart|checkout|authorize|bill|wallet|venmo|zalo|skrill|bluesnap|coin|crypto|currancy|insurance|finance/,
social: /login|join|signin|signup|sign-up|password|reset|password_reset/,
unsupported: {
host: 'fakku.net',
pathname: '/hentai/.+/read/page/.+'
}
};
const defcfg = {
cache: true,
codePreview: false,
autoexpand: false,
filterlang: false,
sleazyredirect: false,
time: 10000,
blacklist: ['userjs-local', 'userjs-finance', 'userjs-social', 'userjs-unsupported'],
engines: [
{
enabled: true,
name: 'greasyfork',
url: 'https://greasyfork.org'
},
{
enabled: false,
name: 'sleazyfork',
url: 'https://sleazyfork.org'
},
{
enabled: false,
name: 'openuserjs',
url: 'https://openuserjs.org/?q='
},
{
enabled: false,
name: 'github',
url: 'https://api.github.com/search/code?q=',
token: ''
}
],
theme: {
'even-row': '',
'odd-row': '',
'even-err': '',
'odd-err': '',
'background-color': '',
'gf-color': '',
'sf-color': '',
'border-b-color': '',
'gf-btn-color': '',
'sf-btn-color': '',
'sf-txt-color': '',
'txt-color': '',
'chck-color': '',
'chck-gf': '',
'chck-git': '',
'chck-open': '',
placeholder: '',
'position-top': '',
'position-bottom': '',
'position-left': '',
'position-right': '',
'font-family': ''
},
recommend: {
author: true,
others: true
}
};
class LanguageHandler {
constructor() {
this.current = (navigator.language ?? 'en').split('-')[0] ?? 'en';
this.cache = [];
const languages = navigator.languages ?? [];
for (const nlang of languages) {
const lg = nlang.split('-')[0];
if (this.cache.indexOf(lg) === -1) {
this.cache.push(lg);
}
}
if (!this.cache.includes(this.current)) {
this.cache.push(this.current);
}
}
}
const language = new LanguageHandler();
const i18n$ = (...args) => {
const list = translations[cfg.language] ?? translations[language.current] ?? translations['en'];
const arr = [];
for (const arg of args) {
arr.push(list[arg]);
}
return arr.length !== 1 ? arr : arr[0];
};
// #region Utilities
/**
* @type { import("../typings/UserJS.d.ts").hasOwn }
*/
const hasOwn = (obj, prop) => {
if (typeof Object.hasOwn !== 'undefined') {
return Object.hasOwn(obj, prop);
}
return Object.prototype.hasOwnProperty.call(obj, prop);
};
/**
* @type { import("../typings/UserJS.d.ts").objToStr }
*/
const objToStr = (obj) => {
return Object.prototype.toString.call(obj);
};
/**
* @type { import("../typings/UserJS.d.ts").strToURL }
*/
const strToURL = (str) => {
try {
str = str ?? window.location ?? 'about:blank';
return objToStr(str).includes('URL') ? str : new URL(str);
} catch (ex) {
err({ cause: 'strToURL', message: ex.message });
return window.location;
}
};
/**
* @type { import("../typings/UserJS.d.ts").isRegExp }
*/
const isRegExp = (obj) => {
const s = objToStr(obj);
return s.includes('RegExp');
};
/**
* @type { import("../typings/UserJS.d.ts").isElem }
*/
const isElem = (obj) => {
const s = objToStr(obj);
return s.includes('Element');
};
/**
* @type { import("../typings/UserJS.d.ts").isObj }
*/
const isObj = (obj) => {
const s = objToStr(obj);
return s.includes('Object');
};
/**
* @type { import("../typings/UserJS.d.ts").isFN }
*/
const isFN = (obj) => {
const s = objToStr(obj);
return s.includes('Function');
};
/**
* @type { import("../typings/UserJS.d.ts").isNull }
*/
const isNull = (obj) => {
return Object.is(obj, null) || Object.is(obj, undefined);
};
/**
* @type { import("../typings/UserJS.d.ts").isBlank }
*/
const isBlank = (obj) => {
return (
(typeof obj === 'string' && Object.is(obj.trim(), '')) ||
((obj instanceof Set || obj instanceof Map) && Object.is(obj.size, 0)) ||
(Array.isArray(obj) && Object.is(obj.length, 0)) ||
(isObj(obj) && Object.is(Object.keys(obj).length, 0))
);
};
/**
* @type { import("../typings/UserJS.d.ts").isEmpty }
*/
const isEmpty = (obj) => {
return isNull(obj) || isBlank(obj);
};
/**
* @type { import("../typings/UserJS.d.ts").normalizeTarget }
*/
const normalizeTarget = (target, toQuery = true, root) => {
if (Object.is(target, null) || Object.is(target, undefined)) {
return [];
}
if (Array.isArray(target)) {
return target;
}
if (typeof target === 'string') {
return toQuery ? Array.from((root || document).querySelectorAll(target)) : [target];
}
if (isElem(target)) {
return [target];
}
return Array.from(target);
};
/**
* @type { import("../typings/UserJS.d.ts").ael }
*/
const ael = (el, type, listener, options = {}) => {
try {
for (const elem of normalizeTarget(el)) {
if (!elem) {
continue;
}
if (isMobile && type === 'click') {
elem.addEventListener('touchstart', listener, options);
continue;
}
elem.addEventListener(type, listener, options);
}
} catch (ex) {
err(ex);
}
};
/**
* @type { import("../typings/UserJS.d.ts").formAttrs }
*/
const formAttrs = (elem, attr = {}) => {
if (!elem) {
return elem;
}
for (const key in attr) {
if (typeof attr[key] === 'object') {
formAttrs(elem[key], attr[key]);
} else if (isFN(attr[key])) {
if (/^on/.test(key)) {
elem[key] = attr[key];
continue;
}
ael(elem, key, attr[key]);
} else if (key === 'class') {
elem.className = attr[key];
} else {
elem[key] = attr[key];
}
}
return elem;
};
/**
* @type { import("../typings/UserJS.d.ts").make }
*/
const make = (tagName, cname, attrs) => {
let el;
try {
const safe = safeSelf();
el = safe.createElement(tagName);
if (!isEmpty(cname)) {
if (typeof cname === 'string') {
el.className = cname;
} else if (isObj(cname)) {
formAttrs(el, cname);
}
}
if (!isEmpty(attrs)) {
if (typeof attrs === 'string') {
el.textContent = attrs;
} else if (isObj(attrs)) {
formAttrs(el, attrs);
}
}
} catch (ex) {
err(ex);
}
return el;
};
/**
* @type { import("../typings/UserJS.d.ts").getGMInfo }
*/
const getGMInfo = () => {
if (isGM) {
if (isObj(GM.info)) {
return GM.info;
} else if (isObj(GM_info)) {
return GM_info;
}
}
return {
script: {
icon: '',
name: 'Magic Userscript+',
namespace: 'https://github.com/magicoflolis/Userscript-Plus',
updateURL: 'https://github.com/magicoflolis/Userscript-Plus/releases',
version: 'Bookmarklet',
bugs: 'https://github.com/magicoflolis/Userscript-Plus/issues'
}
};
};
const $info = getGMInfo();
// #endregion
/**
* @type { import("../typings/UserJS.d.ts").dom }
*/
const dom = {
attr(target, attr, value = undefined) {
for (const elem of normalizeTarget(target)) {
if (value === undefined) {
return elem.getAttribute(attr);
}
if (value === null) {
elem.removeAttribute(attr);
} else {
elem.setAttribute(attr, value);
}
}
},
prop(target, prop, value = undefined) {
for (const elem of normalizeTarget(target)) {
if (value === undefined) {
return elem[prop];
}
elem[prop] = value;
}
},
text(target, text) {
const targets = normalizeTarget(target);
if (text === undefined) {
return targets.length !== 0 ? targets[0].textContent : undefined;
}
for (const elem of targets) {
elem.textContent = text;
}
},
cl: {
add(target, token) {
if (Array.isArray(token)) {
for (const elem of normalizeTarget(target)) {
elem.classList.add(...token);
}
} else {
for (const elem of normalizeTarget(target)) {
elem.classList.add(token);
}
}
},
remove(target, token) {
if (Array.isArray(token)) {
for (const elem of normalizeTarget(target)) {
elem.classList.remove(...token);
}
} else {
for (const elem of normalizeTarget(target)) {
elem.classList.remove(token);
}
}
},
toggle(target, token, force) {
let r;
for (const elem of normalizeTarget(target)) {
r = elem.classList.toggle(token, force);
}
return r;
},
has(target, token) {
for (const elem of normalizeTarget(target)) {
if (elem.classList.contains(token)) {
return true;
}
}
return false;
}
}
};
class Memorize {
constructor() {
/**
* @type {Map<string, Map<string, any>>}
*/
this.store = new Map();
this.create('cfg', 'container', 'userjs');
}
/**
* @template { string } S
* @param { ...S } maps
* @returns { S | S[] }
*/
create(...maps) {
const resp = [];
for (const key of maps) {
if (this.store.has(key)) {
return this.store.get(key);
}
this.store.set(key, new Map());
resp.push(this.store.get(key));
}
return resp.length >= 2 ? resp : resp[0];
}
}
const memory = new Memorize();
const iconSVG = {
cfg: {
viewBox: '0 0 24 24',
html: '<g><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7848 0.449982C13.8239 0.449982 14.7167 1.16546 14.9122 2.15495L14.9991 2.59495C15.3408 4.32442 17.1859 5.35722 18.9016 4.7794L19.3383 4.63233C20.3199 4.30175 21.4054 4.69358 21.9249 5.56605L22.7097 6.88386C23.2293 7.75636 23.0365 8.86366 22.2504 9.52253L21.9008 9.81555C20.5267 10.9672 20.5267 13.0328 21.9008 14.1844L22.2504 14.4774C23.0365 15.1363 23.2293 16.2436 22.7097 17.1161L21.925 18.4339C21.4054 19.3064 20.3199 19.6982 19.3382 19.3676L18.9017 19.2205C17.1859 18.6426 15.3408 19.6754 14.9991 21.405L14.9122 21.845C14.7167 22.8345 13.8239 23.55 12.7848 23.55H11.2152C10.1761 23.55 9.28331 22.8345 9.08781 21.8451L9.00082 21.4048C8.65909 19.6754 6.81395 18.6426 5.09822 19.2205L4.66179 19.3675C3.68016 19.6982 2.59465 19.3063 2.07505 18.4338L1.2903 17.1161C0.770719 16.2436 0.963446 15.1363 1.74956 14.4774L2.09922 14.1844C3.47324 13.0327 3.47324 10.9672 2.09922 9.8156L1.74956 9.52254C0.963446 8.86366 0.77072 7.75638 1.2903 6.8839L2.07508 5.56608C2.59466 4.69359 3.68014 4.30176 4.66176 4.63236L5.09831 4.77939C6.81401 5.35722 8.65909 4.32449 9.00082 2.59506L9.0878 2.15487C9.28331 1.16542 10.176 0.449982 11.2152 0.449982H12.7848ZM12 15.3C13.8225 15.3 15.3 13.8225 15.3 12C15.3 10.1774 13.8225 8.69998 12 8.69998C10.1774 8.69998 8.69997 10.1774 8.69997 12C8.69997 13.8225 10.1774 15.3 12 15.3Z" fill="currentColor"></path></g>'
},
close: {
viewBox: '0 0 24 24',
html: '<g><path d="M4.70718 2.58574C4.31666 2.19522 3.68349 2.19522 3.29297 2.58574L2.58586 3.29285C2.19534 3.68337 2.19534 4.31654 2.58586 4.70706L9.87877 12L2.5859 19.2928C2.19537 19.6834 2.19537 20.3165 2.5859 20.7071L3.293 21.4142C3.68353 21.8047 4.31669 21.8047 4.70722 21.4142L12.0001 14.1213L19.293 21.4142C19.6835 21.8047 20.3167 21.8047 20.7072 21.4142L21.4143 20.7071C21.8048 20.3165 21.8048 19.6834 21.4143 19.2928L14.1214 12L21.4143 4.70706C21.8048 4.31654 21.8048 3.68337 21.4143 3.29285L20.7072 2.58574C20.3167 2.19522 19.6835 2.19522 19.293 2.58574L12.0001 9.87865L4.70718 2.58574Z" fill="currentColor"></path></g>'
},
filter: {
viewBox: '0 0 24 24',
html: '<g stroke-width="0"/><g stroke-linecap="round" stroke-linejoin="round"/><g><path d="M4.22657 2C2.50087 2 1.58526 4.03892 2.73175 5.32873L8.99972 12.3802V19C8.99972 19.3788 9.21373 19.725 9.55251 19.8944L13.5525 21.8944C13.8625 22.0494 14.2306 22.0329 14.5255 21.8507C14.8203 21.6684 14.9997 21.3466 14.9997 21V12.3802L21.2677 5.32873C22.4142 4.03893 21.4986 2 19.7729 2H4.22657Z" fill="currentColor"/></g>'
},
fsClose: {
viewBox: '0 0 24 24',
html: '<g><path d="M7 9.5C8.38071 9.5 9.5 8.38071 9.5 7V2.5C9.5 1.94772 9.05228 1.5 8.5 1.5H7.5C6.94772 1.5 6.5 1.94772 6.5 2.5V6.5H2.5C1.94772 6.5 1.5 6.94772 1.5 7.5V8.5C1.5 9.05228 1.94772 9.5 2.5 9.5H7Z" fill="currentColor"></path> <path d="M17 9.5C15.6193 9.5 14.5 8.38071 14.5 7V2.5C14.5 1.94772 14.9477 1.5 15.5 1.5H16.5C17.0523 1.5 17.5 1.94772 17.5 2.5V6.5H21.5C22.0523 6.5 22.5 6.94772 22.5 7.5V8.5C22.5 9.05228 22.0523 9.5 21.5 9.5H17Z" fill="currentColor"></path> <path d="M17 14.5C15.6193 14.5 14.5 15.6193 14.5 17V21.5C14.5 22.0523 14.9477 22.5 15.5 22.5H16.5C17.0523 22.5 17.5 22.0523 17.5 21.5V17.5H21.5C22.0523 17.5 22.5 17.0523 22.5 16.5V15.5C22.5 14.9477 22.0523 14.5 21.5 14.5H17Z" fill="currentColor"></path> <path d="M9.5 17C9.5 15.6193 8.38071 14.5 7 14.5H2.5C1.94772 14.5 1.5 14.9477 1.5 15.5V16.5C1.5 17.0523 1.94772 17.5 2.5 17.5H6.5V21.5C6.5 22.0523 6.94772 22.5 7.5 22.5H8.5C9.05228 22.5 9.5 22.0523 9.5 21.5V17Z" fill="currentColor"></path></g>'
},
fsOpen: {
viewBox: '0 0 24 24',
html: '<g><path d="M4 1.5C2.61929 1.5 1.5 2.61929 1.5 4V8.5C1.5 9.05228 1.94772 9.5 2.5 9.5H3.5C4.05228 9.5 4.5 9.05228 4.5 8.5V4.5H8.5C9.05228 4.5 9.5 4.05228 9.5 3.5V2.5C9.5 1.94772 9.05228 1.5 8.5 1.5H4Z" fill="currentColor"></path> <path d="M20 1.5C21.3807 1.5 22.5 2.61929 22.5 4V8.5C22.5 9.05228 22.0523 9.5 21.5 9.5H20.5C19.9477 9.5 19.5 9.05228 19.5 8.5V4.5H15.5C14.9477 4.5 14.5 4.05228 14.5 3.5V2.5C14.5 1.94772 14.9477 1.5 15.5 1.5H20Z" fill="currentColor"></path> <path d="M20 22.5C21.3807 22.5 22.5 21.3807 22.5 20V15.5C22.5 14.9477 22.0523 14.5 21.5 14.5H20.5C19.9477 14.5 19.5 14.9477 19.5 15.5V19.5H15.5C14.9477 19.5 14.5 19.9477 14.5 20.5V21.5C14.5 22.0523 14.9477 22.5 15.5 22.5H20Z" fill="currentColor"></path> <path d="M1.5 20C1.5 21.3807 2.61929 22.5 4 22.5H8.5C9.05228 22.5 9.5 22.0523 9.5 21.5V20.5C9.5 19.9477 9.05228 19.5 8.5 19.5H4.5V15.5C4.5 14.9477 4.05228 14.5 3.5 14.5H2.5C1.94772 14.5 1.5 14.9477 1.5 15.5V20Z" fill="currentColor"></path></g>'
},
fullscreen: {
viewBox: '0 0 96 96',
html: '<g><path d="M30,0H6A5.9966,5.9966,0,0,0,0,6V30a6,6,0,0,0,12,0V12H30A6,6,0,0,0,30,0Z"/><path d="M90,0H66a6,6,0,0,0,0,12H84V30a6,6,0,0,0,12,0V6A5.9966,5.9966,0,0,0,90,0Z"/><path d="M30,84H12V66A6,6,0,0,0,0,66V90a5.9966,5.9966,0,0,0,6,6H30a6,6,0,0,0,0-12Z"/><path d="M90,60a5.9966,5.9966,0,0,0-6,6V84H66a6,6,0,0,0,0,12H90a5.9966,5.9966,0,0,0,6-6V66A5.9966,5.9966,0,0,0,90,60Z"/></g>'
},
gf: {
viewBox: '0 0 510.4 510.4',
html: '<g><path d="M505.2,80c-6.4-6.4-16-6.4-22.4,0l-89.6,89.6c-1.6,1.6-6.4,3.2-12.8,1.6c-4.8-1.6-9.6-3.2-14.4-6.4L468.4,62.4 c6.4-6.4,6.4-16,0-22.4c-6.4-6.4-16-6.4-22.4,0L343.6,142.4c-3.2-4.8-4.8-9.6-4.8-12.8c-1.6-6.4-1.6-11.2,1.6-12.8L430,27.2 c6.4-6.4,6.4-16,0-22.4c-6.4-6.4-16-6.4-22.4,0L290.8,121.6c-16,16-20.8,40-14.4,62.4l-264,256c-16,16-16,43.2,0,59.2 c6.4,6.4,16,11.2,27.2,11.2c11.2,0,22.4-4.8,30.4-12.8L319.6,232c8,3.2,16,4.8,24,4.8c16,0,32-6.4,44.8-17.6l116.8-116.8 C511.6,96,511.6,86.4,505.2,80z M46,475.2c-3.2,3.2-9.6,3.2-14.4,0c-3.2-3.2-3.2-9.6,1.6-12.8l257.6-249.6c0,0,1.6,1.6,1.6,3.2 L46,475.2z M316.4,192c-14.4-14.4-16-35.2-4.8-48c4.8,11.2,11.2,22.4,20.8,32c9.6,9.6,20.8,16,32,20.8 C351.6,208,329.2,206.4,316.4,192z"/></g>'
},
gh: {
viewBox: '0 0 16 16',
html: '<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>'
},
hide: {
viewBox: '0 0 24 24',
html: '<g> <path fill-rule="evenodd" clip-rule="evenodd" d="M2 11.5C2 10.9477 2.44772 10.5 3 10.5L21 10.5C21.5523 10.5 22 10.9477 22 11.5V12.5C22 13.0523 21.5523 13.5 21 13.5H3C2.44772 13.5 2 13.0523 2 12.5V11.5Z" fill="currentColor"></path></g>'
},
install: {
viewBox: '0 0 16 16',
html: '<g><path d="M8.75 1.75a.75.75 0 00-1.5 0v6.59L5.3 6.24a.75.75 0 10-1.1 1.02L7.45 10.76a.78.78 0 00.038.038.748.748 0 001.063-.037l3.25-3.5a.75.75 0 10-1.1-1.02l-1.95 2.1V1.75z"/><path d="M1.75 9a.75.75 0 01.75.75v3c0 .414.336.75.75.75h9.5a.75.75 0 00.75-.75v-3a.75.75 0 011.5 0v3A2.25 2.25 0 0112.75 15h-9.5A2.25 2.25 0 011 12.75v-3A.75.75 0 011.75 9z"/></g>'
},
issue: {
viewBox: '0 0 24 24',
html: '<path fill="none" stroke="#ffff" stroke-width="2" d="M23,20 C21.62,17.91 20,17 19,17 M5,17 C4,17 2.38,17.91 1,20 M19,9 C22,9 23,6 23,6 M1,6 C1,6 2,9 5,9 M19,13 L24,13 L19,13 Z M5,13 L0,13 L5,13 Z M12,23 L12,12 L12,23 L12,23 Z M12,23 C8,22.9999998 5,20.0000002 5,16 L5,9 C5,9 8,6.988 12,7 C16,7.012 19,9 19,9 C19,9 19,11.9999998 19,16 C19,20.0000002 16,23.0000002 12,23 L12,23 Z M7,8 L7,6 C7,3.24 9.24,1 12,1 C14.76,1 17,3.24 17,6 L17,8"/>'
},
nav: {
viewBox: '0 0 24 24',
html: '<g><path d="M2 5.5C2 4.94772 2.44772 4.5 3 4.5H21C21.5523 4.5 22 4.94772 22 5.5V6.5C22 7.05228 21.5523 7.5 21 7.5H3C2.44772 7.5 2 7.05228 2 6.5V5.5Z" fill="currentColor"></path> <path d="M2 11.5C2 10.9477 2.44772 10.5 3 10.5H21C21.5523 10.5 22 10.9477 22 11.5V12.5C22 13.0523 21.5523 13.5 21 13.5H3C2.44772 13.5 2 13.0523 2 12.5V11.5Z" fill="currentColor"></path><path d="M3 16.5C2.44772 16.5 2 16.9477 2 17.5V18.5C2 19.0523 2.44772 19.5 3 19.5H21C21.5523 19.5 22 19.0523 22 18.5V17.5C22 16.9477 21.5523 16.5 21 16.5H3Z" fill="currentColor"></path></g>'
},
plus: {
viewBox: '0 0 24 24',
html: '<g><path d="M13.5 3C13.5 2.44772 13.0523 2 12.5 2H11.5C10.9477 2 10.5 2.44772 10.5 3V10.5H3C2.44772 10.5 2 10.9477 2 11.5V12.5C2 13.0523 2.44772 13.5 3 13.5H10.5V21C10.5 21.5523 10.9477 22 11.5 22H12.5C13.0523 22 13.5 21.5523 13.5 21V13.5H21C21.5523 13.5 22 13.0523 22 12.5V11.5C22 10.9477 21.5523 10.5 21 10.5H13.5V3Z" fill="currentColor"/></g>'
},
search: {
viewBox: '0 0 24 24',
html: '<g><path fill-rule="evenodd" clip-rule="evenodd" d="M10 0.5C4.75329 0.5 0.5 4.75329 0.5 10C0.5 15.2467 4.75329 19.5 10 19.5C12.082 19.5 14.0076 18.8302 15.5731 17.6944L20.2929 22.4142C20.6834 22.8047 21.3166 22.8047 21.7071 22.4142L22.4142 21.7071C22.8047 21.3166 22.8047 20.6834 22.4142 20.2929L17.6944 15.5731C18.8302 14.0076 19.5 12.082 19.5 10C19.5 4.75329 15.2467 0.5 10 0.5ZM3.5 10C3.5 6.41015 6.41015 3.5 10 3.5C13.5899 3.5 16.5 6.41015 16.5 10C16.5 13.5899 13.5899 16.5 10 16.5C6.41015 16.5 3.5 13.5899 3.5 10Z" fill="currentColor"/></g>'
},
verified: {
viewBox: '0 0 56 56',
fill: 'currentColor',
stroke: 'currentColor',
html: '<g stroke-width="0"/><g stroke-linecap="round" stroke-linejoin="round"/><g><path d="M 23.6641 52.3985 C 26.6407 55.375 29.3594 55.3516 32.3126 52.3985 L 35.9219 48.8125 C 36.2969 48.4610 36.6250 48.3203 37.1172 48.3203 L 42.1797 48.3203 C 46.3749 48.3203 48.3204 46.3985 48.3204 42.1797 L 48.3204 37.1172 C 48.3204 36.625 48.4610 36.2969 48.8124 35.9219 L 52.3749 32.3125 C 55.3749 29.3594 55.3514 26.6407 52.3749 23.6641 L 48.8124 20.0547 C 48.4610 19.7031 48.3204 19.3516 48.3204 18.8829 L 48.3204 13.7969 C 48.3204 9.625 46.3985 7.6563 42.1797 7.6563 L 37.1172 7.6563 C 36.6250 7.6563 36.2969 7.5391 35.9219 7.1875 L 32.3126 3.6016 C 29.3594 .6250 26.6407 .6485 23.6641 3.6016 L 20.0547 7.1875 C 19.7032 7.5391 19.3516 7.6563 18.8828 7.6563 L 13.7969 7.6563 C 9.6016 7.6563 7.6563 9.5782 7.6563 13.7969 L 7.6563 18.8829 C 7.6563 19.3516 7.5391 19.7031 7.1876 20.0547 L 3.6016 23.6641 C .6251 26.6407 .6485 29.3594 3.6016 32.3125 L 7.1876 35.9219 C 7.5391 36.2969 7.6563 36.625 7.6563 37.1172 L 7.6563 42.1797 C 7.6563 46.3750 9.6016 48.3203 13.7969 48.3203 L 18.8828 48.3203 C 19.3516 48.3203 19.7032 48.4610 20.0547 48.8125 Z M 26.2891 49.7734 L 21.8828 45.3438 C 21.3672 44.8047 20.8282 44.5938 20.1016 44.5938 L 13.7969 44.5938 C 11.7110 44.5938 11.3828 44.2656 11.3828 42.1797 L 11.3828 35.875 C 11.3828 35.1719 11.1719 34.6329 10.6563 34.1172 L 6.2266 29.7109 C 4.7501 28.2109 4.7501 27.7891 6.2266 26.2891 L 10.6563 21.8829 C 11.1719 21.3672 11.3828 20.8282 11.3828 20.1016 L 11.3828 13.7969 C 11.3828 11.6875 11.6876 11.3829 13.7969 11.3829 L 20.1016 11.3829 C 20.8282 11.3829 21.3672 11.1953 21.8828 10.6563 L 26.2891 6.2266 C 27.7891 4.7500 28.2110 4.7500 29.7110 6.2266 L 34.1172 10.6563 C 34.6328 11.1953 35.1719 11.3829 35.8750 11.3829 L 42.1797 11.3829 C 44.2657 11.3829 44.5938 11.7109 44.5938 13.7969 L 44.5938 20.1016 C 44.5938 20.8282 44.8282 21.3672 45.3439 21.8829 L 49.7733 26.2891 C 51.2498 27.7891 51.2498 28.2109 49.7733 29.7109 L 45.3439 34.1172 C 44.8282 34.6329 44.5938 35.1719 44.5938 35.875 L 44.5938 42.1797 C 44.5938 44.2656 44.2657 44.5938 42.1797 44.5938 L 35.8750 44.5938 C 35.1719 44.5938 34.6328 44.8047 34.1172 45.3438 L 29.7110 49.7734 C 28.2110 51.2500 27.7891 51.2500 26.2891 49.7734 Z M 24.3438 39.2266 C 25.0235 39.2266 25.5391 38.9453 25.8907 38.5234 L 38.8985 20.3360 C 39.1563 19.9609 39.2969 19.5391 39.2969 19.1407 C 39.2969 18.1094 38.5001 17.2891 37.4219 17.2891 C 36.6485 17.2891 36.2266 17.5469 35.7579 18.2266 L 24.2735 34.3985 L 18.3438 27.8594 C 17.9454 27.4141 17.5001 27.2266 16.9141 27.2266 C 15.7657 27.2266 14.9454 28.0000 14.9454 29.0782 C 14.9454 29.5469 15.1094 29.9922 15.4376 30.3203 L 22.8907 38.6172 C 23.2423 38.9922 23.6876 39.2266 24.3438 39.2266 Z"/></g>'
},
load(type, container) {
const safe = safeSelf();
const svgElem = safe.createElementNS('http://www.w3.org/2000/svg', 'svg');
for (const [k, v] of Object.entries(iconSVG[type])) {
if (k === 'html') {
continue;
}
svgElem.setAttributeNS(null, k, v);
}
if (typeof iconSVG[type].html === 'string') {
svgElem.innerHTML = iconSVG[type].html;
}
if (container) {
container.appendChild(svgElem);
return svgElem;
}
return svgElem.outerHTML;
}
};
/**
* @type { import("../typings/UserJS.d.ts").StorageSystem }
*/
const StorageSystem = {
getItem(key) {
return window.localStorage.getItem(key);
},
has(key) {
return !isNull(this.getItem(key));
},
setItem(key, value) {
window.localStorage.setItem(key, value);
},
remove(key) {
window.localStorage.removeItem(key);
},
async setValue(key, v) {
v = typeof v === 'string' ? v : JSON.stringify(v ?? {});
if (isGM) {
if (isFN(GM.setValue)) {
await GM.setValue(key, v);
} else if (isFN(GM_setValue)) {
GM_setValue(key, v);
}
} else {
this.setItem(`MUJS-${key}`, v);
}
},
async getValue(key, def = {}) {
try {
if (isGM) {
let GMType;
if (isFN(GM.getValue)) {
GMType = await GM.getValue(key, JSON.stringify(def));
} else if (isFN(GM_getValue)) {
GMType = GM_getValue(key, JSON.stringify(def));
}
if (!isNull(GMType)) {
return JSON.parse(GMType);
}
}
return this.has(`MUJS-${key}`) ? JSON.parse(this.getItem(`MUJS-${key}`)) : def;
} catch (ex) {
err(ex);
}
}
};
/**
* @type { import("../typings/UserJS.d.ts").Network }
*/
const Network = {
async req(url, method = 'GET', responseType = 'json', data = {}, useFetch = false) {
if (isEmpty(url)) {
throw new Error('"url" parameter is empty');
}
method = Network.bscStr(method, false);
responseType = Network.bscStr(responseType);
const params = {
method,
...data
};
if (params.hermes) {
delete params.hermes;
}
if (isGM && !useFetch) {
if (params.credentials) {
Object.assign(params, {
anonymous: false
});
if (Object.is(params.credentials, 'omit')) {
Object.assign(params, {
anonymous: true
});
}
delete params.credentials;
}
} else if (params.onprogress) {
delete params.onprogress;
}
return await new Promise((resolve, reject) => {
if (isGM && !useFetch) {
Network.xmlRequest({
url,
responseType,
...params,
onerror: reject,
onload: (r_1) => {
if (r_1.status !== 200) reject(new Error(`${r_1.status} ${url}`));
if (responseType.match(/basic/)) resolve(r_1);
resolve(r_1.response);
}
});
} else {
fetch(url, params)
.then((response_1) => {
if (!response_1.ok) reject(response_1);
const check = (str_2 = 'text') => {
return isFN(response_1[str_2]) ? response_1[str_2]() : response_1;
};
if (responseType.match(/buffer/)) {
resolve(check('arrayBuffer'));
} else if (responseType.match(/json/)) {
resolve(check('json'));
} else if (responseType.match(/text/)) {
resolve(check('text'));
} else if (responseType.match(/blob/)) {
resolve(check('blob'));
} else if (responseType.match(/formdata/)) {
resolve(check('formData'));
} else if (responseType.match(/clone/)) {
resolve(check('clone'));
} else if (responseType.match(/document/)) {
const domParser = new DOMParser();
const respTxt = check('text');
if (respTxt instanceof Promise) {
respTxt.then((txt) => {
const doc = domParser.parseFromString(txt, 'text/html');
resolve(doc);
});
} else {
const doc = domParser.parseFromString(respTxt, 'text/html');
resolve(doc);
}
} else {
resolve(response_1);
}
})
.catch(reject);
}
});
},
format(bytes, decimals = 2) {
if (Number.isNaN(bytes)) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const i = Math.floor(Math.pow(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${Network.sizes[i]}`;
},
sizes: ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
async xmlRequest(details) {
if (isGM) {
if (isFN(GM.xmlHttpRequest)) {
return GM.xmlHttpRequest(details);
} else if (isFN(GM_xmlhttpRequest)) {
return GM_xmlhttpRequest(details);
}
}
const safe = safeSelf();
return await new Promise((resolve, reject) => {
const req = new safe.XMLHttpRequest();
let method = 'GET';
let url = 'about:blank';
let body;
for (const [key, value] of Object.entries(details)) {
if (key === 'onload') {
req.addEventListener('load', () => {
if (isFN(value)) {
value(req);
}
resolve(req);
});
} else if (key === 'onerror') {
req.addEventListener('error', (evt) => {
if (isFN(value)) {
value(evt);
}
reject(evt);
});
} else if (key === 'onabort') {
req.addEventListener('abort', (evt) => {
if (isFN(value)) {
value(evt);
}
reject(evt);
});
} else if (key === 'onprogress') {
req.addEventListener('progress', value);
} else if (key === 'responseType') {
if (value === 'buffer') {
req.responseType = 'arraybuffer';
} else {
req.responseType = value;
}
} else if (key === 'method') {
method = value;
} else if (key === 'url') {
url = value;
} else if (key === 'body') {
body = value;
}
}
req.open(method, url);
if (isEmpty(req.responseType)) {
req.responseType = 'text';
}
if (body) {
req.send(body);
} else {
req.send();
}
});
},
bscStr(str = '', lowerCase = true) {
const txt = str[lowerCase ? 'toLowerCase' : 'toUpperCase']();
return txt.replaceAll(/\W/g, '');
}
};
/**
* @type { import("../typings/UserJS.d.ts").qs }
*/
const qs = (selector, root) => {
try {
return (root || document).querySelector(selector);
} catch (ex) {
err(ex);
}
return null;
};
/**
* @type { import("../typings/UserJS.d.ts").qsA }
*/
const qsA = (selectors, root) => {
try {
return (root || document).querySelectorAll(selectors);
} catch (ex) {
err(ex);
}
return [];
};
const sleazyRedirect = () => {
const { hostname } = winLocation;
const gfSite = /greasyfork\.org/.test(hostname);
if (!gfSite && cfg.sleazyredirect) {
return;
}
const otherSite = gfSite ? 'sleazyfork' : 'greasyfork';
if (!qs('span.sign-in-link')) {
return;
}
if (!/scripts\/\d+/.test(winLocation.href)) {
return;
}
if (
!qs('#script-info') &&
(otherSite == 'greasyfork' || qs('div.width-constraint>section>p>a'))
) {
const str = winLocation.href.replace(
/\/\/([^.]+\.)?(greasyfork|sleazyfork)\.org/,
'//$1' + otherSite + '.org'
);
if (isFN(winLocation.assign)) {
winLocation.assign(str);
} else {
winLocation.href = str;
}
}
};
const intersect = (a = [], b = []) => {
for (const v of a) {
if (b.includes(v)) {
return true;
}
}
for (const v of b) {
if (a.includes(v)) {
return true;
}
}
return false;
};
// #region Container
class initContainer {
constructor(url) {
this.remove = this.remove.bind(this);
this.webpage = strToURL(url);
this.host = this.getHost(this.webpage.host);
this.domain = this.getDomain(this.webpage.host);
this.ready = false;
this.injected = false;
this.shadowRoot = undefined;
this.supported = isFN(make('main-userjs').attachShadow);
this.frame = this.supported
? make('main-userjs', '', {
dataset: {
insertedBy: $info.script.name,
role: 'primary-container'
}
})
: make('iframe', 'mujs-iframe', {
dataset: {
insertedBy: $info.script.name,
role: 'primary-iframe'
},
loading: 'lazy',
src: 'about:blank',
style:
'position: fixed;bottom: 1rem;right: 1rem;height: 525px;width: 90%;margin: 0px 1rem;z-index: 100000000000000020 !important;',
onload: (iFrame) => {
/**
* @type { HTMLIFrameElement }
*/
const target = iFrame.target;
if (!target.contentDocument) {
return;
}
this.shadowRoot = target.contentDocument.documentElement;
this.ready = true;
dom.cl.add([this.shadowRoot, target.contentDocument.body], 'mujs-iframe');
}
});
if (this.supported) {
/**
* @type { ShadowRoot }
*/
this.shadowRoot = this.frame.attachShadow({
mode: 'open',
clonable: false,
delegatesfocus: false
});
this.ready = true;
}
this.cache = memory.store.get('container');
this.userjsCache = memory.store.get('userjs');
this.root = make('mujs-root');
this.unsaved = false;
this.isBlacklisted = false;
this.rebuild = false;
this.counters = {
total: 0
};
this.opacityMin = '0.15';
this.opacityMax = '1';
this.Timeout = class {
constructor() {
this.ids = [];
}
set(delay, reason) {
return new Promise((resolve, reject) => {
const id = setTimeout(() => {
Object.is(reason, null) || Object.is(reason, undefined) ? resolve() : reject(reason);
this.clear(id);
}, delay);
this.ids.push(id);
});
}
clear(...ids) {
this.ids = this.ids.filter((id) => {
if (ids.includes(id)) {
clearTimeout(id);
return false;
}
return true;
});
}
};
window.addEventListener('beforeunload', this.remove);
}
/**
* @param { Function } callback
* @param { Document } doc
*/
async inject(callback, doc) {
if (this.checkBlacklist(this.host)) {
err('Blacklisted website');
this.remove();
return;
}
if (!this.shadowRoot) {
return;
}
if (!doc) {
return;
}
while (this.ready === false) {
await new Promise((resolve) => requestAnimationFrame(resolve));
}
try {
doc.documentElement.appendChild(this.frame);
if (this.injected) {
return;
}
this.shadowRoot.append(this.root);
if (isNull(this.loadCSS(main_css, 'primary-stylesheet'))) {
throw new Error('Failed to initialize script!', { cause: 'loadCSS' });
}
this.injected = true;
if (isFN(callback)) {
callback.call(this, this.shadowRoot);
}
} catch (ex) {
err(ex);
this.remove();
}
}
remove() {
memory.store.clear();
if (this.frame) {
this.frame.remove();
}
}
async save() {
this.unsaved = false;
await StorageSystem.setValue('Config', cfg);