@whitesev/utils 2.8.0 → 2.8.2
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 +896 -875
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +896 -875
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +896 -875
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +896 -875
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +896 -875
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +896 -875
- 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/index.ts +3 -0
- package/package.json +19 -8
- 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 +4773 -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
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
import type { HttpxHeaders, HttpxMethod, HttpxStatus } from "./Httpx";
|
|
2
|
-
|
|
3
|
-
/** 请求的response配置 */
|
|
4
|
-
export declare interface UtilsAjaxHookResponseOptions {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** hook请求的配置 */
|
|
28
|
-
export declare interface UtilsAjaxHookRequestOptions {
|
|
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
|
-
export declare interface UtilsAjaxHookFilterOptions {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Utils.ajaxHooker */
|
|
90
|
-
export declare interface UtilsAjaxHookResult {
|
|
91
|
-
|
|
92
|
-
* 劫持
|
|
93
|
-
* @example
|
|
94
|
-
ajaxHooker.hook(request => {
|
|
95
|
-
if (request.url === 'https://www.example.com/') {
|
|
96
|
-
request.response = res => {
|
|
97
|
-
console.log(res);
|
|
98
|
-
res.responseText += 'test';
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
* @example
|
|
103
|
-
// 异步特性无法作用于同步请求,但同步修改仍然有效
|
|
104
|
-
// 你可以将以上所有可修改属性赋值为Promise,原请求将被阻塞直至Promise完成(若发生reject,数据将不会被修改)
|
|
105
|
-
// 此特性可用于异步劫持。以下是一个异步修改响应数据的例子
|
|
106
|
-
ajaxHooker.hook(request => {
|
|
107
|
-
request.response = res => {
|
|
108
|
-
const responseText = res.responseText; // 注意保存原数据
|
|
109
|
-
res.responseText = new Promise(resolve => {
|
|
110
|
-
setTimeout(() => {
|
|
111
|
-
resolve(responseText + 'test');
|
|
112
|
-
}, 3000);
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// 也可以传入async回调函数以实现异步
|
|
118
|
-
ajaxHooker.hook(async request => {
|
|
119
|
-
request.data = await modifyData(request.data);
|
|
120
|
-
request.response = async res => {
|
|
121
|
-
res.responseText = await modifyResponse(res.responseText);
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
* 过滤
|
|
128
|
-
* @example
|
|
129
|
-
// 应于hook方法之前执行,此方法若尽早执行,有助于提升性能。
|
|
130
|
-
// 为hook方法设置过滤规则,只有符合规则的请求才会触发hook。过滤规则是一个对象数组,参考下例
|
|
131
|
-
ajaxHooker.filter([
|
|
132
|
-
{type: 'xhr', url: 'www.example.com', method: 'GET', async: true},
|
|
133
|
-
{url: /^http/},
|
|
134
|
-
]);
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
* 阻止xhr和fetch被改写
|
|
139
|
-
* @example
|
|
140
|
-
// 如果库劫持失败,可能是其他代码对xhr/fetch进行了二次劫持,protect方法会尝试阻止xhr和fetch被改写。应于document-start阶段尽早执行,部分网页下可能引发错误,谨慎使用。
|
|
141
|
-
ajaxHooker.protect();
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
* 取消劫持
|
|
146
|
-
* @example
|
|
147
|
-
// 将xhr和fetch恢复至劫持前的状态,调用此方法后,hook方法不再生效。
|
|
148
|
-
ajaxHooker.unhook();
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
}
|
|
1
|
+
import type { HttpxHeaders, HttpxMethod, HttpxStatus } from "./Httpx";
|
|
2
|
+
|
|
3
|
+
/** 请求的response配置 */
|
|
4
|
+
export declare interface UtilsAjaxHookResponseOptions {
|
|
5
|
+
/**
|
|
6
|
+
* (重定向后的)Url
|
|
7
|
+
*/
|
|
8
|
+
finalUrl: string;
|
|
9
|
+
/**
|
|
10
|
+
* 响应码
|
|
11
|
+
*/
|
|
12
|
+
status: HttpxStatus;
|
|
13
|
+
/**
|
|
14
|
+
* 响应头
|
|
15
|
+
*/
|
|
16
|
+
responseHeaders: HttpxHeaders;
|
|
17
|
+
/**
|
|
18
|
+
* 响应内容
|
|
19
|
+
*/
|
|
20
|
+
response?: string | Blob | ArrayBuffer | XMLDocument | FormData;
|
|
21
|
+
/**
|
|
22
|
+
* 响应内容文本
|
|
23
|
+
*/
|
|
24
|
+
responseText?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** hook请求的配置 */
|
|
28
|
+
export declare interface UtilsAjaxHookRequestOptions {
|
|
29
|
+
/**
|
|
30
|
+
* 只读属性。一个字符串,表明请求类型是xhr还是fetch
|
|
31
|
+
*/
|
|
32
|
+
type: "xhr";
|
|
33
|
+
/**
|
|
34
|
+
* 请求的Url
|
|
35
|
+
*/
|
|
36
|
+
url: string;
|
|
37
|
+
/**
|
|
38
|
+
* 请求的url和method,可以直接修改
|
|
39
|
+
*/
|
|
40
|
+
method: HttpxMethod;
|
|
41
|
+
/**
|
|
42
|
+
* 是否取消请求,设置为true即可取消本次请求
|
|
43
|
+
*/
|
|
44
|
+
abort: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 请求头,可以直接修改
|
|
47
|
+
*/
|
|
48
|
+
headers: HttpxHeaders;
|
|
49
|
+
/**
|
|
50
|
+
* 请求携带的数据,可以直接修改
|
|
51
|
+
*/
|
|
52
|
+
data?: any;
|
|
53
|
+
/**
|
|
54
|
+
* 响应内容,必须通过一个回调函数进行读取和修改。
|
|
55
|
+
*
|
|
56
|
+
* 响应内容为一个对象,包含finalUrl、status、responseHeaders和被读取的响应数据,除响应数据可修改,其他属性是只读的。
|
|
57
|
+
*
|
|
58
|
+
* 响应数据是哪个属性取决于哪个属性被读取,xhr可能的属性为response、responseText、responseXML,fetch可能的属性为arrayBuffer、blob、formData、json、text。
|
|
59
|
+
*
|
|
60
|
+
* 在控制台输出时,xhr响应将包含所有属性,但只有被读取过的属性具有明确的值。修改对应属性即可影响读取结果,进而实现响应数据的修改。
|
|
61
|
+
*/
|
|
62
|
+
response?: (res: Required<UtilsAjaxHookResponseOptions>) => void;
|
|
63
|
+
/**
|
|
64
|
+
* 只读属性。异步请求为true,同步请求为false,异步特性无法作用于同步请求
|
|
65
|
+
*/
|
|
66
|
+
async: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 过滤规则配置 */
|
|
70
|
+
export declare interface UtilsAjaxHookFilterOptions {
|
|
71
|
+
/**
|
|
72
|
+
* 应是xhr或fetch
|
|
73
|
+
*/
|
|
74
|
+
type?: "xhr" | "fetch";
|
|
75
|
+
/**
|
|
76
|
+
* 字符串或正则表达式,无需完全匹配
|
|
77
|
+
*/
|
|
78
|
+
url?: string;
|
|
79
|
+
/**
|
|
80
|
+
* 请求方法
|
|
81
|
+
*/
|
|
82
|
+
method?: HttpxMethod;
|
|
83
|
+
/**
|
|
84
|
+
* 是否异步
|
|
85
|
+
*/
|
|
86
|
+
async?: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Utils.ajaxHooker */
|
|
90
|
+
export declare interface UtilsAjaxHookResult {
|
|
91
|
+
/**
|
|
92
|
+
* 劫持
|
|
93
|
+
* @example
|
|
94
|
+
ajaxHooker.hook(request => {
|
|
95
|
+
if (request.url === 'https://www.example.com/') {
|
|
96
|
+
request.response = res => {
|
|
97
|
+
console.log(res);
|
|
98
|
+
res.responseText += 'test';
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
* @example
|
|
103
|
+
// 异步特性无法作用于同步请求,但同步修改仍然有效
|
|
104
|
+
// 你可以将以上所有可修改属性赋值为Promise,原请求将被阻塞直至Promise完成(若发生reject,数据将不会被修改)
|
|
105
|
+
// 此特性可用于异步劫持。以下是一个异步修改响应数据的例子
|
|
106
|
+
ajaxHooker.hook(request => {
|
|
107
|
+
request.response = res => {
|
|
108
|
+
const responseText = res.responseText; // 注意保存原数据
|
|
109
|
+
res.responseText = new Promise(resolve => {
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
resolve(responseText + 'test');
|
|
112
|
+
}, 3000);
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// 也可以传入async回调函数以实现异步
|
|
118
|
+
ajaxHooker.hook(async request => {
|
|
119
|
+
request.data = await modifyData(request.data);
|
|
120
|
+
request.response = async res => {
|
|
121
|
+
res.responseText = await modifyResponse(res.responseText);
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
*/
|
|
125
|
+
hook(callback: (request: UtilsAjaxHookRequestOptions) => void | Promise<undefined>): void;
|
|
126
|
+
/**
|
|
127
|
+
* 过滤
|
|
128
|
+
* @example
|
|
129
|
+
// 应于hook方法之前执行,此方法若尽早执行,有助于提升性能。
|
|
130
|
+
// 为hook方法设置过滤规则,只有符合规则的请求才会触发hook。过滤规则是一个对象数组,参考下例
|
|
131
|
+
ajaxHooker.filter([
|
|
132
|
+
{type: 'xhr', url: 'www.example.com', method: 'GET', async: true},
|
|
133
|
+
{url: /^http/},
|
|
134
|
+
]);
|
|
135
|
+
*/
|
|
136
|
+
filter(filterOptions: UtilsAjaxHookFilterOptions[]): void;
|
|
137
|
+
/**
|
|
138
|
+
* 阻止xhr和fetch被改写
|
|
139
|
+
* @example
|
|
140
|
+
// 如果库劫持失败,可能是其他代码对xhr/fetch进行了二次劫持,protect方法会尝试阻止xhr和fetch被改写。应于document-start阶段尽早执行,部分网页下可能引发错误,谨慎使用。
|
|
141
|
+
ajaxHooker.protect();
|
|
142
|
+
*/
|
|
143
|
+
protect(): void;
|
|
144
|
+
/**
|
|
145
|
+
* 取消劫持
|
|
146
|
+
* @example
|
|
147
|
+
// 将xhr和fetch恢复至劫持前的状态,调用此方法后,hook方法不再生效。
|
|
148
|
+
ajaxHooker.unhook();
|
|
149
|
+
*/
|
|
150
|
+
unhook(): void;
|
|
151
|
+
}
|
package/src/types/env.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
declare var
|
|
1
|
+
/* eslint-disable no-var */
|
|
2
|
+
declare var jQuery: any;
|
|
3
|
+
declare var unsafeWindow: Window;
|
|
4
|
+
|
|
5
|
+
declare var mozIndexedDB: IDBFactory | null;
|
|
6
|
+
declare var webkitIndexedDB: IDBFactory | null;
|
|
7
|
+
declare var msIndexedDB: IDBFactory | null;
|
package/src/types/global.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
export type JSTypeMap = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type JSTypeNames = keyof JSTypeMap;
|
|
13
|
-
|
|
14
|
-
export type ArgsType<T extends JSTypeNames[]> = {
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export declare interface UtilsOwnObject<V
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export declare interface AnyObject {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type PartialKeys<T, K extends keyof T> = {
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type Values<T> = T[keyof T];
|
|
1
|
+
export type JSTypeMap = {
|
|
2
|
+
string: string;
|
|
3
|
+
number: number;
|
|
4
|
+
boolean: boolean;
|
|
5
|
+
object: object;
|
|
6
|
+
symbol: symbol;
|
|
7
|
+
bigint: bigint;
|
|
8
|
+
undefined: undefined;
|
|
9
|
+
null: null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type JSTypeNames = keyof JSTypeMap;
|
|
13
|
+
|
|
14
|
+
export type ArgsType<T extends JSTypeNames[]> = {
|
|
15
|
+
[I in keyof T]: JSTypeMap[T[I]];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export declare interface UtilsOwnObject<V> {
|
|
19
|
+
[key: string]: V | UtilsOwnObject<V>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export declare interface AnyObject {
|
|
23
|
+
[key: string]: any | AnyObject;
|
|
24
|
+
toString(): string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type PartialKeys<T, K extends keyof T> = {
|
|
28
|
+
[P in K]?: T[P];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type Values<T> = T[keyof T];
|