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
4233 lines (4165 loc) · 143 KB
/
Copy pathmain.js
File metadata and controls
4233 lines (4165 loc) · 143 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
// #region Console
const con = {
title: '[%cMagic Userscript+%c]',
color: 'color: rgb(29, 155, 240);',
dbg(...msg) {
const dt = new Date();
console.debug(
`${con.title} %cDBG`,
con.color,
'',
'color: rgb(255, 212, 0);',
`[${dt.getHours()}:${('0' + dt.getMinutes()).slice(-2)}:${('0' + dt.getSeconds()).slice(-2)}]`,
...msg
);
},
err(...msg) {
console.error(`${con.title} %cERROR`, con.color, '', 'color: rgb(249, 24, 128);', ...msg);
const a = typeof alert !== 'undefined' && alert;
const t = con.title.replace(/%c/g, '');
for (const ex of msg) {
if (typeof ex === 'object' && 'cause' in ex && a) {
a(`${t} (${ex.cause}) ${ex.message}`);
}
}
},
info(...msg) {
console.info(`${con.title} %cINF`, con.color, '', 'color: rgb(0, 186, 124);', ...msg);
},
log(...msg) {
console.log(`${con.title} %cLOG`, con.color, '', 'color: rgb(219, 160, 73);', ...msg);
}
};
const { err, info } = con;
// #endregion
/**
* @type { import("../typings/types.d.ts").config }
*/
let cfg;
const BLANK_FN = function () {};
const BLANK_ASYNC_FN = async function () {};
const BLANK_PAGE = 'about:blank';
/**
* @param {string} hn
*/
const normalizedHostname = (hn) => hn.replace(/^www\./, '');
/**
* @param {string} txt
*/
const formatURL = (txt) =>
txt
.split('.')
.splice(-2)
.join('.')
.replace(/\/|https:/g, '');
/**
* @param {string} str
*/
const getHostname = (str) => formatURL(normalizedHostname(str));
/**
* @type {URL | undefined}
*/
let url;
try {
url = new URL(window.location.href ?? BLANK_PAGE);
} catch {
/* empty */
}
// #region Validators
const objToStr = (obj) => Object.prototype.toString.call(obj);
const isRegExp = (obj) => /RegExp/.test(objToStr(obj));
const isElem = (obj) => /Element/.test(objToStr(obj));
const isHTML = (obj) => /object HTML/.test(objToStr(obj));
const isObj = (obj) => /Object/.test(objToStr(obj));
const isFN = (obj) => /Function/.test(objToStr(obj));
const isUserCSS = (str) => /\.user\.css$/.test(str);
const isUserJS = (str) => /\.user\.js$/.test(str);
/**
* @type { import("../typings/types.d.ts").isNull }
*/
const isNull = (obj) => {
return Object.is(obj, null) || Object.is(obj, undefined);
};
/**
* @type { import("../typings/types.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/types.d.ts").isEmpty }
*/
const isEmpty = (obj) => {
return isNull(obj) || isBlank(obj);
};
// #endregion
// #region Globals
/**
* https://github.com/zloirock/core-js/blob/master/packages/core-js/internals/global-this.js
* @returns {typeof globalThis}
*/
function globalWin() {
const check = function (it) {
return it && it.Math === Math && it;
};
return (
check(typeof globalThis == 'object' && globalThis) ||
check(typeof window == 'object' && window) ||
check(typeof self == 'object' && self) ||
check(typeof this == 'object' && this) ||
(function () {
return this;
})() ||
Function('return this')()
);
}
class Safe {
/** @type { import("../typings/UserJS.d.ts").safeHandles } */
_safe;
create() {
try {
const g = globalWin();
/** @type { import("../typings/UserJS.d.ts").safeHandles } */
const safe = {
XMLHttpRequest: g.XMLHttpRequest,
CustomEvent: g.CustomEvent,
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,
navigator: g.navigator,
scheduler: {
postTask(callback, options) {
if ('scheduler' in g && 'postTask' in g.scheduler) {
return g.scheduler.postTask(callback, options);
}
options = Object.assign({}, options);
if (options.delay === undefined) options.delay = 0;
options.delay = Number(options.delay);
if (options.delay < 0) {
return Promise.reject(new TypeError('"delay" must be a positive number.'));
}
return new Promise((resolve) => {
g.setTimeout(() => {
resolve(callback());
}, options.delay);
});
},
yield() {
if ('scheduler' in g && 'yield' in g.scheduler) {
scheduler.yield();
return g.scheduler.yield();
}
return new Promise((resolve) => {
g.setTimeout(resolve, 0);
});
}
},
groupBy(arr, callback) {
if (isFN(Object.groupBy)) {
return Object.groupBy(arr, callback);
}
/** [Object.groupBy polyfill](https://gist.github.com/gtrabanco/7c97bd41aa74af974fa935bfb5044b6e) */
return arr.reduce((acc = {}, ...args) => {
const key = callback(...args);
acc[key] ??= [];
acc[key].push(args[0]);
return acc;
}, {});
}
};
for (const [k, v] of Object.entries(safe)) {
if (/scheduler|navigator/.test(k) || isFN(v)) continue;
throw new Error(`Safe handles "${k}" returned "${v}"`, { cause: 'safeSelf' });
}
this._safe = safe;
} catch (e) {
err(e);
this._safe = null;
}
return this._safe;
}
get _self() {
return this._safe ?? this.create();
}
set _self(obj) {
this._safe = obj;
}
}
const { _self } = new Safe();
// #endregion
// #region Constants
/**
* @type { import("../typings/types.d.ts").cfgBase }
*/
const cfgBase = [];
const cfgSec = new Set();
/** Lets highlight me :) */
const authorID = 166061;
/**
* Some UserJS I personally enjoy - `https://greasyfork.org/scripts/{id}`
*/
const goodUserJS = [
33005,
394820,
438684,
4870,
394420,
25068,
483444,
1682,
22587,
789,
28497,
386908,
24204,
404443,
4336,
368183,
393396,
473830,
12179,
423001,
376510,
23840,
40525,
6456,
'https://openuserjs.org/install/Patabugen/Always_Remember_Me.user.js',
'https://openuserjs.org/install/nokeya/Direct_links_out.user.js',
'https://github.com/jijirae/y2monkey/raw/main/y2monkey.user.js',
'https://github.com/jijirae/r2monkey/raw/main/r2monkey.user.js',
'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'
];
/** Remove UserJS from banned accounts */
const badUserJS = [478597];
/** Unsupport host for search engines */
const engineUnsupported = {
greasyfork: ['pornhub.com'],
sleazyfork: ['pornhub.com'],
openuserjs: [],
github: []
};
const isMobile = (() => {
if (userjs.isMobile !== undefined) {
return userjs.isMobile;
}
try {
const { navigator } = _self;
if (navigator) {
const { userAgent, userAgentData } = navigator;
const { platform, mobile } = userAgentData ? Object(userAgentData) : {};
userjs.isMobile =
/Mobile|Tablet/.test(userAgent ? String(userAgent) : '') ||
Boolean(mobile) ||
/Android|Apple/.test(platform ? String(platform) : '');
} else {
userjs.isMobile = false;
}
} catch (ex) {
userjs.isMobile = false;
ex.cause = 'getUAData';
err(ex);
}
return userjs.isMobile;
})();
const isGM = typeof GM !== 'undefined';
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/.+'
}
};
// #endregion
// #region DEFAULT_CONFIG
/**
* @type { import("../typings/types.d.ts").config }
*/
const DEFAULT_CONFIG = {
autofetch: true,
autoinject: true,
autoSort: 'daily_installs',
clearTabCache: true,
cache: true,
autoexpand: false,
filterlang: false,
sleazyredirect: false,
time: 10000,
blacklist: ['userjs-local', 'userjs-finance', 'userjs-social', 'userjs-unsupported'],
preview: {
code: false,
metadata: false
},
engines: [
{
enabled: true,
name: 'greasyfork',
query: encodeURIComponent('https://greasyfork.org/scripts/by-site/{host}.json?language=all')
},
{
enabled: false,
name: 'sleazyfork',
query: encodeURIComponent('https://sleazyfork.org/scripts/by-site/{host}.json?language=all')
},
{
enabled: false,
name: 'openuserjs',
query: encodeURIComponent('https://openuserjs.org/?q={host}')
},
{
enabled: false,
name: 'github',
token: '',
query: encodeURIComponent(
'https://api.github.com/search/repositories?q=topic:{domain}+topic:userscript'
)
}
],
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
},
filters: {
ASCII: {
enabled: false,
name: 'Non-ASCII',
regExp: '[^\\x00-\\x7F\\s]+'
},
Latin: {
enabled: false,
name: 'Non-Latin',
regExp: '[^\\u0000-\\u024F\\u2000-\\u214F\\s]+'
},
Games: {
enabled: false,
name: 'Games',
flag: 'iu',
regExp:
'Aimbot|AntiGame|Agar|agar\\.io|alis\\.io|angel\\.io|ExtencionRipXChetoMalo|AposBot|DFxLite|ZTx-Lite|AposFeedingBot|AposLoader|Balz|Blah Blah|Orc Clan Script|Astro\\s*Empires|^\\s*Attack|^\\s*Battle|BiteFight|Blood\\s*Wars|Bloble|Bonk|Bots|Bots4|Brawler|\\bBvS\\b|Business\\s*Tycoon|Castle\\s*Age|City\\s*Ville|chopcoin\\.io|Comunio|Conquer\\s*Club|CosmoPulse|cursors\\.io|Dark\\s*Orbit|Dead\\s*Frontier|Diep\\.io|\\bDOA\\b|doblons\\.io|DotD|Dossergame|Dragons\\s*of\\s*Atlantis|driftin\\.io|Dugout|\\bDS[a-z]+\\n|elites\\.io|Empire\\s*Board|eRep(ublik)?|Epicmafia|Epic.*War|ExoPlanet|Falcon Tools|Feuerwache|Farming|FarmVille|Fightinfo|Frontier\\s*Ville|Ghost\\s*Trapper|Gladiatus|Goalline|Gondal|gota\\.io|Grepolis|Hobopolis|\\bhwm(\\b|_)|Ikariam|\\bIT2\\b|Jellyneo|Kapi\\s*Hospital|Kings\\s*Age|Kingdoms?\\s*of|knastv(o|oe)gel|Knight\\s*Fight|\\b(Power)?KoC(Atta?ck)?\\b|\\bKOL\\b|Kongregate|Krunker|Last\\s*Emperor|Legends?\\s*of|Light\\s*Rising|lite\\.ext\\.io|Lockerz|\\bLoU\\b|Mafia\\s*(Wars|Mofo)|Menelgame|Mob\\s*Wars|Mouse\\s*Hunt|Molehill\\s*Empire|MooMoo|MyFreeFarm|narwhale\\.io|Neopets|NeoQuest|Nemexia|\\bOGame\\b|Ogar(io)?|Pardus|Pennergame|Pigskin\\s*Empire|PlayerScripts|pokeradar\\.io|Popmundo|Po?we?r\\s*(Bot|Tools)|PsicoTSI|Ravenwood|Schulterglatze|Skribbl|slither\\.io|slitherplus\\.io|slitheriogameplay|SpaceWars|splix\\.io|Survivio|\\bSW_[a-z]+\\n|\\bSnP\\b|The\\s*Crims|The\\s*West|torto\\.io|Travian|Treasure\\s*Isl(and|e)|Tribal\\s*Wars|TW.?PRO|Vampire\\s*Wars|vertix\\.io|War\\s*of\\s*Ninja|World\\s*of\\s*Tanks|West\\s*Wars|wings\\.io|\\bWoD\\b|World\\s*of\\s*Dungeons|wtf\\s*battles|Wurzelimperium|Yohoho|Zombs'
},
SocialNetworks: {
enabled: false,
name: 'Social Networks',
flag: 'iu',
regExp:
'Face\\s*book|Google(\\+| Plus)|\\bHabbo|Kaskus|\\bLepra|Leprosorium|MySpace|meinVZ|odnoklassniki|Одноклассники|Orkut|sch(ue|ü)ler(VZ|\\.cc)?|studiVZ|Unfriend|Valenth|VK|vkontakte|ВКонтакте|Qzone|Twitter|TweetDeck'
},
Clutter: {
enabled: false,
name: 'Clutter',
flag: 'iu',
regExp:
"^\\s*(.{1,3})\\1+\\n|^\\s*(.+?)\\n+\\2\\n*$|^\\s*.{1,5}\\n|do\\s*n('|o)?t (install|download)|nicht installieren|(just )?(\\ban? |\\b)test(ing|s|\\d|\\b)|^\\s*.{0,4}test.{0,4}\\n|\\ntest(ing)?\\s*|^\\s*(\\{@|Smolka|Hacks)|\\[\\d{4,5}\\]|free\\s*download|theme|(night|dark) ?(mode)?"
}
}
};
// #endregion
// #region i18n
/** @type {Map<string, string>} */
const i18nMap = new Map();
class i18nHandler {
constructor() {
for (const [k, v] of Object.entries(translations)) {
if (!i18nMap.has(k)) i18nMap.set(k, v);
}
}
/**
* @param {string | Date | number} str
*/
toDate(str = '') {
const { navigator } = _self;
return new Intl.DateTimeFormat(navigator.language).format(
typeof str === 'string' ? new Date(str) : str
);
}
/**
* @param {number | bigint} number
*/
toNumber(number) {
const { navigator } = _self;
return new Intl.NumberFormat(navigator.language).format(number);
}
/**
* @type { import("../typings/UserJS.d.ts").i18n$ }
*/
i18n$(key) {
const { navigator } = _self;
const current = navigator.language.split('-')[0] ?? 'en';
try {
return i18nMap.get(current)?.[key] ?? 'Invalid Key';
} catch (e) {
err(e);
return 'error';
}
}
get current() {
const { navigator } = _self;
return navigator.language.split('-')[0] ?? 'en';
}
}
const language = new i18nHandler();
const { i18n$ } = language;
// #endregion
// #region Utilities
const union = (...arr) => [...new Set(arr.flat())];
/**
* @param {string} str
*/
const decode = (str) => {
try {
if (decodeURI(str) !== decodeURIComponent(str)) {
return decode(decodeURIComponent(str));
}
} catch (ex) {
err(ex);
}
return str;
};
/**
* @type { import("../typings/types.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)) : Array.of(target);
}
if (/object HTML/.test(Object.prototype.toString.call(target))) {
return Array.of(target);
}
return Array.from(target);
};
/**
* @type { import("../typings/types.d.ts").qs }
*/
const qs = (selector, root) => {
try {
return (root || document).querySelector(selector);
} catch (ex) {
err(ex);
}
return null;
};
/**
* @type { import("../typings/types.d.ts").qsA }
*/
const qsA = (selectors, root) => {
try {
return (root || document).querySelectorAll(selectors);
} catch (ex) {
err(ex);
}
return [];
};
/**
* @type { import("../typings/types.d.ts").ael }
*/
const ael = (el, type, listener, options = {}) => {
for (const elem of normalizeTarget(el).filter(isHTML)) {
if (isMobile && type === 'click') {
elem.addEventListener('touchstart', listener, options);
continue;
}
elem.addEventListener(type, listener, options);
}
};
/**
* @type { import("../typings/types.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/types.d.ts").make }
*/
const make = (tagName, cname, attrs) => {
let el;
try {
const { createElement } = _self;
el = createElement(tagName.toLowerCase());
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) {
if (ex instanceof DOMException) throw new Error(`${ex.name}: ${ex.message}`, { cause: 'make' });
ex.cause = 'make';
err(ex);
}
return el;
};
const $info = (() => {
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/raw/master/dist/magic-userjs.js',
version: 'Bookmarklet',
bugs: 'https://github.com/magicoflolis/Userscript-Plus/issues'
}
};
})();
// #endregion
/**
* @type { import("../typings/types.d.ts").dom }
*/
const dom = {
attr(target, attr, value = undefined) {
for (const elem of normalizeTarget(target).filter(isHTML)) {
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).filter(isHTML)) {
if (value === undefined) {
return elem[prop];
}
elem[prop] = value;
}
},
text(target, text) {
const targets = normalizeTarget(target).filter(isHTML);
if (text === undefined) {
return targets.length !== 0 ? targets[0].textContent : undefined;
}
for (const elem of targets) {
elem.textContent = text;
}
},
remove(target) {
normalizeTarget(target)
.filter(isHTML)
.some((elem) => elem.remove());
},
cl: {
add(target, token) {
token = normalizeTarget(token, false);
return normalizeTarget(target)
.filter(isHTML)
.some((elem) => elem.classList.add(...token));
},
remove(target, token) {
token = normalizeTarget(token, false);
return normalizeTarget(target)
.filter(isHTML)
.some((elem) => elem.classList.remove(...token));
},
toggle(target, token, force) {
let r;
for (const elem of normalizeTarget(target).filter(isHTML)) {
r = elem.classList.toggle(token, force);
}
return r;
},
has(target, token) {
return normalizeTarget(target)
.filter(isHTML)
.some((elem) => elem.classList.contains(token));
}
}
};
//#region Icon SVGs
const iconSVG = {
close: {
viewBox: '0 0 384 512',
html: '<path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/>'
},
code: {
viewBox: '0 0 640 512',
html: '<path d="M392.8 1.2c-17-4.9-34.7 5-39.6 22l-128 448c-4.9 17 5 34.7 22 39.6s34.7-5 39.6-22l128-448c4.9-17-5-34.7-22-39.6zm80.6 120.1c-12.5 12.5-12.5 32.8 0 45.3L562.7 256l-89.4 89.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l112-112c12.5-12.5 12.5-32.8 0-45.3l-112-112c-12.5-12.5-32.8-12.5-45.3 0zm-306.7 0c-12.5-12.5-32.8-12.5-45.3 0l-112 112c-12.5 12.5-12.5 32.8 0 45.3l112 112c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256l89.4-89.4c12.5-12.5 12.5-32.8 0-45.3z"/>'
},
collapse: {
viewBox: '0 0 448 512',
html: '<path d="M160 64c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 64-64 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l96 0c17.7 0 32-14.3 32-32l0-96zM32 320c-17.7 0-32 14.3-32 32s14.3 32 32 32l64 0 0 64c0 17.7 14.3 32 32 32s32-14.3 32-32l0-96c0-17.7-14.3-32-32-32l-96 0zM352 64c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 96c0 17.7 14.3 32 32 32l96 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-64 0 0-64zM320 320c-17.7 0-32 14.3-32 32l0 96c0 17.7 14.3 32 32 32s32-14.3 32-32l0-64 64 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-96 0z"/>'
},
download: {
viewBox: '0 0 384 512',
html: '<path d="M64 0C28.7 0 0 28.7 0 64L0 448c0 35.3 28.7 64 64 64l256 0c35.3 0 64-28.7 64-64l0-288-128 0c-17.7 0-32-14.3-32-32L224 0 64 0zM256 0l0 128 128 0L256 0zM216 232l0 102.1 31-31c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-72 72c-9.4 9.4-24.6 9.4-33.9 0l-72-72c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l31 31L168 232c0-13.3 10.7-24 24-24s24 10.7 24 24z"/>'
},
expand: {
viewBox: '0 0 448 512',
html: '<path d="M32 32C14.3 32 0 46.3 0 64l0 96c0 17.7 14.3 32 32 32s32-14.3 32-32l0-64 64 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 32zM64 352c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 96c0 17.7 14.3 32 32 32l96 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-64 0 0-64zM320 32c-17.7 0-32 14.3-32 32s14.3 32 32 32l64 0 0 64c0 17.7 14.3 32 32 32s32-14.3 32-32l0-96c0-17.7-14.3-32-32-32l-96 0zM448 352c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 64-64 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l96 0c17.7 0 32-14.3 32-32l0-96z"/>'
},
gear: {
viewBox: '0 0 512 512',
html: '<path d="M495.9 166.6c3.2 8.7 .5 18.4-6.4 24.6l-43.3 39.4c1.1 8.3 1.7 16.8 1.7 25.4s-.6 17.1-1.7 25.4l43.3 39.4c6.9 6.2 9.6 15.9 6.4 24.6c-4.4 11.9-9.7 23.3-15.8 34.3l-4.7 8.1c-6.6 11-14 21.4-22.1 31.2c-5.9 7.2-15.7 9.6-24.5 6.8l-55.7-17.7c-13.4 10.3-28.2 18.9-44 25.4l-12.5 57.1c-2 9.1-9 16.3-18.2 17.8c-13.8 2.3-28 3.5-42.5 3.5s-28.7-1.2-42.5-3.5c-9.2-1.5-16.2-8.7-18.2-17.8l-12.5-57.1c-15.8-6.5-30.6-15.1-44-25.4L83.1 425.9c-8.8 2.8-18.6 .3-24.5-6.8c-8.1-9.8-15.5-20.2-22.1-31.2l-4.7-8.1c-6.1-11-11.4-22.4-15.8-34.3c-3.2-8.7-.5-18.4 6.4-24.6l43.3-39.4C64.6 273.1 64 264.6 64 256s.6-17.1 1.7-25.4L22.4 191.2c-6.9-6.2-9.6-15.9-6.4-24.6c4.4-11.9 9.7-23.3 15.8-34.3l4.7-8.1c6.6-11 14-21.4 22.1-31.2c5.9-7.2 15.7-9.6 24.5-6.8l55.7 17.7c13.4-10.3 28.2-18.9 44-25.4l12.5-57.1c2-9.1 9-16.3 18.2-17.8C227.3 1.2 241.5 0 256 0s28.7 1.2 42.5 3.5c9.2 1.5 16.2 8.7 18.2 17.8l12.5 57.1c15.8 6.5 30.6 15.1 44 25.4l55.7-17.7c8.8-2.8 18.6-.3 24.5 6.8c8.1 9.8 15.5 20.2 22.1 31.2l4.7 8.1c6.1 11 11.4 22.4 15.8 34.3zM256 336a80 80 0 1 0 0-160 80 80 0 1 0 0 160z"/>'
},
github: {
viewBox: '0 0 496 512',
html: '<path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3 .3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5 .3-6.2 2.3zm44.2-1.7c-2.9 .7-4.9 2.6-4.6 4.9 .3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3 .7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3 .3 2.9 2.3 3.9 1.6 1 3.6 .7 4.3-.7 .7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3 .7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3 .7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/>'
},
globe: {
viewBox: '0 0 512 512',
html: '<path d="M352 256c0 22.2-1.2 43.6-3.3 64l-185.3 0c-2.2-20.4-3.3-41.8-3.3-64s1.2-43.6 3.3-64l185.3 0c2.2 20.4 3.3 41.8 3.3 64zm28.8-64l123.1 0c5.3 20.5 8.1 41.9 8.1 64s-2.8 43.5-8.1 64l-123.1 0c2.1-20.6 3.2-42 3.2-64s-1.1-43.4-3.2-64zm112.6-32l-116.7 0c-10-63.9-29.8-117.4-55.3-151.6c78.3 20.7 142 77.5 171.9 151.6zm-149.1 0l-176.6 0c6.1-36.4 15.5-68.6 27-94.7c10.5-23.6 22.2-40.7 33.5-51.5C239.4 3.2 248.7 0 256 0s16.6 3.2 27.8 13.8c11.3 10.8 23 27.9 33.5 51.5c11.6 26 20.9 58.2 27 94.7zm-209 0L18.6 160C48.6 85.9 112.2 29.1 190.6 8.4C165.1 42.6 145.3 96.1 135.3 160zM8.1 192l123.1 0c-2.1 20.6-3.2 42-3.2 64s1.1 43.4 3.2 64L8.1 320C2.8 299.5 0 278.1 0 256s2.8-43.5 8.1-64zM194.7 446.6c-11.6-26-20.9-58.2-27-94.6l176.6 0c-6.1 36.4-15.5 68.6-27 94.6c-10.5 23.6-22.2 40.7-33.5 51.5C272.6 508.8 263.3 512 256 512s-16.6-3.2-27.8-13.8c-11.3-10.8-23-27.9-33.5-51.5zM135.3 352c10 63.9 29.8 117.4 55.3 151.6C112.2 482.9 48.6 426.1 18.6 352l116.7 0zm358.1 0c-30 74.1-93.6 130.9-171.9 151.6c25.5-34.2 45.2-87.7 55.3-151.6l116.7 0z"/>'
},
install: {
viewBox: '0 0 512 512',
html: '<path d="M288 32c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 242.7-73.4-73.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l128 128c12.5 12.5 32.8 12.5 45.3 0l128-128c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L288 274.7 288 32zM64 352c-35.3 0-64 28.7-64 64l0 32c0 35.3 28.7 64 64 64l384 0c35.3 0 64-28.7 64-64l0-32c0-35.3-28.7-64-64-64l-101.5 0-45.3 45.3c-25 25-65.5 25-90.5 0L165.5 352 64 352zm368 56a24 24 0 1 1 0 48 24 24 0 1 1 0-48z"/>'
},
issue: {
viewBox: '0 0 512 512',
html: '<path d="M256 0c53 0 96 43 96 96l0 3.6c0 15.7-12.7 28.4-28.4 28.4l-135.1 0c-15.7 0-28.4-12.7-28.4-28.4l0-3.6c0-53 43-96 96-96zM41.4 105.4c12.5-12.5 32.8-12.5 45.3 0l64 64c.7 .7 1.3 1.4 1.9 2.1c14.2-7.3 30.4-11.4 47.5-11.4l112 0c17.1 0 33.2 4.1 47.5 11.4c.6-.7 1.2-1.4 1.9-2.1l64-64c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3l-64 64c-.7 .7-1.4 1.3-2.1 1.9c6.2 12 10.1 25.3 11.1 39.5l64.3 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-64 0c0 24.6-5.5 47.8-15.4 68.6c2.2 1.3 4.2 2.9 6 4.8l64 64c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0l-63.1-63.1c-24.5 21.8-55.8 36.2-90.3 39.6L272 240c0-8.8-7.2-16-16-16s-16 7.2-16 16l0 239.2c-34.5-3.4-65.8-17.8-90.3-39.6L86.6 502.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3l64-64c1.9-1.9 3.9-3.4 6-4.8C101.5 367.8 96 344.6 96 320l-64 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l64.3 0c1.1-14.1 5-27.5 11.1-39.5c-.7-.6-1.4-1.2-2.1-1.9l-64-64c-12.5-12.5-12.5-32.8 0-45.3z"/>'
},
minus: {
viewBox: '0 0 448 512',
html: '<path d="M432 256c0 17.7-14.3 32-32 32L48 288c-17.7 0-32-14.3-32-32s14.3-32 32-32l352 0c17.7 0 32 14.3 32 32z"/>'
},
nav: {
viewBox: '0 0 448 512',
html: '<path d="M0 96C0 78.3 14.3 64 32 64l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 128C14.3 128 0 113.7 0 96zM0 256c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 288c-17.7 0-32-14.3-32-32zM448 416c0 17.7-14.3 32-32 32L32 448c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"/>'
},
pager: {
viewBox: '0 0 512 512',
html: '<path d="M0 128C0 92.7 28.7 64 64 64l384 0c35.3 0 64 28.7 64 64l0 256c0 35.3-28.7 64-64 64L64 448c-35.3 0-64-28.7-64-64L0 128zm64 32l0 64c0 17.7 14.3 32 32 32l320 0c17.7 0 32-14.3 32-32l0-64c0-17.7-14.3-32-32-32L96 128c-17.7 0-32 14.3-32 32zM80 320c-13.3 0-24 10.7-24 24s10.7 24 24 24l56 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-56 0zm136 0c-13.3 0-24 10.7-24 24s10.7 24 24 24l48 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-48 0z"/>'
},
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>'
},
refresh: {
viewBox: '0 0 512 512',
fill: 'currentColor',
html: '<path d="M463.5 224l8.5 0c13.3 0 24-10.7 24-24l0-128c0-9.7-5.8-18.5-14.8-22.2s-19.3-1.7-26.2 5.2L413.4 96.6c-87.6-86.5-228.7-86.2-315.8 1c-87.5 87.5-87.5 229.3 0 316.8s229.3 87.5 316.8 0c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0c-62.5 62.5-163.8 62.5-226.3 0s-62.5-163.8 0-226.3c62.2-62.2 162.7-62.5 225.3-1L327 183c-6.9 6.9-8.9 17.2-5.2 26.2s12.5 14.8 22.2 14.8l119.5 0z"/>'
},
load(type, container) {
const { createElementNS } = _self;
const svgElem = 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);
}
try {
if (typeof iconSVG[type].html === 'string') {
svgElem.innerHTML = iconSVG[type].html;
svgElem.setAttribute('id', `mujs_${type ?? 'Unknown'}`);
}
// eslint-disable-next-line no-unused-vars
} catch (ex) {
/* empty */
}
if (container) {
container.appendChild(svgElem);
return svgElem;
}
return svgElem.outerHTML;
}
};
//#endregion
/**
* @type { import("../typings/UserJS.d.ts").StorageSystem }
*/
const StorageSystem = {
prefix: 'MUJS',
events: new Set(),
getItem(key) {
return window.localStorage.getItem(key);
},
has(key) {
return !this.getItem(key);
},
setItem(key, value) {
window.localStorage.setItem(key, value);
},
remove(key) {
window.localStorage.removeItem(key);
},
async setValue(key, v) {
if (!v) {
return;
}
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(`${this.prefix}-${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(`${this.prefix}-${key}`)
? JSON.parse(this.getItem(`${this.prefix}-${key}`))
: def;
} catch (ex) {
ex.cause = 'getValue';
err(ex);
return def;
}
}
};
const Command = {
cmds: new Set(),
register(text, command) {
if (!isGM) {
return;
}
if (isFN(command)) {
if (this.cmds.has(command)) {
return;
}
this.cmds.add(command);
}
if (isFN(GM.registerMenuCommand)) {
GM.registerMenuCommand(text, command);
} else if (isFN(GM_registerMenuCommand)) {
GM_registerMenuCommand(text, command);
}
}
};
/**
* @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');
}
data = Object.assign({}, data);
method = this.bscStr(method, false);
responseType = this.bscStr(responseType, true);
const params = {
method,
...data
};
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 new Promise((resolve, reject) => {
if (isGM && !useFetch) {
Network.xmlRequest({
url,
responseType,
...params,
onerror: (r_1) => {
reject(new Error(`${r_1.status} ${url}`));
},
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 respTxt = check('text');
const domParser = new DOMParser();
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 ${this.sizes[0]}`;
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${this.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);
}
}
return await new Promise((resolve, reject) => {
const { XMLHttpRequest } = _self;
const req = new XMLHttpRequest();
let method = 'GET';
let url = BLANK_PAGE;
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, '');
}
};
const Counter = {
cnt: {
total: {
count: 0
}
},
set(engine) {
if (!this.cnt[engine.name]) {
const counter = make('count-frame', engine.enabled ? '' : 'hidden', {
dataset: {
counter: engine.name
},
title: decode(engine.query ?? engine.url),
textContent: '0'
});
this.cnt[engine.name] = {
root: counter,
count: 0
};
return counter;
}