forked from F9y4ng/GreasyFork-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoogle & Baidu Switcher.user.js
3501 lines (3385 loc) · 218 KB
/
Google & Baidu Switcher.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 Google & baidu Switcher (ALL in One)
// @name:en Search Engine Assistant
// @name:zh-CN 优雅的搜索引擎助手
// @name:zh-TW 優雅的搜索引擎助手
// @name:ru Поисковый помощник
// @name:ja 優雅な検索エンジン助手
// @version 2024.02.03.1
// @author F9y4ng
// @description Le script est alias « Elegant Search Engine Assistant », ce qui permet à l'utilisateur de passer d'un moteur de recherche à l'autre ; prise en charge de la personnalisation des moteurs de recherche couramment utilisés, effet de rendu de mise en évidence des mots clés ; fournit également la suppression de la redirection des liens de recherche, protégeant les résultats de recherche des annonces, les paramètres visuels, la détection automatique des mises à jour et d'autres fonctionnalités avancées ; compatible avec un certain nombre de moteurs de recherche connus, tels que Baidu, Google, Bing, Duckduckgo, Sogou, Wuzhuiso, Yandex, 360so, Toutiao, Baidu.dev, Ecosia, Yahoo, You, Startpage, Brave, Yep, Swisscows, etc.
// @description:en "Elegant search engine assistant" facilitates users to jump between different search engines; supports custom commonly used search engines and search keyword highlighting effects; provides advanced functions such as removing search link redirection, blocking search results advertisements, etc.; it is compatible with well-known search engines such as Baidu, Google, Bing, Duckduckgo, Yandex, Sogou, Ecosia, You, Startpage, Brave, etc.
// @description:zh-CN “优雅的搜索引擎助手”方便用户在不同的搜索引擎之间跳转;支持自定义常用搜索引擎、关键词高亮渲染效果;还提供去除搜索链接重定向、屏蔽搜索结果广告、可视化参数设置、及自动更新检测等高级功能;兼容多个知名搜索引擎,如Baidu、Google、Bing、Duckduckgo、Yandex、Sogou、Ecosia、You、Startpage、Brave等。
// @description:zh-TW 「優雅的搜索引擎助手」方便用戶在不同的搜索引擎之間跳轉;支持自定義常用搜索引擎、關鍵詞高亮渲染效果;還提供去除搜索鏈接重定嚮、屏蔽搜索結果廣告、可視化參數設置、及自動更新檢測等高級功能;兼容多個知名搜索引擎,如Baidu、Google、Bing、Duckduckgo、Yandex、Sogou、Ecosia、You、Startpage、Brave等。
// @description:ru "Поисковый помощник" облегчает пользователям переход между различными поисковыми системами; поддерживает пользовательские широко используемые поисковые системы и эффекты подсветки ключевых слов; предоставляет расширенные функции, такие как удаление перенаправления поисковых ссылок, блокирование рекламы результатов поиска и т.д.; он совместим с известными поисковыми системами, такими как Baidu, Google, Bing, Duckduckgo, Yandex, Sogou, Ecosia, You, Startpage, brave и т.д.
// @description:ja “優雅な検索エンジン助手”は、ユーザが異なる検索エンジン間でジャンプすることを容易にし、カスタム常用検索エンジン、検索キーワードのハイライト効果をサポートし、検索リンクのリダイレクト除去、検索結果広告の遮蔽、可視化パラメータ設定、自動更新検出などの高度な機能を提供し、Baidu、Google、Bing、Duckduckgo、Yandex、Sogou、Ecosia、You、Startpage、Braveなどの複数の有名な検索エンジンに対応する。
// @namespace https://openuserjs.org/scripts/f9y4ng/Google_baidu_Switcher_(ALL_in_One)
// @icon https://img.icons8.com/stickers/48/search-in-cloud.png
// @homepage https://f9y4ng.github.io/GreasyFork-Scripts/
// @homepageURL https://f9y4ng.github.io/GreasyFork-Scripts/
// @supportURL https://github.com/F9y4ng/GreasyFork-Scripts/issues
// @updateURL https://github.com/F9y4ng/GreasyFork-Scripts/raw/master/Google%20%26%20Baidu%20Switcher.meta.js
// @downloadURL https://github.com/F9y4ng/GreasyFork-Scripts/raw/master/Google%20%26%20Baidu%20Switcher.user.js
// @require https://update.greasyfork.org/scripts/460897/1277476/gbCookies.js#sha256-Sv+EuBerch8z/6LvAU0m/ufvjmqB1Q/kbQrX7zAvOPk=
// @match *://www.baidu.com/*
// @match *://image.baidu.com/search*
// @match *://kaifa.baidu.com/searchPage*
// @match *://*.bing.com/*search*
// @match *://duckduckgo.com/*
// @match *://*.sogou.com/*
// @match *://www.wuzhuiso.com/s*
// @match *://www.so.com/s*
// @match *://image.so.com/*
// @match *://so.toutiao.com/search*
// @match *://yandex.com/*search*
// @match *://yandex.ru/*search*
// @match *://www.ecosia.org/*
// @match *://*.search.yahoo.com/search*
// @match *://you.com/search*
// @match *://www.startpage.com/*
// @match *://search.brave.com/*
// @match *://yep.com/*
// @match *://swisscows.com/*
// @include *://*.google.*/search*
// @exclude *://www.google.com/sorry*
// @exclude *://www.baidu.com/link*
// @exclude *://www.sogou.com/link*
// @exclude *://www.so.com/link*
// @exclude *://so.toutiao.com/search/jump*
// @connect baidu.com
// @connect bing.com
// @connect sogou.com
// @connect so.com
// @connect search.yahoo.com
// @connect greasyfork.org
// @connect openuserjs.org
// @connect githubusercontent.com
// @connect favicon.yandex.net
// @compatible edge 兼容Tampermonkey, Violentmonkey
// @compatible Chrome 兼容Tampermonkey, Violentmonkey
// @compatible Firefox 兼容Greasemonkey, Tampermonkey, Violentmonkey
// @compatible Opera 兼容Tampermonkey, Violentmonkey
// @compatible Safari 兼容Tampermonkey, Userscripts
// @note 修复部分搜索引擎的跳转按钮的显示BUG。
// @note 置换脚本引用源地址至github.com域内。
// @note 修正一些已知问题,优化样式,优化代码。
// @grant GM_getValue
// @grant GM.getValue
// @grant GM_setValue
// @grant GM.setValue
// @grant GM_listValues
// @grant GM.listValues
// @grant GM_deleteValue
// @grant GM.deleteValue
// @grant GM_openInTab
// @grant GM.openInTab
// @grant GM_registerMenuCommand
// @grant GM.registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_xmlhttpRequest
// @grant GM.xmlHttpRequest
// @license GPL-3.0-only
// @create 2015-10-07
// @copyright 2015-2024, F9y4ng
// @run-at document-start
// ==/UserScript==
/* jshint esversion: 11 */
~(function (w) {
"use strict";
/**
* LICENSE FOR OPEN SOURCE USE: GPLv3.
* CUSTOM SCRIPT DEBUGGING, DO NOT TURN ON FOR DAILY USE.
* SET TO "TRUE" FOR SCRIPT DEBUGGING, MAY CAUSE THE SCRIPT TO RUN SLOWLY.
* THE SETTING VALUE TYPE MUST BE BOOLEAN, FALSE BY DEFAULT.
*/
const IS_OPEN_DEBUG = false;
/* PERFECTLY COMPATIBLE FOR GREASEMONKEY, TAMPERMONKEY, VIOLENTMONKEY, USERSCRIPTS 2023-04-08 F9Y4NG */
const GMinfo = GM?.info ?? GM_info;
const GMversion = GMinfo.version ?? GMinfo.scriptHandlerVersion ?? "unknown";
const GMscriptHandler = GMinfo.scriptHandler;
const GMsetValue = gmSelector("setValue");
const GMgetValue = gmSelector("getValue");
const GMdeleteValue = gmSelector("deleteValue");
const GMlistValues = gmSelector("listValues");
const GMopenInTab = gmSelector("openInTab");
const GMregisterMenuCommand = gmSelector("registerMenuCommand");
const GMunregisterMenuCommand = gmSelector("unregisterMenuCommand");
const GMxmlhttpRequest = gmSelector("xmlhttpRequest");
const GMunsafeWindow = gmSelector("unsafeWindow");
const GMcontentMode = gmSelector("contentMode");
const GMcachedPrototype = gmSelector("cachedPrototype");
/* INITIALIZE_DEBUG_FUNCTIONS */
const IS_DEBUG = setDebuggerMode() || IS_OPEN_DEBUG;
const DEBUG = IS_DEBUG ? __console.bind(console, "log") : () => {};
const ERROR = IS_DEBUG ? __console.bind(console, "error") : () => {};
const COUNT = IS_DEBUG ? __console.bind(console, "count") : () => {};
/* INITIALIZE_COMMON_CONSTANTS */
const def = {
count: { clickTimer: 0 },
const: {
disappear: "ͼA2tB7nͽ",
translucent: "ͼC9b7Zqͽ",
isSecurityPolicy: false,
ft: parseFloat(1000 / 60),
loading: generateRandomString(6, "char"),
raf: Symbol(`פֿ${generateRandomString(8, "hex")}`),
caf: Symbol(`פֿ${generateRandomString(8, "hex")}`),
cssAttrName: `gb-css-${generateRandomString(8, "hex")}`,
rndButtonID: generateRandomString(12, "char"),
rndclassName: `SC${generateRandomString(8, "digit")}`,
rndstyleName: `SS${generateRandomString(8, "digit")}`,
rndadvName: `SA${generateRandomString(8, "digit")}`,
leftButton: generateRandomString(6, "mix"),
rightButton: generateRandomString(6, "mix"),
scrollspan: generateRandomString(8, "char"),
scrollspan2: generateRandomString(8, "char"),
scrollbars: generateRandomString(8, "char"),
scrollbars2: generateRandomString(8, "char"),
yandexIcon: decrypt("aHR0cHMlM0ElMkYlMkZmYXZpY29uLnlhbmRleC5uZXQlMkZmYXZpY29uJTJGdjI="),
backupIcon: decrypt("aHR0cHMlM0ElMkYlMkZ6MS5heDF4LmNvbSUyRjIwMjMlMkYxMSUyRjMwJTJGcGlyTTFTZy5wbmc="),
},
variable: {
undef: void 0,
refresh: () => location.reload(true),
curVersion: getMetaValue("version") ?? GMinfo.script.version ?? "2024.02.03.0",
scriptName: getMetaValue(`name:${navigator.language ?? "zh-CN"}`) ?? decrypt("U2VhcmNoJTIwRW5naW5lJTIwQXNzaXN0YW50"),
feedback: getMetaValue("supportURL") ?? GMinfo.script.supportURL ?? decrypt("aHR0cHMlM0ElMkYlMkZmOXk0bmcubGlrZXMuZmFucyUyRnN1cHBvcnQ="),
homepage: getMetaValue("homepage") ?? getMetaValue("homepageURL") ?? decrypt("aHR0cHMlM0ElMkYlMkZmOXk0bmcuZ2l0aHViLmlvJTJGR3JlYXN5Rm9yay1TY3JpcHRzJTJG"),
},
dialog: { alert: alert.bind(w), prompt: prompt.bind(w), confirm: confirm.bind(w) },
notice: {
rName: generateRandomString(8, "char"),
random: generateRandomString(5, "char"),
noticejs: generateRandomString(7, "char"),
linkerror: generateRandomString(7, "mix"),
item: generateRandomString(6, "mix"),
close: generateRandomString(6, "mix"),
center: generateRandomString(6, "mix"),
success: generateRandomString(7, "char"),
warning: generateRandomString(7, "char"),
info: generateRandomString(7, "char"),
error: generateRandomString(7, "char"),
checkbox: generateRandomString(6, "char"),
configuration: generateRandomString(7, "char"),
animated: generateRandomString(7, "char"),
stopUpdate: generateRandomString(6, "mix"),
searchButton: generateRandomString(6, "mix"),
favicon: generateRandomString(6, "mix"),
favicons: generateRandomString(6, "mix"),
searchList: generateRandomString(7, "mix"),
fieldset: generateRandomString(6, "char"),
legend: generateRandomString(6, "char"),
settingList: generateRandomString(7, "mix"),
readonly: generateRandomString(8, "mix"),
hk: generateRandomString(5, "mix"),
gj: generateRandomString(5, "mix"),
lw: generateRandomString(5, "mix"),
kh: generateRandomString(5, "mix"),
ar: generateRandomString(5, "mix"),
aa: generateRandomString(5, "mix"),
au: generateRandomString(5, "mix"),
grid: generateRandomString(7, "char"),
card: generateRandomString(7, "char"),
noticeHTML: str => String(`<div class="${def.notice.rName}"><dl>${str}</dl></div>`),
},
};
if (checkRedundantScript(GMunsafeWindow)) return;
/* INITIALIZE_SETTIMEOUT_AND_SETINTERVAL_FUNCTION_CLASSES */
class RAF {
constructor(global) {
if (RAF.instance) return RAF.instance;
registerWindowsProperties(global);
this.timerMap = { timeout: {}, interval: {} };
this.setTimeout = this.setTimeout.bind(this);
this.global = global;
RAF.instance = this;
}
_ticking(fn, type, interval, lastTime = Date.now()) {
const timerSymbol = Symbol(type);
const step = () => {
this._setTimerMap(timerSymbol, type, step);
if (interval < def.const.ft || Date.now() - lastTime >= interval) {
typeof fn === "function" && fn();
if (type === "interval") lastTime = Date.now();
else this.clearTimeout(timerSymbol);
}
};
this._setTimerMap(timerSymbol, type, step);
return timerSymbol;
}
_setTimerMap(timerSymbol, type, step) {
this.timerMap[type][timerSymbol] = this.global[def.const.raf](step);
}
setTimeout(fn, interval) {
return this._ticking(fn, "timeout", interval);
}
clearTimeout(timer) {
this.global[def.const.caf](this.timerMap.timeout[timer]);
delete this.timerMap.timeout[timer];
}
setInterval(fn, interval) {
return this._ticking(fn, "interval", interval);
}
clearInterval(timer) {
this.global[def.const.caf](this.timerMap.interval[timer]);
delete this.timerMap.interval[timer];
}
}
const raf = new RAF(w);
/* GLOBAL_GENERAL_FUNCTIONS */
function gmSelector(rec) {
const gmFunctions = {
setValue: typeof GM_setValue !== "undefined" ? GM_setValue : GM?.setValue ?? localStorage.setItem.bind(localStorage),
getValue: typeof GM_getValue !== "undefined" ? GM_getValue : GM?.getValue ?? localStorage.getItem.bind(localStorage),
deleteValue: typeof GM_deleteValue !== "undefined" ? GM_deleteValue : GM?.deleteValue ?? localStorage.removeItem.bind(localStorage),
listValues: typeof GM_listValues !== "undefined" ? GM_listValues : GM?.listValues ?? (() => []),
openInTab: typeof GM_openInTab !== "undefined" ? GM_openInTab : GM?.openInTab ?? open.bind(w),
registerMenuCommand: typeof GM_registerMenuCommand !== "undefined" ? GM_registerMenuCommand : GM?.registerMenuCommand ?? (() => {}),
unregisterMenuCommand: typeof GM_unregisterMenuCommand !== "undefined" ? GM_unregisterMenuCommand : GM?.unregisterMenuCommand ?? (() => {}),
xmlhttpRequest: typeof GM_xmlhttpRequest !== "undefined" ? GM_xmlhttpRequest : GM?.xmlHttpRequest ?? replaceXHR,
unsafeWindow: typeof unsafeWindow !== "undefined" ? unsafeWindow : w,
contentMode: GMinfo.injectInto === "content" || GMinfo.script["inject-into"] === "content" || ["dom", "js"].includes(GMinfo.sandboxMode),
cachedPrototype: { decrypt: atob.bind(w), encrypt: btoa.bind(w), console: Object.assign({}, w.console) },
};
return gmFunctions[rec] ?? (() => {});
}
function __console(act, argm, ...args) {
const _this = GMcachedPrototype.console;
const _argm = argm ?? "";
switch (act) {
case "log":
return _this[act](`%c\ud83d\udd33 %c${_argm}`, "display:inline-block", "font-family:monospace", ...args);
case "error":
case "warn":
return _this[act](`%c\ud83d\udea9 ${_argm}`, "display:inline-block;font-family:monospace", ...args);
case "count":
return _this[act](`\ud83d\udd33 ${_argm}`);
default:
return _this.log(_argm, ...args);
}
}
function registerWindowsProperties(scope) {
// REGISTER RAF
scope[def.const.raf] =
scope.requestAnimationFrame ||
scope.webkitRequestAnimationFrame ||
scope.mozRequestAnimationFrame ||
scope.oRequestAnimationFrame ||
(function () {
const delay = def.const.ft;
const animationStartTime = Date.now();
let previousCallTime = animationStartTime;
return function requestAnimationFrame(callback) {
const requestTime = Date.now();
const timeout = Math.max(0, delay - (requestTime - previousCallTime));
const timeToCall = requestTime + timeout;
previousCallTime = timeToCall;
return setTimeout(function onAnimationFrame() {
callback(timeToCall - animationStartTime);
}, timeout);
};
})();
// REGISTER CAF
scope[def.const.caf] =
scope.cancelAnimationFrame ||
scope.webkitCancelAnimationFrame ||
scope.mozCancelAnimationFrame ||
scope.oCancelAnimationFrame ||
scope.cancelRequestAnimationFrame ||
scope.webkitCancelRequestAnimationFrame ||
scope.mozCancelRequestAnimationFrame ||
scope.oCancelRequestAnimationFrame ||
function cancelAnimationFrame(id) {
clearTimeout(id);
};
// REGISTER PUSHSTATE/REPLACESTATE
const wrapHistory = type => {
const original = history[type];
const event = new Event(type);
return function () {
const fn = original.apply(this, arguments);
event.arguments = arguments;
scope.dispatchEvent(event);
return fn;
};
};
history.pushState = wrapHistory("pushState");
history.replaceState = wrapHistory("replaceState");
}
function qS(expr, target = document) {
try {
if (/^#[\w:-]+$/.test(expr)) return target.getElementById(expr.slice(1));
return target.querySelector(expr);
} catch (e) {
return null;
}
}
function qA(expr, target = document) {
try {
return Array.prototype.slice.call(target.querySelectorAll(expr), 0);
} catch (e) {
return [];
}
}
function cE(nodeName) {
return document.createElement(nodeName);
}
function gCS(target, value, opt = null) {
if (!target) return;
if (value) {
return w.getComputedStyle(target, opt).getPropertyValue(value);
} else {
return w.getComputedStyle(target, opt);
}
}
function random(range, type = "round") {
return Math[type]((w.crypto.getRandomValues(new Uint32Array(1))[0] / (0xffffffff + 1)) * range);
}
function capitalize(string) {
string = String(string ?? "").toLowerCase();
return string.replace(/\b[a-z]|\s[a-z]/g, str => str.toUpperCase());
}
function encrypt(string, encode = true) {
if (typeof string !== "string") return "";
try {
const req = encode ? encodeURIComponent(string) : string;
return GMcachedPrototype.encrypt(req);
} catch (e) {
return "";
}
}
function decrypt(string, decode = true) {
if (typeof string !== "string") return "";
try {
const rst = GMcachedPrototype.decrypt(string.replace(/[^A-Za-z0-9+/=]/g, ""));
return decode ? decodeURIComponent(rst) : rst;
} catch (e) {
return "";
}
}
function compareArray(array1, array2) {
if (!Array.isArray(array1) || !Array.isArray(array2)) return false;
return (
array1.length === array2.length &&
array1.sort().every(function (element, index) {
return element === array2.sort()[index];
})
);
}
function uniq(array) {
if (!Array.isArray(array)) return [];
return Array.from(new Set(array)).filter(Boolean);
}
function generateRandomString(length, type) {
const digits = "0123456789";
const lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";
const upperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const hexLetters = lowerCaseLetters.slice(0, 6);
let characters = upperCaseLetters;
let prefix = "";
let randomString = [];
switch (type) {
case "mix":
characters = lowerCaseLetters + digits + upperCaseLetters;
prefix = upperCaseLetters[random(upperCaseLetters.length, "floor")];
length--;
break;
case "char":
characters = lowerCaseLetters + upperCaseLetters;
break;
case "digit":
characters = digits;
break;
case "hex":
characters = hexLetters + digits + hexLetters;
break;
}
for (let i = length; i > 0; i--) {
randomString.push(characters[random(characters.length, "floor")]);
}
return prefix + randomString.join("");
}
function replaceXHR(xhr) {
return fetch(xhr?.url)
.then(response => response.text())
.then(data => {
let res = { response: data };
xhr?.onreadystatechange?.(res);
xhr?.onload?.(res);
})
.catch(e => xhr?.onerror?.(e));
}
function escapeHTML(string) {
const element = cE("gb-escape-html");
element.innerText = string;
return element.innerHTML;
}
function createTrustedTypePolicy() {
const policy = { createHTML: string => string };
if (!w.trustedTypes?.createPolicy) return policy;
return w.trustedTypes.createPolicy("default", policy);
}
function checkRedundantScript(global) {
const { isTop: CUR_WINDOW_TOP } = getLocationInfo();
// PAGE_MODE
const redundantScripts = global["gb-init-redundantcheck"];
if (redundantScripts === true) return scriptRedundancyWarning();
global["gb-init-redundantcheck"] = true;
// CONTENT_MODE
if (GMcontentMode) {
const redundantScriptsInfo = document.documentElement?.getAttribute("gb-init-rc");
if (redundantScriptsInfo === "true") return scriptRedundancyWarning();
}
document.documentElement?.setAttribute("gb-init-rc", true);
return false;
function scriptRedundancyWarning() {
if (CUR_WINDOW_TOP) {
__console("error", `\ud83d\udea9 [Redundant Scripts]:\r\nFound redundant-installed scripts: ${def.variable.scriptName}. please reload to troubleshoot the issue.`);
GMregisterMenuCommand("\ufff8\ud83d\uded1 Found redundant scripts, reload!", () => location.reload());
}
return true;
}
}
function getNavigatorInfo() {
const certificate = `${GMscriptHandler} ${GMversion}`;
const uad = getUserAgentDataFromExtension(certificate);
const trustengine = getRealBrowserEngine();
let engine = "Unknown";
let brand = "Unknown";
let brandversion = "0.0.0.0";
if (uad) {
const os = getFullPlatformName(uad.platform);
const brandMap = {
SAFARI: { engine: "WebKit", brand: "Safari" },
FIREFOX: { engine: "Gecko", brand: "Firefox" },
EDGE: { engine: "Blink", brand: "Edge" },
CHROME: { engine: "Blink", brand: "Chrome" },
OPERA: { engine: "Blink", brand: "Opera" },
BRAVE: { engine: "Blink", brand: "Brave" },
YANDEX: { engine: "Blink", brand: "Yandex" },
"MICROSOFT EDGE": { engine: "Blink", brand: "Edge" },
"GOOGLE CHROME": { engine: "Blink", brand: "Chrome" },
};
uad.brands.some(b => {
const reqBrand = b.brand.toUpperCase();
const brandInfo = brandMap[reqBrand];
if (brandInfo) {
engine = brandInfo.engine;
brand = brandInfo.brand;
brandversion = b.version;
return true;
} else if (reqBrand === "CHROMIUM") {
engine = "Blink";
brand = "Chromium";
brandversion = b.version;
}
});
return { engine, brand, brandversion: formatVersion(brandversion), os, "trust-engine": trustengine, credit: uad.credit ?? null };
} else {
const ua = navigator.userAgent;
const checkString = str => new RegExp(str).test(ua);
const getVersion = (str, offset) => checkString(str) && ua.substring(ua.indexOf(str) + offset).match(/\d+(\.\d+)*/)?.[0];
const { brand, engine, brandversion } = getBrowserInfoFromUA(ua, checkString, getVersion);
const os = getOSInfoFromUA(checkString);
return { engine, brand, brandversion, os, "trust-engine": trustengine, credit: null };
}
function formatVersion(version) {
if (!version) return "0.0.0.0";
const numbers = version.split(".").map(num => parseInt(num));
while (numbers.length < 4) numbers.push(0);
return numbers.join(".");
}
function getUserAgentDataFromExtension(cert) {
const vmuad = (uad => {
if (!uad) return;
const archs = uad.arch?.split("-") ?? [];
const brand = capitalize(uad.browserBrand || uad.browserName);
return {
brands: [{ brand, version: uad.browserVersion }],
platform: capitalize(uad.os),
bitness: archs[1] ?? "unknown",
architecture: archs[0] ?? "unknown",
credit: cert,
};
})(GMinfo.platform);
const tmuad = (uad => {
if (!uad) return;
uad.credit = cert;
return uad;
})(GMinfo.userAgentData);
return vmuad ?? tmuad ?? navigator.userAgentData;
}
function getFullPlatformName(platform) {
if (!platform) return "Unknown";
const os = capitalize(platform);
return /^(Like Mac|Ios)$/.test(os) ? "iOS" : os === "Cros" ? "Chrome OS" : os.startsWith("Win") ? "Windows" : os.startsWith("Mac") ? "MacOS" : os === "X11" ? "Unix" : os;
}
function getRealBrowserEngine() {
return w.webkitRequestFileSystem ? "Blink" : !isNaN(parseFloat(w.mozInnerScreenX)) ? "Gecko" : w.GestureEvent ? "WebKit" : "Unknown";
}
function getBrowserInfoFromUA(ua, checkString, getVersion) {
const engine = /Gecko\/|FxiOS/.test(ua) ? "Gecko" : /Chrom[e|ium]|CriOS/.test(ua) ? "Blink" : /AppleWebKit\//.test(ua) ? "WebKit" : "Unknown";
const brandMap = {
OPR: { brand: "Opera", engine: "Blink", as: "Chrome" },
QQBrowser: { brand: "QQBrowser", engine: "Blink", as: "Chrome" },
YaBrowser: { brand: "Yandex", engine, as: "Chrome" },
Brave: { brand: "Brave", engine: "Blink" },
Edg: { brand: "Edge", engine: "Blink" },
Maxthon: { brand: "Maxthon", engine: "Blink", as: "Chrome" },
CriOS: { brand: "Chrome", engine: "Blink" },
Chromium: { brand: "Chromium", engine: "Blink" },
Chrome: { brand: "Chrome", engine: "Blink" },
FxiOS: { brand: "Firefox", engine: "Gecko" },
Waterfox: { brand: "Waterfox", engine: "Gecko" },
PaleMoon: { brand: "PaleMoon", engine: "Gecko", as: "Firefox" },
Firefox: { brand: "Firefox", engine: "Gecko" },
Safari: { brand: "Safari", engine: "WebKit", verset: ["Version"] },
Trident: { brand: "IE", engine: "Trident", verset: ["MSIE", "rv"] },
};
for (const key of Object.keys(brandMap)) {
if (checkString(key)) {
const { brand: _brand, engine, verset, as } = brandMap[key];
const _verset = verset?.find(k => checkString(k)) ?? verset?.[0];
const _key = _verset ?? as ?? key;
const _brandversion = formatVersion(getVersion(_key, _key.length + 1));
return { brand: _brandversion ? _brand : brand, engine, brandversion: _brandversion ?? brandversion };
}
}
const nameOffset = ua.lastIndexOf(" ") + 1;
const verOffset = ua.lastIndexOf("/");
const _brand = ua.substring(nameOffset, verOffset);
const _brandversion = formatVersion(ua.substring(verOffset + 1).match(/\d+(\.\d+)*/)?.[0]);
const isValidValue = !/version|\/|\(|\)|;/i.test(_brand) && _brandversion;
return { brand: isValidValue ? _brand : brand, engine, brandversion: isValidValue ? _brandversion : brandversion };
}
function getOSInfoFromUA(checkString) {
let os = "Unknown";
const platforms = ["like Mac", "Mac", "Android", "Debian", "Ubuntu", "Linux", "Win", "CrOS", "X11"];
for (let i = 0; i < platforms.length; i++) {
const platform = platforms[i];
if (checkString(platform)) {
os = getFullPlatformName(platform);
break;
}
}
return os;
}
}
function getLocationInfo() {
const { pathname: cPN, hostname: cHN, protocol: cP } = location;
const isTop = w.self === w.top;
const pHN = w.parent !== w.self ? getParentHost() : cHN;
return { cHN, cPN, cP, pHN, isTop };
function getParentHost() {
try {
return w.parent.location.hostname;
} catch (e) {
return new URL(document.referrer || location).hostname;
}
}
}
function getMetaValue(str) {
const queryReg = new RegExp(`//\\s+@${str}\\s+(.+)`);
const metaValue = (GMinfo.scriptMetaStr || GMinfo.scriptSource)?.match(queryReg);
return metaValue?.[1];
}
function setDebuggerMode() {
const key = decrypt("\u0052\u006a\u006c\u0035\u004e\u0047\u0035\u006e");
const value = new URLSearchParams(location.search).get("whoami");
return Object.is(key, value);
}
function sleep(delay, { useCachedSetTimeout } = {}) {
const timeoutFunction = useCachedSetTimeout ? setTimeout : raf.setTimeout;
const sleepPromise = new Promise(resolve => {
timeoutFunction(resolve, delay);
});
const promiseFunction = value => sleepPromise.then(() => value);
promiseFunction.then = (...args) => sleepPromise.then(...args);
promiseFunction.catch = Promise.resolve().catch;
return promiseFunction;
}
function deBounce({ fn, delay, timer, immed, once } = {}) {
if (typeof fn !== "function" || !timer) return;
let caller = 0;
const threshold = Number(Boolean(immed));
return function () {
const context = this;
const args = arguments;
const name = Symbol.for(String(timer));
if (typeof def.count[name] === "undefined") {
if (immed === true) {
fn.apply(context, args);
if (once === true) return (def.count[name] = true);
}
} else {
if (once === true && def.count[name] === true) return true;
raf.clearTimeout(def.count[name]);
caller++;
}
def.count[name] = raf.setTimeout(() => {
if (caller >= threshold) {
fn.apply(context, args);
if (once === true) return (def.count[name] = true);
}
delete def.count[name];
}, Number(delay) || 0);
};
}
function safeRemove(expr, scope) {
let removedNodes = [];
let pendingNodes = [];
switch (typeof expr) {
case "string":
if (!expr) return false;
pendingNodes = qA(expr, scope);
pendingNodes.forEach(item => removeNode(item));
break;
case "object":
if (expr?.nodeType === Node.ELEMENT_NODE) {
pendingNodes.push(expr);
removeNode(expr);
} else return false;
break;
default:
ERROR("Element not exist!");
return false;
}
return compareArray(removedNodes, pendingNodes);
function removeNode(item) {
try {
removedNodes.push(item.parentNode.removeChild(item));
} catch (e) {
removedNodes.push(item);
item.remove();
}
}
}
~(function (tTP, requestEnvironmentConstants) {
const { navigatorInfo, locationInfo } = requestEnvironmentConstants();
const { engine, brand, "trust-engine": trustengine, credit } = navigatorInfo;
const { cP: CUR_PROTOCOL, cHN: CUR_HOST_NAME, isTop: CUR_WINDOW_TOP } = locationInfo;
const IS_REAL_GECKO = trustengine === "Gecko";
const IS_REAL_BLINK = trustengine === "Blink";
const IS_REAL_WEBKIT = trustengine === "WebKit";
const IS_CHEAT_UA = !credit && (engine !== trustengine || checkBlinkCheatingUA());
const IS_GREASEMONKEY = GMscriptHandler === "Greasemonkey";
const NOTICE_CSS = String(
`#${def.const.rndButtonID} *{text-shadow:none!important;font-family:Helvetica,system-ui,-apple-system,BlinkMacSystemFont,sans-serif!important;-webkit-text-stroke:0 transparent!important}.${def.notice.noticejs} *,.${def.notice.noticejs} *::after,.${def.notice.noticejs} *::before {box-sizing:content-box;line-height:normal;scrollbar-width:thin}.${def.notice.animated}{animation-duration:1s;animation-fill-mode:both}.${def.notice.animated}.infinite{animation-iteration-count:infinite}.${def.notice.animated}.hinge{animation-duration:2s}.${def.notice.animated}.bounceIn,.${def.notice.animated}.bounceOut,.${def.notice.animated}.flipOutX,.${def.notice.animated}.flipOutY{animation-duration:1.25s}@keyframes fadeIn{from{opacity:0}to{opacity:1}}.${def.notice.random}_fadeIn{animation-name:fadeIn}@keyframes fadeOut{from{opacity:1}to{opacity:0}}.${def.notice.random}_fadeOut{animation-name:fadeOut}.${def.notice.noticejs},.${def.notice.noticejs} *{text-shadow:none!important;font-family:Microsoft YaHei UI,system-ui,-apple-system,BlinkMacSystemFont,sans-serif!important;-webkit-text-stroke:0 transparent!important}.${def.notice.noticejs}-top{top:0;width:100%}.${def.notice.noticejs}-top .${def.notice.item}{margin:0!important;border-radius:0!important}.${def.notice.noticejs}-topRight{top:10px;right:10px;z-index:10000059!important}.${def.notice.noticejs}-topLeft{top:10px;left:10px}` +
`.${def.notice.noticejs}-topCenter{top:10px;left:50%;transform:translate(-50%)}.${def.notice.noticejs}-middleLeft,.${def.notice.noticejs}-middleRight{right:10px;top:50%;transform:translateY(-50%)}.${def.notice.noticejs}-middleLeft{left:10px}.${def.notice.noticejs}-middleCenter{top:50%;left:50%;transform:translate(-50%,-50%)}.${def.notice.noticejs}-bottom{bottom:0;width:100%}.${def.notice.noticejs}-bottom .${def.notice.item}{border-radius:0!important;margin:0!important}.${def.notice.noticejs}-bottomRight{bottom:10px;right:10px;z-index:10000055!important}.${def.notice.noticejs}-bottomLeft{bottom:10px;left:10px}.${def.notice.noticejs}-bottomCenter{bottom:10px;left:50%;transform:translate(-50%)}.${def.notice.noticejs} .${def.notice.item}{margin:0 0 10px;border-radius:6px;overflow:hidden}.${def.const.translucent} *{display:none!important}.${def.const.translucent} notice-label{display:block!important}.${def.const.disappear}{display:none!important}[gb-filter-notice]{display:block!important;margin:18px 0 28px 10px!important;padding:10px 2px!important;font:normal 400 14px/100% 'Times New Roman',system-ui,-apple-system,BlinkMacSystemFont,serif!important;-webkit-text-stroke:0 transparent!important;line-height:100%!important}gb-filters.code{display:block;margin:20px 0;word-break:break-word;font-size:12px!important}` +
`.${def.notice.noticejs} .${def.notice.item} .${def.notice.close}{float:right;margin-right:7px;color:#ffffff;text-shadow:0 1px 0 #ffffff;font-weight:700;font-size:18px!important;line-height:1;opacity:1}.${def.notice.noticejs} .${def.notice.item} .${def.notice.close}:hover{color:#000;opacity:.5;cursor:pointer}.${def.notice.noticejs} .${def.notice.item} a{border-bottom:1px dashed #ffffff;color:#ffffff;}.${def.notice.noticejs} .${def.notice.item} a,.${def.notice.noticejs} .${def.notice.item} a:hover{text-decoration:none}.${def.notice.noticejs} .${def.notice.success}{background-color:#64ce83;}.${def.notice.noticejs} .${def.notice.success} .${def.notice.noticejs}-heading{padding:10px;background-color:#3da95c;color:#ffffff;font-weight:700;font-size:14px!important}.${def.notice.noticejs} .${def.notice.success} .${def.notice.noticejs}-body{padding:10px!important;color:#ffffff;}.${def.notice.noticejs} .${def.notice.success} .${def.notice.noticejs}-body:hover{visibility:visible!important}.${def.notice.noticejs} .${def.notice.success} .${def.notice.noticejs}-content{visibility:visible}.${def.notice.noticejs} .${def.notice.info}{background-color:#3ea2ff;}.${def.notice.noticejs} .${def.notice.info} .${def.notice.noticejs}-heading{padding:10px;background-color:#067cea;color:#ffffff;font-weight:700;font-size:14px!important}.${def.notice.noticejs} .${def.notice.info} .${def.notice.noticejs}-body{padding:10px!important;color:#ffffff;}.${def.notice.noticejs} .${def.notice.info} .${def.notice.noticejs}-body:hover{visibility:visible!important}.${def.notice.noticejs} .${def.notice.info} .${def.notice.noticejs}-content{visibility:visible}.${def.notice.noticejs} .${def.notice.warning}{background-color:#ff7f48;}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.noticejs}-heading{padding:10px!important;background-color:#f97038;color:#ffffff;font-weight:700;font-size:14px!important}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.noticejs}-body{color:#ffffff;padding:10px}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.noticejs}-body:hover{visibility:visible!important}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.noticejs}-content{visibility:visible}` +
`.${def.notice.noticejs} .${def.notice.error}{background-color:#e74c3c;}.${def.notice.noticejs} .${def.notice.error} .${def.notice.noticejs}-heading{padding:10px!important;background-color:#e93724;color:#ffffff;font-weight:700;font-size:14px!important}.${def.notice.noticejs} .${def.notice.error} .${def.notice.noticejs}-body{padding:10px;color:#ffffff;}.${def.notice.noticejs} .${def.notice.error} .${def.notice.noticejs}-body:hover{visibility:visible!important}.${def.notice.noticejs} .${def.notice.error} .${def.notice.noticejs}-content{visibility:visible}.${def.notice.configuration} input[disabled],.${def.notice.configuration} select[disabled]{color:#bbbbbb;background:linear-gradient(45deg,#ffe9e9 0,#ffe9e9 25%,transparent 25%,transparent 50%,#ffe9e9 50%,#ffe9e9 75%,transparent 75%,transparent)!important;background-size:20px 20px!important;background-color:#fff7f7!important}.${def.notice.noticejs} .${def.notice.configuration}{background:linear-gradient(to right,#fcfcfc,#f2f2f7);background:-webkit-gradient(linear,0 0,0 100%,from(#fcfcfc),to(#f2f2f7));box-shadow:0 0 5px #888}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.close}{float:right;margin-right:7px;color:#000000;text-shadow:0 1px 0 #aaaaaa;font-weight:700;font-size:18px!important;line-height:1;opacity:1}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.close}:hover{color:#555555;opacity:.5;cursor:pointer}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.noticejs}-heading{padding:10px!important;background-color:#e7e7e7;color:#333333;font-weight:700;font-size:14px!important}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.noticejs}-body{padding:10px;color:#333333;}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.noticejs}-body:hover{visibility:visible!important}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.noticejs}-content{visibility:visible}` +
`.${def.notice.noticejs} .${def.notice.noticejs}-heading-title{display:inline-block;vertical-align:middle;overflow:hidden;max-width:275px;text-overflow:ellipsis;white-space:nowrap}.${def.notice.noticejs} .${def.notice.success} .${def.notice.noticejs}-progressbar{margin-top:-1px;width:100%;background-color:#64ce83;}.${def.notice.noticejs} .${def.notice.success} .${def.notice.noticejs}-progressbar .${def.notice.noticejs}-bar{width:100%;height:5px;background:#3da95c;}.${def.notice.noticejs} .${def.notice.info} .${def.notice.noticejs}-progressbar{margin-top:-1px;width:100%;background-color:#3ea2ff;}.${def.notice.noticejs} .${def.notice.info} .${def.notice.noticejs}-progressbar .${def.notice.noticejs}-bar{width:100%;height:5px;background:#067cea;}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.noticejs}-progressbar{margin-top:-1px;width:100%;background-color:#ff7f48;}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.noticejs}-progressbar .${def.notice.noticejs}-bar{width:100%;height:5px;background:#f44e06;}.${def.notice.noticejs} .${def.notice.error} .${def.notice.noticejs}-progressbar{margin-top:-1px;width:100%;background-color:#fd5f4e;}.${def.notice.noticejs} .${def.notice.error} .${def.notice.noticejs}-progressbar .${def.notice.noticejs}-bar{width:100%;height:5px;background:#ba2c1d;}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.noticejs}-progressbar{margin-top:-1px;width:100%;background-color:#efefef;}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.noticejs}-progressbar .${def.notice.noticejs}-bar{width:100%;height:5px;background:#cccccc;}` +
`@keyframes ${def.notice.noticejs}-fadeOut{0%{opacity:1}to{opacity:0}}.${def.notice.noticejs}-fadeOut{animation-name:${def.notice.noticejs}-fadeOut}@keyframes ${def.notice.noticejs}-modal-in{to{opacity:.3}}@keyframes ${def.notice.noticejs}-modal-out{to{opacity:0}}.${def.notice.noticejs}{position:fixed;z-index:10000051}.${def.notice.noticejs} ::-webkit-scrollbar{width:8px}.${def.notice.noticejs} ::-webkit-scrollbar-button{width:8px;height:5px}.${def.notice.noticejs} ::-webkit-scrollbar-track{border-radius:3px}.${def.notice.noticejs} ::-webkit-scrollbar-thumb{background:#e1e1e1;border-radius:3px}.${def.notice.noticejs} ::-webkit-scrollbar-thumb:hover{background:#cccccc;}.${def.notice.noticejs}-modal{position:fixed;top:0;left:0;z-index:10000050;width:100%;height:100%;background-color:#000000;opacity:.3}.${def.notice.noticejs}-modal-open{opacity:0;animation:${def.notice.noticejs}-modal-in .3s ease-out}.${def.notice.noticejs}-modal-close{animation:${def.notice.noticejs}-modal-out .3s ease-out;animation-fill-mode:forwards}.${def.notice.rName}{padding:2px!important}.${def.notice.noticejs} .${def.notice.rName} dl{margin:0!important;padding:1px!important}.${def.notice.noticejs} .${def.notice.rName} dl dt{margin:2px 0 6px!important;font-weight:900!important;font-size:16px!important}.${def.notice.noticejs} .${def.notice.rName} dl dd{margin:2px 2px 0 0!important;font-size:14px!important;line-height:180%!important;margin-inline-start:10px!important}.${def.notice.noticejs} .${def.notice.rName} .${def.notice.center}{width:100%;text-align:center!important}.${def.notice.noticejs} .${def.notice.rName} dl dd em{padding:0 5px;color:#ffffff;font-style:italic;font-size:24px!important;font-family:Candara,sans-serif!important}.${def.notice.noticejs} .${def.notice.rName} dl dd span{margin-right:8px;font-weight:700;font-size:15px!important}.${def.notice.noticejs} .${def.notice.rName} dl dd i{font-size:20px!important;font-family:Candara,sans-serif!important}.${def.notice.noticejs} .${def.notice.rName} dl dd .im{padding:0 3px;color:gold;font-weight:900;font-size:16px!important}` +
`.${def.notice.noticejs} .${def.notice.warning} .${def.notice.rName} ul{display:inline-block;margin:0 0 0 8px;padding:4px 4px 8px;width:90%;color:rgba(255, 255, 255, 0.8);counter-reset:xxx 0;vertical-align:top;text-align:left}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.rName} li{position:relative;margin:0 0 0 2px;padding:0 0 2px 2px;list-style:none;font-style:italic!important;line-height:150%;-webkit-transition:.12s;transition:.12s}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.rName} li::before{display:inline-block;margin-left:-1.5em;width:1.5em;content:counter(xxx,decimal) "、";counter-increment:xxx 1;font-size:1em;font-family:Candara,sans-serif;-webkit-transition:.5s;transition:.5s}.${def.notice.noticejs} .${def.notice.warning} .${def.notice.rName} #${def.notice.stopUpdate}{float:right;margin:0 5px!important;font-size:12px!important;cursor:help}.${def.const.loading}{position:relative;}.${def.const.loading}::after{content:" \u21ba";animation:fade 1.25s infinite;}@keyframes fade{0%{opacity:0.1}50%{opacity:0.5}to{opacity:0}}.${def.notice.readonly}{background:linear-gradient(45deg,#ffe9e9,#ffe9e9 25%,transparent 0,transparent 50%,#ffe9e9 0,#ffe9e9 75%,transparent 0,transparent)!important;background-color:#fff7f7!important;background-size:50px 50px!important;color:#999}` +
`#${def.notice.stopUpdate} input[type='checkbox']{box-sizing:content-box;margin:2px 4px 0 0;width:14px;height:14px;border:2px solid #ffffff;border-radius:50%;background:#ffa077;vertical-align:top;cursor:help;-webkit-appearance:none}#${def.notice.stopUpdate}:hover input,#${def.notice.stopUpdate} input:hover{background:#ba2c1d;}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.checkbox}{display:none!important}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.checkbox}+label{position:relative;display:inline-block;-webkit-box-sizing:content-box;box-sizing:content-box;margin:0 0 0 25px;padding:11px 9px;width:58px;height:10px;border-radius:7px;background:#f7836d;box-shadow:inset 0 0 20px rgba(0,0,0,.1),0 0 10px rgba(245,146,146,.4);word-wrap:normal!important;cursor:pointer}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.checkbox}+label::before{position:absolute;top:0;left:0;z-index:99;width:24px;height:32px;-webkit-border-radius:7px;border-radius:7px;background:#ffffff;box-shadow:0 0 1px rgba(0,0,0,.6);color:#ffffff;content:" "}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.checkbox}+label::after{position:absolute;top:2px;left:28px;-webkit-box-sizing:content-box;box-sizing:content-box;padding:5px;-webkit-border-radius:100px;border-radius:100px;color:#ffffff;content:"OFF";font-weight:700;font-size:1em}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.checkbox}:checked+label{-webkit-box-sizing:content-box;box-sizing:content-box;margin:0 0 0 25px;background:#67a5df!important;box-shadow:inset 0 0 20px rgba(0,0,0,.1),0 0 10px rgba(146, 196, 245, 0.4);cursor:pointer}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.checkbox}:checked+label::after{top:2px;left:10px;content:"ON"}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.checkbox}:checked+label::before{position:absolute;left:52px;z-index:99;content:" "}` +
`.${def.notice.noticejs} .${def.notice.configuration} button.${def.notice.searchButton}{display:flex;margin:0 0 10px;padding:6px 0;width:162px;height:25px;border:2px solid #eeeeee;border-radius:6px;background:#ffffff;box-shadow:1px 1px 0 1px #aaaaaa;font-size:14px!important;cursor:pointer;align-content:center;justify-content:center;align-items:center}.${def.notice.noticejs} .${def.notice.configuration} button.${def.notice.searchButton}:hover{box-shadow:1px 1px 3px 0 #888888;color:red}.${def.notice.noticejs} .${def.notice.configuration} span.${def.notice.favicon}{margin:0 6px 0 0;width:24px;height:24px}.${def.notice.noticejs} .${def.notice.configuration} ul.${def.notice.searchList}{margin:5px;padding:2px;list-style:none}.${def.notice.noticejs} .${def.notice.configuration} ul.${def.notice.searchList} li{margin:0;list-style:none;font-style:normal}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.fieldset}{display:block;margin:2px;padding:4px 6px;width:auto;height:auto;border:2px dashed #dfdfdf;border-radius:10px;background:transparent!important;text-align:left}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.legend}{display:block;margin:0;padding:0 8px;width:auto;color:#8b0000!important;font-weight:900!important;font-size:14px!important;-webkit-user-select:all;user-select:all}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList}{margin:0;padding:0;background:transparent!important}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} li{float:none;display:flex;margin:3px 0;padding:2px 8px 2px 12px;height:36px;border:none;background:transparent!important;list-style:none;cursor:default;-webkit-user-select:none;user-select:none;align-content:center;justify-content:space-between}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} li>div{font:normal 700 14px/150% Microsoft YaHei UI,Helvetica Neue,sans-serif!important}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} button{box-sizing:border-box;margin:0 0 0 8px;padding:4px 8px;height:36px;min-width:65px;border:1px solid #cccccc;border-radius:8px;background:#fafafa;box-shadow:1px 1px 1px 0 #cccccc;color:#5e5e5e;font-weight:700;font-size:14px!important}` +
`.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} .${def.notice.random}_filter_info{font-weight:400!important;}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} .${def.notice.random}_filter_info em{color:crimson!important;font-style:normal;}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} .${def.notice.random}_filter_textarea{padding: 6px 0;margin:0}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} .${def.notice.random}_filter{display:block;margin:0;height:100%}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} .${def.notice.random}_filter_content{box-sizing:border-box;margin:0!important;padding:5px!important;max-height:530px;width:100%;min-height:280px;outline:0!important;border:1px solid #bbb;border-radius:6px;white-space:pre;font:normal 400 14px/150% monospace,system-ui,-apple-system,BlinkMacSystemFont,sans-serif!important;resize:vertical;scrollbar-width:thin;overscroll-behavior:contain;word-break:keep-all!important;cursor:auto;}.${def.notice.random}_filter_textarea textarea::-webkit-scrollbar{width:8px;height:8px}.${def.notice.random}_filter_textarea textarea::-webkit-scrollbar-corner{border-radius:2px;background:#efefef;box-shadow:inset 0 0 3px #aaaaaa;}.${def.notice.random}_filter_textarea textarea::-webkit-scrollbar-thumb{border-radius:2px;background:#cfcfcf;box-shadow:inset 0 0 5px #999;}.${def.notice.random}_filter_textarea textarea::-webkit-scrollbar-track{border-radius:2px;background:#efefef;box-shadow:inset 0 0 5px #aaaaaa;}.${def.notice.random}_filter_textarea textarea::-webkit-scrollbar-track-piece{border-radius:2px;background:#efefef;box-shadow:inset 0 0 5px #aaaaaa;}` +
`.${def.notice.noticejs} .${def.notice.configuration} #${def.notice.random}_customColor{margin:0;cursor:pointer}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} button:hover{background:#ffffff;cursor:pointer}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} .${def.notice.random}__content{display:block;margin:0;height:268px}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} .${def.notice.grid}{overflow-x:hidden;overflow-y:auto;box-sizing:border-box;margin:4px 0 3px;padding:8px;width:266px;max-height:237px;overscroll-behavior:contain}.${def.notice.card} h2{margin:0;padding:0;border:0;vertical-align:baseline;font:inherit;font-size:100%;line-height:135%;}.${def.notice.card}{margin:0;padding:0;--background:#ffffff;--background-chackbox:#0082ff;--background-image:#ffffff,rgba(0,107,175,0.2);--text-color:#666666;--text-headline:#000000;--card-shadow:#0082ff;--card-height:48px;--card-witght:240px;--card-radius:12px;--header-height:47px;--blend-mode:overlay;--transition:0.15s;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.${def.notice.card}__input{position:absolute;display:block;margin:0;padding:0;outline:none;border:none;background:none;-webkit-appearance:none}.${def.notice.card}__input:checked ~ .${def.notice.card}__body{--shadow:0 0 0 3px var(--card-shadow);}.${def.notice.card}__input:checked ~ .${def.notice.card}__body .${def.notice.card}__body-cover-chackbox{--chack-bg:var(--background-chackbox);--chack-border:#ffffff;--chack-scale:1;--chack-opacity:1;}.${def.notice.card}__input:checked ~ .${def.notice.card}__body .${def.notice.card}__body-cover-chackbox--svg{--stroke-color:#ffffff;--stroke-dashoffset:0;}.${def.notice.card}__input:checked ~ .${def.notice.card}__body .${def.notice.card}__body-cover:after{--opacity-bg:0;}.${def.notice.random}_iconText{color:#333333;}.${def.notice.random}_iconText:hover{color:crimson}` +
`.${def.notice.card}__input:disabled ~ .${def.notice.card}__body{cursor:not-allowed;opacity:0.5;}.${def.notice.card}__input:disabled ~ .${def.notice.card}__body:active{--scale:1;}.${def.notice.card}__body{position:relative;display:grid;overflow:hidden;width:var(--card-witght);height:var(--card-height);border-radius:var(--card-radius);background:var(--background);box-shadow:var(--shadow,1px 1px 3px 1px #ccc);cursor:pointer;-webkit-transition:box-shadow var(--transition),-webkit-transform var(--transition);transition:box-shadow var(--transition),-webkit-transform var(--transition);transition:transform var(--transition),box-shadow var(--transition);transition:transform var(--transition),box-shadow var(--transition),-webkit-transform var(--transition);-webkit-transform:scale(var(--scale,1)) translateZ(0);transform:scale(var(--scale,1)) translateZ(0);grid-auto-rows:calc(var(--card-height) - var(--header-height)) auto}.${def.notice.card}__body:active{--scale:0.96;}.${def.notice.card}__body-cover-image{position:absolute;top:8px;left:10px;z-index:100;width:32px;height:32px}.${def.notice.card}__body-cover-image span.${def.notice.favicons}{display:block;width:32px;height:32px}.${def.notice.card}__body-cover-chackbox{position:absolute;top:10px;right:10px;z-index:1;width:28px;height:28px;border:2px solid var(--chack-border,#fff);border-radius:50%;background:var(--chack-bg,var(--background-chackbox));opacity:var(--chack-opacity,0);transition:transform var(--transition),opacity calc(var(--transition)*1.2) linear,-webkit-transform var(--transition) ease;-webkit-transform:scale(var(--chack-scale,0));transform:scale(var(--chack-scale,0))}.${def.notice.card}__body-cover-chackbox--svg{display:inline-block;visibility:visible!important;margin:8px 0 0 7px;width:13px;height:11px;vertical-align:top;-webkit-transition:stroke-dashoffset .4s ease var(--transition);transition:stroke-dashoffset .4s ease var(--transition);fill:none;stroke:var(--stroke-color,#fff);stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:16px;stroke-dashoffset:var(--stroke-dashoffset,16px)}` +
`.${def.notice.card}__body-header{padding:4px 10px 6px 50px;height:var(--header-height);background:var(--background)}.${def.notice.card}__body-header-title{margin-bottom:0!important;color:var(--text-headline);font-weight:700!important;font-size:15px!important}.${def.notice.card}__body-header-subtitle{color:var(--text-color);font-weight:500;font-size:13px!important}.${def.notice.noticejs} .${def.notice.configuration} .${def.notice.settingList} .${def.notice.grid}{display:grid;grid-template-columns:repeat(1, 1fr);grid-gap:10px;}#${def.notice.random}_help{position:relative;margin:0;padding:4px 15px!important;border:1px solid transparent;background:#f07f6a;box-shadow:0 0 6px 0 #f5846f;color:#ffffff;cursor:help}#${def.notice.random}_help:hover{background:#ed6248;box-shadow:0 0 6px 0 #f34525;}#${def.notice.random}_clear{margin:0 0 0 10px;color:#666666;font-weight:500;cursor:pointer}#${def.notice.random}_clear:hover{color:red}#${def.notice.random}_clear u{padding:0 2px;text-decoration:none}.${def.notice.linkerror},.${def.notice.linkerror}:hover,.${def.notice.linkerror} *,.${def.notice.linkerror} *:hover{color:grey!important;text-decoration-line:line-through!important;text-decoration-color:red!important;text-decoration-style:wavy!important}`
);
/* INITIALIZE_GMNOTIFICATION_FUNCTION */
const defaultOpt = {
title: "",
text: "",
type: def.notice.success,
position: "bottomRight",
newestOnTop: false,
timeout: 30,
progressBar: true,
closeWith: ["button"],
animation: {
open: `${def.notice.animated} ${def.notice.random}_fadeIn`,
close: `${def.notice.animated} ${def.notice.random}_fadeOut`,
},
modal: false,
width: 400,
scroll: { maxHeight: 400, showOnHover: false },
rtl: false,
callbacks: { beforeShow: [], onShow: [], afterShow: [], onClose: [], afterClose: [], onClick: [], onHover: [], onTemplate: [] },
};
const options = defaultOpt;
function getCallback(ref, eventName) {
if (ref.callbacks.hasOwnProperty(eventName)) {
ref.callbacks[eventName].forEach(cb => {
if (typeof cb === "function") cb.apply(ref);
});
}
}
function addModal() {
const modalElements = qA(`.${def.notice.noticejs}-modal`);
if (modalElements.length === 0) {
const element = cE("div");
element.classList.add(`${def.notice.noticejs}-modal`);
element.classList.add(`${def.notice.noticejs}-modal-open`);
document.documentElement.appendChild(element);
sleep(2e2).then(() => (element.className = `${def.notice.noticejs}-modal`));
}
}
function closeItem(item, immed = false) {
getCallback(options, "onClose");
if (options.animation?.close) {
item.className += ` ${options.animation.close}`;
}
sleep(immed ? 0 : 2e2).then(() => item.remove());
if (options.modal && qA(`[${def.notice.noticejs}-modal='true']`).length >= 1) {
qS(`.${def.notice.noticejs}-modal`).className += ` ${def.notice.noticejs}-modal-close`;
sleep(5e2).then(() => qS(`.${def.notice.noticejs}-modal`).remove());
}
const closetNode = item.closest(`.${def.notice.noticejs}`);
const closetNodeCName = closetNode?.className?.replace(def.notice.noticejs, "").trim() ?? `${def.notice.noticejs}-bottomRight`;
const position = `.${closetNodeCName}`;
sleep(5e2).then(() => {
if (qA(position + ` .${def.notice.item}`).length === 0) qS(position)?.remove();
});
}
function addListener(item) {
const closeBtn = item.querySelector(`.${def.notice.close}`);
const handleClick = () => closeItem(item);
if (options.closeWith.includes("button")) closeBtn?.addEventListener("click", handleClick);
if (options.closeWith?.includes("click")) {
item.style.cursor = "pointer";
item.addEventListener("click", e => {
if (e.target.className !== def.notice.close) {
getCallback(options, "onClick");
handleClick();
}
});
} else {
item.addEventListener("click", e => e.target.className !== def.notice.close && getCallback(options, "onClick"));
}
item.addEventListener("mouseover", () => getCallback(options, "onHover"));
}
function appendNoticeJs(noticeJsHeader, noticeJsBody, noticeJsProgressBar) {
const target_class = `.${def.notice.noticejs}-` + options.position;
const noticeJsItem = cE("div");
noticeJsItem.classList.add(def.notice.item);
noticeJsItem.classList.add(options.type);
if (options.rtl === true) noticeJsItem.classList.add(`${def.notice.noticejs}-rtl`);
if (options.width !== "" && Number.isInteger(options.width)) noticeJsItem.style.width = options.width + "px";
if (noticeJsHeader && noticeJsHeader.nodeType === Node.ELEMENT_NODE) noticeJsItem.appendChild(noticeJsHeader);
if (noticeJsBody.nodeType === Node.ELEMENT_NODE) noticeJsItem.appendChild(noticeJsBody);
if (noticeJsProgressBar && noticeJsProgressBar !== "" && noticeJsProgressBar.nodeType === Node.ELEMENT_NODE) noticeJsItem.appendChild(noticeJsProgressBar);
if (["top", "bottom"].includes(options.position)) qS(target_class).textContent = "";
if (options.animation !== null && options.animation.open !== null) noticeJsItem.className += " " + options.animation.open;
if (options.modal === true) {
noticeJsItem.setAttribute(`${def.notice.noticejs}-modal`, "true");
addModal();
}
addListener(noticeJsItem);
getCallback(options, "beforeShow");
getCallback(options, "onShow");
if (options.newestOnTop === true) {
qS(target_class)?.insertAdjacentElement("afterbegin", noticeJsItem);
} else {
qS(target_class)?.appendChild(noticeJsItem);
}
getCallback(options, "afterShow");
return noticeJsItem;
}
class Components {
constructor(options) {
this.options = options;
}
createContainer() {
const element_class = `${def.notice.noticejs}-${this.options.position}`;
const element = cE("gb-notice");
element.classList.add(def.notice.noticejs);
element.classList.add(element_class);
element.id = element_class;
element.style.display = "block";
return element;
}
createHeader() {
let element;
const { options } = this;
if (options.title) {
element = cE("div");
element.setAttribute("class", `${def.notice.noticejs}-heading`);
element.innerHTML = tTP.createHTML(`<span class="${def.notice.noticejs}-heading-title" title="${options.title}">${options.title}</span>`);
}
if (options.closeWith.includes("button")) {
const close = cE("div");
close.setAttribute("class", def.notice.close);
close.innerHTML = tTP.createHTML("×");
if (element) {
element.appendChild(close);
} else {
element = close;
}
}
return element;
}
createBody() {
const { options } = this;
const element = cE("div");
element.setAttribute("class", `${def.notice.noticejs}-body`);
const content = cE("div");
content.setAttribute("class", `${def.notice.noticejs}-content`);
content.innerHTML = tTP.createHTML(options.text);
element.appendChild(content);
if (options.scroll !== null && options.scroll.maxHeight !== "") {
element.style.overflowY = "auto";
element.style.maxHeight = `min(calc(100vh - 100px), ${options.scroll.maxHeight}px)`;
if (options.scroll.showOnHover === true) element.style.visibility = "hidden";
}
return element;
}
createProgressBar() {
const { options } = this;
const element = cE("div");
element.setAttribute("class", `${def.notice.noticejs}-progressbar`);
const bar = cE("div");
bar.setAttribute("class", `${def.notice.noticejs}-bar`);
element.appendChild(bar);
if (options.progressBar === true && typeof options.timeout !== "boolean" && options.timeout !== false) {
let width = 1e2;
const progress = raf.setInterval(() => {
if (width <= 0) {
raf.clearInterval(progress);
let item = element.closest(`div.${def.notice.item}`);
if (options.animation !== null && options.animation.close !== null) {
item.className = item.className.replace(new RegExp("(?:^|\\s)" + options.animation.open + "(?:\\s|$)"), " ");
item.className += " " + options.animation.close;
const close_time = parseInt(options.timeout) + 5e2;
sleep(close_time).then(() => closeItem(item));
} else {
closeItem(item);
}
} else {
width--;
bar.style.width = width + "%";
}
}, options.timeout);
}
return element;
}
}
class NoticeJs {
constructor(options = {}) {
this.options = Object.assign(defaultOpt, options);
this.component = new Components(this.options);
this.registerCallbacks();
}
show() {
let container = this.component.createContainer();
if (document.documentElement && !qS(`.${def.notice.noticejs}-${this.options.position}`)) {
document.documentElement.appendChild(container);
}
let noticeJsHeader = this.component.createHeader(this.options.title, this.options.closeWith);
let noticeJsBody = this.component.createBody(this.options.text);
let noticeJsProgressBar = null;
if (this.options.progressBar === true) noticeJsProgressBar = this.component.createProgressBar();
const noticeJs = appendNoticeJs(noticeJsHeader, noticeJsBody, noticeJsProgressBar);
return noticeJs;
}
registerCallbacks() {
Object.keys(this.options.callbacks).forEach(eventName => {
const cb = this.options.callbacks[eventName];
if (typeof cb === "function") this.on(eventName, cb);
});
}
on(eventName, cb = () => {}) {
if (typeof cb === "function" && this.options.callbacks.hasOwnProperty(eventName)) {
this.options.callbacks[eventName].push(cb);
}
return this;
}
static overrideDefaults(options) {
this.options = Object.assign(defaultOpt, options);
return this;
}
}
function GMnotification({ title, text, type, scroll, width, closeWith, newestOnTop, progressBar, timeout, callbacks, position } = {}) {
try {
new NoticeJs({
title: title || "",
text: text,
type: type || def.notice.success,
width: width || 400,
newestOnTop: newestOnTop || false,
closeWith: closeWith || ["button"],
progressBar: progressBar ?? true,
timeout: timeout ?? 30,
scroll: scroll || { maxHeight: 400, showOnHover: true },
callbacks: { ...callbacks },
position: position || "bottomRight",
}).show();
} catch (e) {
ERROR("GMnotification:", e.message);
}
}
/* GMSET/GET/DELETEVALUE_WITH_CACHE */
const cache = {
value: (data, eT = 6048e5) => {
return { data: data, expired: Date.now() + eT };
},
set: (key, ...options) => GMsetValue(key, encrypt(JSON.stringify(cache.value(...options)))),
get: async key => {
const obj = await GMgetValue(key);
if (!obj) return null;
try {
const value = JSON.parse(decrypt(obj));
const data = value.data;
const expiredTime = value.expired;
const curTime = Date.now();
if (expiredTime > curTime && data) {
return data;
} else {
cache.remove(key);
return null;
}
} catch (e) {
ERROR("Cache.get:", e.message);
cache.remove(key);
return null;
}