@whitesev/utils 2.8.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -176
- package/dist/index.amd.js +893 -874
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +893 -874
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +893 -874
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +893 -874
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +893 -874
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +893 -874
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/CommonUtil.d.ts +59 -59
- package/dist/types/src/DOMUtils.d.ts +1 -1
- package/dist/types/src/Dictionary.d.ts +1 -1
- package/dist/types/src/Httpx.d.ts +2 -2
- package/dist/types/src/Progress.d.ts +0 -4
- package/dist/types/src/TryCatch.d.ts +2 -2
- package/dist/types/src/Utils.d.ts +365 -365
- package/dist/types/src/UtilsGMCookie.d.ts +2 -2
- package/dist/types/src/UtilsGMMenu.d.ts +1 -1
- package/dist/types/src/indexedDB.d.ts +3 -3
- package/dist/types/src/types/Event.d.ts +188 -188
- package/dist/types/src/types/Httpx.d.ts +1344 -1343
- package/dist/types/src/types/Log.d.ts +19 -19
- package/dist/types/src/types/Progress.d.ts +20 -20
- package/dist/types/src/types/React.d.ts +119 -119
- package/dist/types/src/types/TryCatch.d.ts +9 -9
- package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
- package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
- package/dist/types/src/types/Vue2.d.ts +166 -166
- package/dist/types/src/types/WindowApi.d.ts +14 -14
- package/dist/types/src/types/ajaxHooker.d.ts +151 -151
- package/dist/types/src/types/env.d.ts +7 -2
- package/dist/types/src/types/global.d.ts +31 -31
- package/package.json +16 -7
- package/src/ColorConversion.ts +105 -106
- package/src/CommonUtil.ts +280 -279
- package/src/DOMUtils.ts +251 -272
- package/src/Dictionary.ts +153 -154
- package/src/GBKEncoder.ts +108 -112
- package/src/Hooks.ts +73 -81
- package/src/Httpx.ts +1457 -1466
- package/src/LockFunction.ts +62 -62
- package/src/Log.ts +258 -259
- package/src/ModuleRaid.js +1 -0
- package/src/Progress.ts +108 -114
- package/src/TryCatch.ts +86 -86
- package/src/Utils.ts +4772 -4825
- package/src/UtilsCommon.ts +14 -14
- package/src/UtilsGMCookie.ts +254 -261
- package/src/UtilsGMMenu.ts +445 -454
- package/src/Vue.ts +233 -229
- package/src/WindowApi.ts +59 -59
- package/src/ajaxHooker/ajaxHooker.js +1 -0
- package/src/indexedDB.ts +497 -502
- package/src/types/Event.d.ts +188 -188
- package/src/types/Httpx.d.ts +1344 -1343
- package/src/types/Log.d.ts +19 -19
- package/src/types/Progress.d.ts +20 -20
- package/src/types/React.d.ts +119 -119
- package/src/types/TryCatch.d.ts +9 -9
- package/src/types/UtilsGMCookie.d.ts +93 -93
- package/src/types/UtilsGMMenu.d.ts +77 -77
- package/src/types/Vue2.d.ts +166 -166
- package/src/types/WindowApi.d.ts +14 -14
- package/src/types/ajaxHooker.d.ts +151 -151
- package/src/types/env.d.ts +7 -2
- package/src/types/global.d.ts +31 -31
|
@@ -31,20 +31,20 @@ declare class Utils {
|
|
|
31
31
|
*/
|
|
32
32
|
addStyle(cssText: string): HTMLStyleElement;
|
|
33
33
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
* JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
|
|
35
|
+
* @param target 目标数据
|
|
36
|
+
* @param source 源数据
|
|
37
|
+
* @param isAdd 是否可以追加键,默认false
|
|
38
|
+
* @example
|
|
39
|
+
* Utils.assign({"1":1,"2":{"3":3}}, {"2":{"3":4}});
|
|
40
|
+
* >
|
|
41
|
+
* {
|
|
42
|
+
"1": 1,
|
|
43
|
+
"2": {
|
|
44
|
+
"3": 4
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
*/
|
|
48
48
|
assign: <T1, T2 extends object, T3 extends boolean>(target: T1, source: T2, isAdd?: T3 | undefined) => T3 extends true ? T1 & T2 : T1;
|
|
49
49
|
/**
|
|
50
50
|
* 异步替换字符串
|
|
@@ -343,7 +343,7 @@ declare class Utils {
|
|
|
343
343
|
* Utils.getArrayLastValue([1,2,3,4,5]);
|
|
344
344
|
* > 5
|
|
345
345
|
*/
|
|
346
|
-
getArrayLastValue<R
|
|
346
|
+
getArrayLastValue<R = unknown>(targetObj: NodeList | any[]): R;
|
|
347
347
|
/**
|
|
348
348
|
* 应用场景: 当想获取的元素可能是不同的选择器的时候,按顺序优先级获取
|
|
349
349
|
* 参数类型可以是Element或者是Function
|
|
@@ -498,7 +498,7 @@ declare class Utils {
|
|
|
498
498
|
* Utils.getRandomValue(1,9,6,99)
|
|
499
499
|
* > 6
|
|
500
500
|
*/
|
|
501
|
-
getRandomValue<T
|
|
501
|
+
getRandomValue<T>(...args: T[]): T;
|
|
502
502
|
/**
|
|
503
503
|
* 获取随机值
|
|
504
504
|
* @example
|
|
@@ -508,7 +508,7 @@ declare class Utils {
|
|
|
508
508
|
* Utils.getRandomValue({1:"结果1",2:"结果2",3:"结果3"}})
|
|
509
509
|
* > 结果2
|
|
510
510
|
*/
|
|
511
|
-
getRandomValue<T
|
|
511
|
+
getRandomValue<T>(val: T[] | UtilsOwnObject<T>): T;
|
|
512
512
|
/**
|
|
513
513
|
* 获取两个数之间随机值
|
|
514
514
|
* @example
|
|
@@ -522,7 +522,7 @@ declare class Utils {
|
|
|
522
522
|
* Utils.getRandomValue({1:1},{2:2})
|
|
523
523
|
* > {1: 1}
|
|
524
524
|
*/
|
|
525
|
-
getRandomValue<T
|
|
525
|
+
getRandomValue<T>(val_1: UtilsOwnObject<T>, val_2: UtilsOwnObject<T>): T;
|
|
526
526
|
/**
|
|
527
527
|
* 获取元素上的使用React框架的实例属性,目前包括reactFiber、reactProps、reactEvents、reactEventHandlers、reactInternalInstance
|
|
528
528
|
* @param element 需要获取的目标元素
|
|
@@ -562,85 +562,72 @@ declare class Utils {
|
|
|
562
562
|
*/
|
|
563
563
|
getThunderUrl(url: string): string;
|
|
564
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
|
-
|
|
565
|
+
* 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
|
|
566
|
+
* @example
|
|
567
|
+
let GM_cookie = new Utils.GM_Cookie();
|
|
568
|
+
GM_cookie.list({name:"xxx_cookie_xxx"},function(cookies,error){
|
|
569
|
+
if (!error) {
|
|
570
|
+
console.log(cookies);
|
|
571
|
+
console.log(cookies.value);
|
|
572
|
+
} else {
|
|
573
|
+
console.error(error);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
GM_cookie.set({name:"xxx_cookie_test_xxx",value:"这是Cookie测试值"},function(error){
|
|
577
|
+
if (error) {
|
|
578
|
+
console.error(error);
|
|
579
|
+
} else {
|
|
580
|
+
console.log('Cookie set successfully.');
|
|
581
|
+
}
|
|
582
|
+
})
|
|
583
|
+
GM_cookie.delete({name:"xxx_cookie_test_xxx"},function(error){
|
|
584
|
+
if (error) {
|
|
585
|
+
console.error(error);
|
|
586
|
+
} else {
|
|
587
|
+
console.log('Cookie set successfully.');
|
|
588
|
+
}
|
|
589
|
+
})
|
|
590
|
+
**/
|
|
591
591
|
GM_Cookie: typeof UtilsGMCookie;
|
|
592
592
|
/**
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
593
|
+
* 注册油猴菜单,要求本地存储的键名不能存在其它键名`GM_Menu_Local_Map`会冲突/覆盖
|
|
594
|
+
* @example
|
|
595
|
+
let GM_Menu = new Utils.GM_Menu({
|
|
596
|
+
data: [
|
|
597
|
+
{
|
|
598
|
+
menu_key: "menu_key",
|
|
599
|
+
text: "测试按钮",
|
|
600
|
+
enable: true,
|
|
601
|
+
accessKey: "a",
|
|
602
|
+
autoClose: false,
|
|
603
|
+
showText(text, enable) {
|
|
604
|
+
return "[" + (enable ? "√" : "×") + "]" + text;
|
|
605
|
+
},
|
|
606
|
+
callback(data) {
|
|
607
|
+
console.log("点击菜单,值修改为", data.enable);
|
|
608
|
+
},
|
|
608
609
|
},
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
text: "测试按钮2",
|
|
631
|
-
enable: false,
|
|
632
|
-
showText(text,enable){
|
|
633
|
-
return "[" + (enable ? "√" : "×") + "]" + text;
|
|
634
|
-
},
|
|
635
|
-
callback(data){
|
|
636
|
-
console.log("点击菜单,值修改为",data.enable);
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
// 使用数组的方式添加多个菜单,如menu_key3、menu_key4
|
|
640
|
-
GM_Menu.add([
|
|
641
|
-
{
|
|
642
|
-
key:"menu_key3",
|
|
643
|
-
text: "测试按钮3",
|
|
610
|
+
],
|
|
611
|
+
autoReload: false,
|
|
612
|
+
GM_getValue,
|
|
613
|
+
GM_setValue,
|
|
614
|
+
GM_registerMenuCommand,
|
|
615
|
+
GM_unregisterMenuCommand,
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
// 获取某个菜单项的值
|
|
620
|
+
GM_Menu.get("menu_key");
|
|
621
|
+
> true
|
|
622
|
+
|
|
623
|
+
// 获取某个菜单项的开启/关闭后显示的文本
|
|
624
|
+
GM_Menu.getShowTextValue("menu_key");
|
|
625
|
+
> √测试按钮
|
|
626
|
+
|
|
627
|
+
// 添加键为menu_key2的菜单项
|
|
628
|
+
GM_Menu.add({
|
|
629
|
+
key:"menu_key2",
|
|
630
|
+
text: "测试按钮2",
|
|
644
631
|
enable: false,
|
|
645
632
|
showText(text,enable){
|
|
646
633
|
return "[" + (enable ? "√" : "×") + "]" + text;
|
|
@@ -648,127 +635,140 @@ declare class Utils {
|
|
|
648
635
|
callback(data){
|
|
649
636
|
console.log("点击菜单,值修改为",data.enable);
|
|
650
637
|
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
638
|
+
});
|
|
639
|
+
// 使用数组的方式添加多个菜单,如menu_key3、menu_key4
|
|
640
|
+
GM_Menu.add([
|
|
641
|
+
{
|
|
642
|
+
key:"menu_key3",
|
|
643
|
+
text: "测试按钮3",
|
|
644
|
+
enable: false,
|
|
645
|
+
showText(text,enable){
|
|
646
|
+
return "[" + (enable ? "√" : "×") + "]" + text;
|
|
647
|
+
},
|
|
648
|
+
callback(data){
|
|
649
|
+
console.log("点击菜单,值修改为",data.enable);
|
|
650
|
+
}
|
|
658
651
|
},
|
|
659
|
-
|
|
660
|
-
|
|
652
|
+
{
|
|
653
|
+
key:"menu_key4",
|
|
654
|
+
text: "测试按钮4",
|
|
655
|
+
enable: false,
|
|
656
|
+
showText(text,enable){
|
|
657
|
+
return "[" + (enable ? "√" : "×") + "]" + text;
|
|
658
|
+
},
|
|
659
|
+
callback(data){
|
|
660
|
+
console.log("点击菜单,值修改为",data.enable);
|
|
661
|
+
}
|
|
661
662
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
663
|
+
]);
|
|
664
|
+
|
|
665
|
+
// 更新键为menu_key的显示文字和点击回调
|
|
666
|
+
GM_Menu.update({
|
|
667
|
+
menu_key:{
|
|
668
|
+
text: "更新后的测试按钮",
|
|
669
|
+
enable: true,
|
|
670
|
+
showText(text,enable){
|
|
671
|
+
return "[" + (enable ? "√" : "×") + "]" + text;
|
|
672
|
+
},
|
|
673
|
+
callback(data){
|
|
674
|
+
console.log("点击菜单更新后的测试按钮,新值修改为",data.enable);
|
|
675
|
+
}
|
|
675
676
|
}
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
**/
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
// 删除键为menu_key的菜单
|
|
680
|
+
GM_Menu.delete("menu_key");
|
|
681
|
+
**/
|
|
682
682
|
GM_Menu: typeof GMMenu;
|
|
683
683
|
/**
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
684
|
+
* 基于Function prototype,能够勾住和释放任何函数
|
|
685
|
+
*
|
|
686
|
+
* .hook
|
|
687
|
+
* + realFunc {string} 用于保存原始函数的函数名称,用于unHook
|
|
688
|
+
* + hookFunc {string} 替换的hook函数
|
|
689
|
+
* + context {object} 目标函数所在对象,用于hook非window对象下的函数,如String.protype.slice,carInstance1
|
|
690
|
+
* + methodName {string} 匿名函数需显式传入目标函数名eg:this.Begin = function(){....};}
|
|
691
|
+
*
|
|
692
|
+
* .unhook
|
|
693
|
+
* + realFunc {string} 用于保存原始函数的函数名称,用于unHook
|
|
694
|
+
* + funcName {string} 被Hook的函数名称
|
|
695
|
+
* + context {object} 目标函数所在对象,用于hook非window对象下的函数,如String.protype.slice,carInstance1
|
|
696
|
+
* @example
|
|
697
|
+
let hook = new Utils.Hooks();
|
|
698
|
+
hook.initEnv();
|
|
699
|
+
function myFunction(){
|
|
700
|
+
console.log("我自己需要执行的函数");
|
|
701
|
+
}
|
|
702
|
+
function testFunction(){
|
|
703
|
+
console.log("正常执行的函数");
|
|
704
|
+
}
|
|
705
|
+
testFunction.hook(testFunction,myFunction,window);
|
|
706
|
+
**/
|
|
707
707
|
Hooks: typeof Hooks;
|
|
708
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
|
-
|
|
709
|
+
* 为减少代码量和回调,把GM_xmlhttpRequest封装
|
|
710
|
+
* 文档地址: https://www.tampermonkey.net/documentation.php?ext=iikm
|
|
711
|
+
* 其中onloadstart、onprogress、onreadystatechange是回调形式,onabort、ontimeout、onerror可以设置全局回调函数
|
|
712
|
+
* @param _GM_xmlHttpRequest_ 油猴中的GM_xmlhttpRequest
|
|
713
|
+
* @example
|
|
714
|
+
let httpx = new Utils.Httpx(GM_xmlhttpRequest);
|
|
715
|
+
let postResp = await httpx.post({
|
|
716
|
+
url:url,
|
|
717
|
+
data:JSON.stringify({
|
|
718
|
+
test:1
|
|
719
|
+
}),
|
|
720
|
+
timeout: 5000
|
|
721
|
+
});
|
|
722
|
+
console.log(postResp);
|
|
723
|
+
> {
|
|
724
|
+
status: true,
|
|
725
|
+
data: {responseText: "...", response: xxx,...},
|
|
726
|
+
msg: "请求完毕",
|
|
727
|
+
type: "onload",
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
if(postResp === "onload" && postResp.status){
|
|
731
|
+
// onload
|
|
732
|
+
}else if(postResp === "ontimeout"){
|
|
733
|
+
// ontimeout
|
|
734
|
+
}
|
|
735
|
+
* @example
|
|
736
|
+
// 也可以先配置全局参数
|
|
737
|
+
let httpx = new Utils.Httpx(GM_xmlhttpRequest);
|
|
738
|
+
httpx.config({
|
|
739
|
+
timeout: 5000,
|
|
740
|
+
async: false,
|
|
741
|
+
responseType: "html",
|
|
742
|
+
redirect: "follow",
|
|
743
|
+
})
|
|
744
|
+
// 优先级为 默认details < 全局details < 单独的details
|
|
745
|
+
*/
|
|
746
746
|
Httpx: typeof Httpx;
|
|
747
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
|
-
|
|
748
|
+
* 浏览器端的indexedDB操作封装
|
|
749
|
+
* @example
|
|
750
|
+
let db = new Utils.indexedDB('web_DB', 'nav_text')
|
|
751
|
+
let data = {name:'管理员', roleId: 1, type: 1};
|
|
752
|
+
db.save('list',data).then((resolve)=>{
|
|
753
|
+
console.log(resolve,'存储成功')
|
|
754
|
+
})
|
|
755
|
+
|
|
756
|
+
db.get('list').then((resolve)=>{
|
|
757
|
+
console.log(resolve,'查询成功')
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
db.getPaging('list',20,10).then((resolve)=>{
|
|
761
|
+
console.log(resolve,'查询分页偏移第20,一共10行成功');
|
|
762
|
+
})
|
|
763
|
+
|
|
764
|
+
db.delete('list').then(resolve=>{
|
|
765
|
+
console.log(resolve,'删除成功---->>>>>>name')
|
|
766
|
+
})
|
|
767
|
+
|
|
768
|
+
db.deleteAll().then(resolve=>{
|
|
769
|
+
console.log(resolve,'清除数据库---->>>>>>name')
|
|
770
|
+
})
|
|
771
|
+
**/
|
|
772
772
|
indexedDB: typeof indexedDB;
|
|
773
773
|
/**
|
|
774
774
|
* 判断目标函数是否是Native Code
|
|
@@ -780,7 +780,7 @@ declare class Utils {
|
|
|
780
780
|
* Utils.isNativeFunc(window.location.assign)
|
|
781
781
|
* > true
|
|
782
782
|
*/
|
|
783
|
-
isNativeFunc(target:
|
|
783
|
+
isNativeFunc(target: (...args: any[]) => any): boolean;
|
|
784
784
|
/**
|
|
785
785
|
* 判断当前的位置是否位于页面底部附近
|
|
786
786
|
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
@@ -852,50 +852,50 @@ declare class Utils {
|
|
|
852
852
|
(...args: any[]): boolean;
|
|
853
853
|
};
|
|
854
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
|
-
|
|
855
|
+
* 判断对象或数据是否为空
|
|
856
|
+
* + `String`判空的值,如 ""、"null"、"undefined"、" "
|
|
857
|
+
* + `Number`判空的值,如 0
|
|
858
|
+
* + `Object`判空的值,如 {}、null、undefined
|
|
859
|
+
* + `Array`(存在属性Symbol.iterator)判空的值,如 []
|
|
860
|
+
* + `Boolean`判空的值,如false
|
|
861
|
+
* + `Function`判空的值,如()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){}
|
|
862
|
+
* @returns
|
|
863
|
+
* + true 为空
|
|
864
|
+
* + false 不为空
|
|
865
|
+
* @example
|
|
866
|
+
Utils.isNull({});
|
|
867
|
+
> true
|
|
868
|
+
* @example
|
|
869
|
+
Utils.isNull([]);
|
|
870
|
+
> true
|
|
871
|
+
* @example
|
|
872
|
+
Utils.isNull(" ");
|
|
873
|
+
> true
|
|
874
|
+
* @example
|
|
875
|
+
Utils.isNull(function(){});
|
|
876
|
+
> true
|
|
877
|
+
* @example
|
|
878
|
+
Utils.isNull(()=>{}));
|
|
879
|
+
> true
|
|
880
|
+
* @example
|
|
881
|
+
Utils.isNull("undefined");
|
|
882
|
+
> true
|
|
883
|
+
* @example
|
|
884
|
+
Utils.isNull("null");
|
|
885
|
+
> true
|
|
886
|
+
* @example
|
|
887
|
+
Utils.isNull(" ", false);
|
|
888
|
+
> true
|
|
889
|
+
* @example
|
|
890
|
+
Utils.isNull([1],[]);
|
|
891
|
+
> false
|
|
892
|
+
* @example
|
|
893
|
+
Utils.isNull([],[1]);
|
|
894
|
+
> false
|
|
895
|
+
* @example
|
|
896
|
+
Utils.isNull(false,[123]);
|
|
897
|
+
> false
|
|
898
|
+
**/
|
|
899
899
|
isNull: {
|
|
900
900
|
<T>(value: T | undefined | null): value is null | undefined;
|
|
901
901
|
(...args: any[]): boolean;
|
|
@@ -946,48 +946,48 @@ declare class Utils {
|
|
|
946
946
|
* Utils.parseObjectToArray({"工具类":"jsonToArray","return","Array"});
|
|
947
947
|
* > ['jsonToArray', 'Array']
|
|
948
948
|
**/
|
|
949
|
-
parseObjectToArray<T
|
|
950
|
-
/**
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
949
|
+
parseObjectToArray<T>(target: T): T[keyof T][];
|
|
950
|
+
/**
|
|
951
|
+
* 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
|
|
952
|
+
* @example
|
|
953
|
+
let lock = new Utils.LockFunction(()=>{console.log(1)}))
|
|
954
|
+
lock.run();
|
|
955
|
+
> 1
|
|
956
|
+
* @example
|
|
957
|
+
let lock = new Utils.LockFunction(()=>{console.log(1)}),true) -- 异步操作
|
|
958
|
+
await lock.run();
|
|
959
|
+
> 1
|
|
960
|
+
**/
|
|
961
961
|
LockFunction: typeof LockFunction;
|
|
962
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
|
-
|
|
963
|
+
* 日志对象
|
|
964
|
+
* @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}}
|
|
965
|
+
* @example
|
|
966
|
+
let log = new Utils.Log(GM_info);
|
|
967
|
+
log.info("普通输出");
|
|
968
|
+
> 普通输出
|
|
969
|
+
|
|
970
|
+
log.success("成功输出");
|
|
971
|
+
> 成功输出
|
|
972
|
+
|
|
973
|
+
log.error("错误输出");
|
|
974
|
+
> 错误输出
|
|
975
|
+
|
|
976
|
+
log.warn("警告输出");
|
|
977
|
+
> 警告输出
|
|
978
|
+
|
|
979
|
+
log.tag = "自定义tag信息";
|
|
980
|
+
log.info("自定义info的颜色","#e0e0e0");
|
|
981
|
+
> 自定义info的颜色
|
|
982
|
+
|
|
983
|
+
log.config({
|
|
984
|
+
successColor: "#31dc02",
|
|
985
|
+
errorColor: "#e02d2d",
|
|
986
|
+
infoColor: "black",
|
|
987
|
+
})
|
|
988
|
+
log.success("颜色为#31dc02");
|
|
989
|
+
> 颜色为#31dc02
|
|
990
|
+
*/
|
|
991
991
|
Log: typeof Log;
|
|
992
992
|
/**
|
|
993
993
|
* 合并数组内的JSON的值字符串
|
|
@@ -997,27 +997,27 @@ declare class Utils {
|
|
|
997
997
|
* Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
|
|
998
998
|
* > '数组内数据部分字段合并成字符串->mergeToString'
|
|
999
999
|
**/
|
|
1000
|
-
mergeArrayToString<T
|
|
1001
|
-
/**
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1000
|
+
mergeArrayToString<T>(data: T[], handleFunc?: ((val: T) => T) | keyof T): string;
|
|
1001
|
+
/**
|
|
1002
|
+
* 监听页面元素改变并处理
|
|
1003
|
+
* @param target 需要监听的元素,如果不存在,可以等待它出现
|
|
1004
|
+
* @param observer_config MutationObserver的配置
|
|
1005
|
+
* @example
|
|
1006
|
+
Utils.mutationObserver(document.querySelector("div.xxxx"),{
|
|
1007
|
+
"callback":(mutations, observer)=>{},
|
|
1008
|
+
"config":{childList:true,attributes:true}
|
|
1009
|
+
});
|
|
1010
|
+
* @example
|
|
1011
|
+
Utils.mutationObserver(document.querySelectorAll("div.xxxx"),{
|
|
1012
|
+
"callback":(mutations, observer)=>{},
|
|
1013
|
+
"config":{childList:true,attributes:true}}
|
|
1014
|
+
);
|
|
1015
|
+
* @example
|
|
1016
|
+
Utils.mutationObserver($("div.xxxx"),{
|
|
1012
1017
|
"callback":(mutations, observer)=>{},
|
|
1013
1018
|
"config":{childList:true,attributes:true}}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
Utils.mutationObserver($("div.xxxx"),{
|
|
1017
|
-
"callback":(mutations, observer)=>{},
|
|
1018
|
-
"config":{childList:true,attributes:true}}
|
|
1019
|
-
);
|
|
1020
|
-
**/
|
|
1019
|
+
);
|
|
1020
|
+
**/
|
|
1021
1021
|
mutationObserver(target: HTMLElement | Node | NodeList | Document, observer_config: {
|
|
1022
1022
|
/**
|
|
1023
1023
|
* observer的配置
|
|
@@ -1051,37 +1051,37 @@ declare class Utils {
|
|
|
1051
1051
|
*/
|
|
1052
1052
|
noConflict(): Utils;
|
|
1053
1053
|
/**
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1054
|
+
* 恢复/释放该对象内的为function,让它无效/有效
|
|
1055
|
+
* @param needReleaseObject 需要操作的对象
|
|
1056
|
+
* @param needReleaseName 需要操作的对象的名字
|
|
1057
|
+
* @param functionNameList (可选)需要释放的方法,默认:全部方法
|
|
1058
|
+
* @param release (可选)
|
|
1059
|
+
* + true (默认) 释放该对象下的某些方法
|
|
1060
|
+
* + false 恢复该对象下的某些方法
|
|
1061
|
+
* @example
|
|
1062
|
+
// 释放该方法
|
|
1063
|
+
Utils.noConflictFunc(console,"console",["log"],true);
|
|
1064
|
+
console.log;
|
|
1065
|
+
> () => {}
|
|
1066
|
+
|
|
1067
|
+
* @example
|
|
1068
|
+
// 恢复该方法
|
|
1069
|
+
Utils.noConflictFunc(console,"console",["log"],false);
|
|
1070
|
+
console.log;
|
|
1071
|
+
> ƒ log() { [native code] }
|
|
1072
|
+
|
|
1073
|
+
* @example
|
|
1074
|
+
// 释放所有方法
|
|
1075
|
+
Utils.noConflictFunc(console,"console",[],true);
|
|
1076
|
+
console.debug;
|
|
1077
|
+
> () => {}
|
|
1078
|
+
|
|
1079
|
+
* @example
|
|
1080
|
+
// 恢复所有方法
|
|
1081
|
+
Utils.noConflictFunc(console,"console",[],false);
|
|
1082
|
+
console.debug;
|
|
1083
|
+
> ƒ log() { [native code] }
|
|
1084
|
+
**/
|
|
1085
1085
|
noConflictFunc(needReleaseObject: object, needReleaseName: string, functionNameList?: any[], release?: boolean): void;
|
|
1086
1086
|
/**
|
|
1087
1087
|
* base64转blob
|
|
@@ -1196,11 +1196,11 @@ declare class Utils {
|
|
|
1196
1196
|
*/
|
|
1197
1197
|
preventEvent(element: HTMLElement, eventNameList?: string | string[], capture?: boolean): boolean;
|
|
1198
1198
|
/**
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1199
|
+
* 在canvas元素节点上绘制进度圆圈
|
|
1200
|
+
* @example
|
|
1201
|
+
let progress = new Utils.Process({canvasNode:document.querySelector("canvas")});
|
|
1202
|
+
progress.draw();
|
|
1203
|
+
* **/
|
|
1204
1204
|
Progress: typeof Progress;
|
|
1205
1205
|
/**
|
|
1206
1206
|
* 劫持Event的isTrust为true,注入时刻,ducument-start
|
|
@@ -1290,11 +1290,11 @@ declare class Utils {
|
|
|
1290
1290
|
enterFullScreen(element: HTMLElement, options?: FullscreenOptions): void;
|
|
1291
1291
|
/**
|
|
1292
1292
|
* 使浏览器退出全屏
|
|
1293
|
-
* @param
|
|
1293
|
+
* @param $el (可选)目标元素,默认:document.documentElement
|
|
1294
1294
|
* @example
|
|
1295
1295
|
* Utils.exitFullScreen();
|
|
1296
1296
|
*/
|
|
1297
|
-
exitFullScreen(
|
|
1297
|
+
exitFullScreen($el?: HTMLElement | HTMLDocument | Document): Promise<void>;
|
|
1298
1298
|
/**
|
|
1299
1299
|
* 数组按照内部某个值的大小比对排序,如[{"time":"2022-1-1"},{"time":"2022-2-2"}]
|
|
1300
1300
|
* @param data 数据|获取数据的方法
|
|
@@ -1310,7 +1310,7 @@ declare class Utils {
|
|
|
1310
1310
|
* Utils.sortListByProperty([{"time":"2022-1-1"},{"time":"2022-2-2"}],(item)=>{return item["time"]},false)
|
|
1311
1311
|
* > [{time: '2022-1-1'},{time: '2022-2-2'}]
|
|
1312
1312
|
**/
|
|
1313
|
-
sortListByProperty<T
|
|
1313
|
+
sortListByProperty<T>(data: T[], getPropertyValueFunc: string | ((value: T) => any), sortByDesc?: boolean): T[];
|
|
1314
1314
|
/**
|
|
1315
1315
|
* 字符串转正则,用于把字符串中不规范的字符进行转义
|
|
1316
1316
|
* @param targetString 需要进行转换的字符串
|
|
@@ -1372,7 +1372,7 @@ declare class Utils {
|
|
|
1372
1372
|
/**
|
|
1373
1373
|
* 将UrlSearchParams格式的字符串转为对象
|
|
1374
1374
|
*/
|
|
1375
|
-
searchParamStrToObj<T
|
|
1375
|
+
searchParamStrToObj<T>(searhParamsStr?: string | null | undefined): T;
|
|
1376
1376
|
/**
|
|
1377
1377
|
* 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
1378
1378
|
* @example
|
|
@@ -1384,8 +1384,8 @@ declare class Utils {
|
|
|
1384
1384
|
*/
|
|
1385
1385
|
tryCatch: (...args: any) => {
|
|
1386
1386
|
config(paramDetails: import("./types/TryCatch").UtilsTryCatchConfig): /*elided*/ any;
|
|
1387
|
-
error(handler: ((...args: any[]) => any) | string |
|
|
1388
|
-
run<A extends any[], R>(callback: ((...args: A) => R) | string |
|
|
1387
|
+
error(handler: ((...args: any[]) => any) | string | ((...args: any[]) => any)): /*elided*/ any;
|
|
1388
|
+
run<A extends any[], R>(callback: ((...args: A) => R) | string | ((...args: any[]) => any), __context__?: any): import("./types/TryCatch").UtilsTryCatchType;
|
|
1389
1389
|
};
|
|
1390
1390
|
/**
|
|
1391
1391
|
* 数组去重,去除重复的值
|
|
@@ -1405,7 +1405,7 @@ declare class Utils {
|
|
|
1405
1405
|
* Utils.uniqueArray([{"key":1,"value":2},{"key":2}],[{"key":1}],(item,item2)=>{return item["key"] === item2["key"] ? true:false});
|
|
1406
1406
|
* > [{"key": 2}]
|
|
1407
1407
|
**/
|
|
1408
|
-
uniqueArray<T
|
|
1408
|
+
uniqueArray<T, TT>(uniqueArrayData?: T[], compareArrayData?: TT[], compareFun?: (item1: T, item2: TT) => boolean): any[];
|
|
1409
1409
|
/**
|
|
1410
1410
|
* 数组去重,去除不需要的值
|
|
1411
1411
|
* @param uniqueArrayData 需要过滤的数组
|
|
@@ -1422,7 +1422,7 @@ declare class Utils {
|
|
|
1422
1422
|
* @example
|
|
1423
1423
|
* await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
|
|
1424
1424
|
**/
|
|
1425
|
-
waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc:
|
|
1425
|
+
waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: (...args: any[]) => any): Promise<void[]>;
|
|
1426
1426
|
/**
|
|
1427
1427
|
* 等待任意事件成立
|
|
1428
1428
|
*
|
|
@@ -1439,7 +1439,7 @@ declare class Utils {
|
|
|
1439
1439
|
* }
|
|
1440
1440
|
* })
|
|
1441
1441
|
*/
|
|
1442
|
-
wait<T
|
|
1442
|
+
wait<T>(checkFn: (...args: any[]) => {
|
|
1443
1443
|
/**
|
|
1444
1444
|
* 是否检测成功
|
|
1445
1445
|
*/
|
|
@@ -1449,7 +1449,7 @@ declare class Utils {
|
|
|
1449
1449
|
*/
|
|
1450
1450
|
data: T;
|
|
1451
1451
|
}, timeout?: null | undefined, parent?: Node | Element | Document | HTMLElement): Promise<T>;
|
|
1452
|
-
wait<T
|
|
1452
|
+
wait<T>(checkFn: (...args: any[]) => {
|
|
1453
1453
|
/**
|
|
1454
1454
|
* 是否检测成功
|
|
1455
1455
|
*/
|
|
@@ -1468,8 +1468,8 @@ declare class Utils {
|
|
|
1468
1468
|
* console.log($div); // $div => HTMLDivELement | null
|
|
1469
1469
|
* })
|
|
1470
1470
|
*/
|
|
1471
|
-
waitNode<K
|
|
1472
|
-
waitNode<K
|
|
1471
|
+
waitNode<K>(selectorFn: () => K | null | undefined): Promise<K>;
|
|
1472
|
+
waitNode<K>(selectorFn: () => K | null | undefined, timeout: number): Promise<K | null | undefined>;
|
|
1473
1473
|
/**
|
|
1474
1474
|
* 等待元素出现
|
|
1475
1475
|
* @param selector CSS选择器
|
|
@@ -1704,7 +1704,7 @@ declare class Utils {
|
|
|
1704
1704
|
* > "test success set"
|
|
1705
1705
|
*
|
|
1706
1706
|
*/
|
|
1707
|
-
waitProperty<T
|
|
1707
|
+
waitProperty<T>(checkObj: any | (() => any), checkPropertyName: string): Promise<T>;
|
|
1708
1708
|
/**
|
|
1709
1709
|
* 在规定时间内等待对象上的属性出现
|
|
1710
1710
|
* @param checkObj 检查的对象
|
|
@@ -1715,7 +1715,7 @@ declare class Utils {
|
|
|
1715
1715
|
* await Utils.waitPropertyByInterval(window,"test");
|
|
1716
1716
|
* console.log("test success set");
|
|
1717
1717
|
*/
|
|
1718
|
-
waitPropertyByInterval<T
|
|
1718
|
+
waitPropertyByInterval<T>(checkObj: any | (() => any), checkPropertyName: string | ((obj: any) => boolean), intervalTimer?: number, maxTime?: number): Promise<T>;
|
|
1719
1719
|
/**
|
|
1720
1720
|
* 在规定时间内等待元素上的__vue__属性或者__vue__属性上的某个值出现出现
|
|
1721
1721
|
* @param element 目标元素
|
|
@@ -1757,7 +1757,7 @@ declare class Utils {
|
|
|
1757
1757
|
* @param target 待获取的对象
|
|
1758
1758
|
* @param handler 获取属性的回调
|
|
1759
1759
|
*/
|
|
1760
|
-
queryProperty<T
|
|
1760
|
+
queryProperty<T = any>(target: any, handler: (target: T) => {
|
|
1761
1761
|
/**
|
|
1762
1762
|
* 是否是需要的属性
|
|
1763
1763
|
* + `true` 将目标值赋值给data
|
|
@@ -1774,7 +1774,7 @@ declare class Utils {
|
|
|
1774
1774
|
* @param target 待获取的对象
|
|
1775
1775
|
* @param handler 获取属性的回调
|
|
1776
1776
|
*/
|
|
1777
|
-
asyncQueryProperty<T
|
|
1777
|
+
asyncQueryProperty<T = any>(target: any, handler: (target: T) => {
|
|
1778
1778
|
/**
|
|
1779
1779
|
* 是否是需要的属性
|
|
1780
1780
|
* + true 将目标值赋值给data
|
|
@@ -1856,7 +1856,7 @@ declare class Utils {
|
|
|
1856
1856
|
* @param callback 回调函数
|
|
1857
1857
|
* @param [timeout=0] 延迟时间,默认为0
|
|
1858
1858
|
*/
|
|
1859
|
-
workerSetTimeout(callback:
|
|
1859
|
+
workerSetTimeout(callback: (...args: any[]) => any, timeout?: number): number;
|
|
1860
1860
|
/**
|
|
1861
1861
|
* 配合 .setTimeout 使用
|
|
1862
1862
|
* @param timeId setTimeout 返回的`id`
|
|
@@ -1867,7 +1867,7 @@ declare class Utils {
|
|
|
1867
1867
|
* @param callback 回调函数
|
|
1868
1868
|
* @param timeout 间隔时间,默认为0
|
|
1869
1869
|
*/
|
|
1870
|
-
workerSetInterval(callback:
|
|
1870
|
+
workerSetInterval(callback: (...args: any[]) => any, timeout?: number): number;
|
|
1871
1871
|
/**
|
|
1872
1872
|
* 配合 .setInterval 使用
|
|
1873
1873
|
* @param timeId setInterval 返回的`id`
|
|
@@ -1887,5 +1887,5 @@ declare class Utils {
|
|
|
1887
1887
|
content: string;
|
|
1888
1888
|
}>;
|
|
1889
1889
|
}
|
|
1890
|
-
declare
|
|
1890
|
+
declare const utils: Utils;
|
|
1891
1891
|
export { utils as Utils };
|