@whitesev/utils 2.9.9 → 2.9.10
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/dist/index.amd.js +3199 -3214
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +3199 -3214
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +3199 -3214
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +3199 -3214
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +3199 -3214
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +3199 -3214
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +1 -1
- package/dist/types/src/Log.d.ts +1 -2
- package/dist/types/src/Utils.d.ts +44 -44
- package/dist/types/src/types/ajaxHooker.d.ts +3 -1
- package/package.json +10 -8
- package/src/Httpx.ts +2 -2
- package/src/Log.ts +34 -59
- package/src/Utils.ts +57 -57
- package/src/types/ajaxHooker.d.ts +3 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HttpxHookErrorData,
|
|
1
|
+
import type { HttpxHookErrorData, HttpxInitOption, HttpxPromise, HttpxRequestOption, HttpxResponse, HttpxResponseData } from "./types/Httpx";
|
|
2
2
|
export declare class Httpx {
|
|
3
3
|
#private;
|
|
4
4
|
private GM_Api;
|
package/dist/types/src/Log.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { ColorConversion } from "./ColorConversion";
|
|
2
|
+
import { UtilsDictionary } from "./Dictionary";
|
|
2
3
|
import { GBKEncoder } from "./GBKEncoder";
|
|
3
|
-
import { UtilsGMCookie } from "./UtilsGMCookie";
|
|
4
|
-
import { GMMenu } from "./UtilsGMMenu";
|
|
5
4
|
import { Hooks } from "./Hooks";
|
|
6
5
|
import { Httpx } from "./Httpx";
|
|
7
6
|
import { indexedDB } from "./indexedDB";
|
|
8
7
|
import { LockFunction } from "./LockFunction";
|
|
9
8
|
import { Log } from "./Log";
|
|
9
|
+
import { ModuleRaid } from "./ModuleRaid";
|
|
10
10
|
import { Progress } from "./Progress";
|
|
11
|
-
import { UtilsDictionary } from "./Dictionary";
|
|
12
11
|
import type { UtilsAjaxHookResult } from "./types/ajaxHooker";
|
|
13
|
-
import { Vue } from "./Vue";
|
|
14
12
|
import { type ArgsType, type JSTypeNames, type UtilsOwnObject } from "./types/global";
|
|
15
|
-
import type { WindowApiOption } from "./types/WindowApi";
|
|
16
|
-
import { ModuleRaid } from "./ModuleRaid";
|
|
17
13
|
import type { ReactInstance } from "./types/React";
|
|
14
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
15
|
+
import { UtilsGMCookie } from "./UtilsGMCookie";
|
|
16
|
+
import { GMMenu } from "./UtilsGMMenu";
|
|
17
|
+
import { Vue } from "./Vue";
|
|
18
18
|
declare class Utils {
|
|
19
19
|
private windowApi;
|
|
20
20
|
constructor(option?: WindowApiOption);
|
|
@@ -616,43 +616,43 @@ declare class Utils {
|
|
|
616
616
|
**/
|
|
617
617
|
Hooks: typeof Hooks;
|
|
618
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
|
-
|
|
619
|
+
* 为减少代码量和回调,把GM_xmlhttpRequest封装
|
|
620
|
+
* 文档地址: https://www.tampermonkey.net/documentation.php?ext=iikm
|
|
621
|
+
* 其中onloadstart、onprogress、onreadystatechange是回调形式,onabort、ontimeout、onerror可以设置全局回调函数
|
|
622
|
+
* @param _GM_xmlHttpRequest_ 油猴中的GM_xmlhttpRequest
|
|
623
|
+
* @example
|
|
624
|
+
let httpx = new Utils.Httpx(GM_xmlhttpRequest);
|
|
625
|
+
let postResp = await httpx.post({
|
|
626
|
+
url:url,
|
|
627
|
+
data:JSON.stringify({
|
|
628
|
+
test:1
|
|
629
|
+
}),
|
|
630
|
+
timeout: 5000
|
|
631
|
+
});
|
|
632
|
+
console.log(postResp);
|
|
633
|
+
> {
|
|
634
|
+
status: true,
|
|
635
|
+
data: {responseText: "...", response: xxx,...},
|
|
636
|
+
msg: "请求完毕",
|
|
637
|
+
type: "onload",
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if(postResp === "onload" && postResp.status){
|
|
641
|
+
// onload
|
|
642
|
+
}else if(postResp === "ontimeout"){
|
|
643
|
+
// ontimeout
|
|
644
|
+
}
|
|
645
|
+
* @example
|
|
646
|
+
// 也可以先配置全局参数
|
|
647
|
+
let httpx = new Utils.Httpx(GM_xmlhttpRequest);
|
|
648
|
+
httpx.config({
|
|
649
|
+
timeout: 5000,
|
|
650
|
+
async: false,
|
|
651
|
+
responseType: "html",
|
|
652
|
+
redirect: "follow",
|
|
653
|
+
})
|
|
654
|
+
// 优先级为 默认details < 全局details < 单独的details
|
|
655
|
+
*/
|
|
656
656
|
Httpx: typeof Httpx;
|
|
657
657
|
/**
|
|
658
658
|
* 浏览器端的indexedDB操作封装
|
|
@@ -1295,7 +1295,7 @@ declare class Utils {
|
|
|
1295
1295
|
run<A extends any[], R>(callback: ((...args: A) => R) | string | ((...args: any[]) => any), __context__?: any): import("./types/TryCatch").UtilsTryCatchType;
|
|
1296
1296
|
};
|
|
1297
1297
|
/**
|
|
1298
|
-
*
|
|
1298
|
+
* 数组去重,去除重复的值,返回新的数组(不修改原数组)
|
|
1299
1299
|
* @param uniqueArrayData 需要去重的数组
|
|
1300
1300
|
* @param compareArrayData 用来比较的数组
|
|
1301
1301
|
* @param compareFun 数组比较方法,如果值相同,去除该数据
|
|
@@ -89,7 +89,9 @@ export declare interface UtilsAjaxHookFilterOptions {
|
|
|
89
89
|
/** Utils.ajaxHooker */
|
|
90
90
|
export declare interface UtilsAjaxHookResult {
|
|
91
91
|
/**
|
|
92
|
-
* 劫持
|
|
92
|
+
* 劫持xhr和fetch
|
|
93
|
+
*
|
|
94
|
+
* 提示:如果多次调用.hook方法,将会多次处理同一个请求
|
|
93
95
|
* @example
|
|
94
96
|
ajaxHooker.hook(request => {
|
|
95
97
|
if (request.url === 'https://www.example.com/') {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@whitesev/utils",
|
|
4
|
-
"version": "2.9.
|
|
4
|
+
"version": "2.9.10",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "一个常用的工具库",
|
|
7
7
|
"main": "dist/index.cjs.js",
|
|
@@ -36,27 +36,29 @@
|
|
|
36
36
|
"author": "WhiteSev",
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"worker-timers": "^8.0.
|
|
39
|
+
"worker-timers": "^8.0.26"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@eslint/js": "^9.39.
|
|
42
|
+
"@eslint/js": "^9.39.2",
|
|
43
43
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
44
44
|
"@rollup/plugin-json": "^6.1.0",
|
|
45
45
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
46
46
|
"@rollup/plugin-terser": "^0.4.4",
|
|
47
47
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
48
|
+
"@types/node": "^25.0.3",
|
|
49
|
+
"browserslist": "^4.28.1",
|
|
50
|
+
"caniuse-lite": "^1.0.30001760",
|
|
51
|
+
"eslint": "^9.39.2",
|
|
51
52
|
"eslint-config-prettier": "^10.1.8",
|
|
52
53
|
"eslint-plugin-compat": "^6.0.2",
|
|
53
54
|
"eslint-plugin-prettier": "^5.5.4",
|
|
54
55
|
"globals": "^16.5.0",
|
|
55
|
-
"
|
|
56
|
+
"rolldown": "1.0.0-beta.55",
|
|
57
|
+
"rollup": "^4.53.5",
|
|
56
58
|
"rollup-plugin-clear": "^2.0.7",
|
|
57
59
|
"tslib": "^2.8.1",
|
|
58
60
|
"typescript": "^5.9.3",
|
|
59
|
-
"typescript-eslint": "^8.
|
|
61
|
+
"typescript-eslint": "^8.50.0"
|
|
60
62
|
},
|
|
61
63
|
"scripts": {
|
|
62
64
|
"lint": "eslint .",
|
package/src/Httpx.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { TryCatch } from "./TryCatch";
|
|
|
3
3
|
import type {
|
|
4
4
|
HttpxAllowInterceptConfig,
|
|
5
5
|
HttpxHookErrorData,
|
|
6
|
+
HttpxInitOption,
|
|
6
7
|
HttpxMethod,
|
|
8
|
+
HttpxPromise,
|
|
7
9
|
HttpxRequestOption,
|
|
8
10
|
HttpxResponse,
|
|
9
11
|
HttpxResponseData,
|
|
10
|
-
HttpxPromise,
|
|
11
|
-
HttpxInitOption,
|
|
12
12
|
} from "./types/Httpx";
|
|
13
13
|
import { GenerateUUID } from "./UtilsCommon";
|
|
14
14
|
|
package/src/Log.ts
CHANGED
|
@@ -12,23 +12,22 @@ export class Log {
|
|
|
12
12
|
/* 配置 */
|
|
13
13
|
#details: UtilsLogOptions = {
|
|
14
14
|
tag: true,
|
|
15
|
-
successColor: "#
|
|
16
|
-
errorColor: "#FF0000",
|
|
17
|
-
infoColor: "
|
|
18
|
-
warnColor: "
|
|
15
|
+
successColor: "background: #0eac0eff;",
|
|
16
|
+
errorColor: "background: #FF0000;",
|
|
17
|
+
infoColor: "background: #6495ed;",
|
|
18
|
+
warnColor: "background: #ff8c00;",
|
|
19
19
|
debug: false,
|
|
20
20
|
autoClearConsole: false,
|
|
21
21
|
logMaxCount: 999,
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* 通用样式配置
|
|
25
25
|
*/
|
|
26
|
-
#
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
];
|
|
26
|
+
#commonStyleConfig = {
|
|
27
|
+
commonStyle: "color: #ffffff; padding: 3px; border-radius: 3px;line-height: 1;margin-right: 6px;",
|
|
28
|
+
tagStyle: "background: #6495ed;",
|
|
29
|
+
callerNameStyle: "background: #78909C;",
|
|
30
|
+
};
|
|
32
31
|
/**
|
|
33
32
|
* @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
|
|
34
33
|
* @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
|
|
@@ -112,61 +111,36 @@ export class Log {
|
|
|
112
111
|
/**
|
|
113
112
|
* 输出内容
|
|
114
113
|
* @param msg 需要输出的内容
|
|
115
|
-
* @param
|
|
116
|
-
* @param otherStyle 其它CSS
|
|
114
|
+
* @param tagColor tag颜色
|
|
117
115
|
*/
|
|
118
|
-
private printContent(msg: any[],
|
|
116
|
+
private printContent(msg: any[], tagColor?: string) {
|
|
119
117
|
this.checkClearConsole();
|
|
120
|
-
otherStyle = otherStyle || "";
|
|
121
118
|
const stackSplit = new Error()!.stack!.split("\n");
|
|
122
119
|
stackSplit.splice(0, 2);
|
|
123
120
|
const { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
|
|
124
121
|
const tagName = this.tag;
|
|
125
122
|
const that = this;
|
|
126
123
|
|
|
124
|
+
const msgColorDetails: string[] = [];
|
|
125
|
+
// 控制台输出的tag的html格式
|
|
126
|
+
let consoleHTML = `%c${tagName}`;
|
|
127
127
|
/** tag的html输出格式 */
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
callerNameHTML = `-${callerNameHTML}`;
|
|
128
|
+
if (typeof tagColor === "string" && tagColor.trim() !== "") {
|
|
129
|
+
msgColorDetails.push(that.#commonStyleConfig.commonStyle + tagColor);
|
|
130
|
+
} else {
|
|
131
|
+
msgColorDetails.push(that.#commonStyleConfig.commonStyle + that.#commonStyleConfig.tagStyle);
|
|
133
132
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
that.#console.log(
|
|
141
|
-
`${tagNameHTML}${callerNameHTML} %s`,
|
|
142
|
-
...that.#msgColorDetails,
|
|
143
|
-
`color: ${color};${otherStyle}`,
|
|
144
|
-
message
|
|
145
|
-
);
|
|
146
|
-
} else if (typeof message === "number") {
|
|
147
|
-
that.#console.log(
|
|
148
|
-
`${tagNameHTML}${callerNameHTML} %d`,
|
|
149
|
-
...that.#msgColorDetails,
|
|
150
|
-
`color: ${color};${otherStyle}`,
|
|
151
|
-
message
|
|
152
|
-
);
|
|
153
|
-
} else if (typeof message === "object") {
|
|
154
|
-
that.#console.log(
|
|
155
|
-
`${tagNameHTML}${callerNameHTML} %o`,
|
|
156
|
-
...that.#msgColorDetails,
|
|
157
|
-
`color: ${color};${otherStyle}`,
|
|
158
|
-
message
|
|
159
|
-
);
|
|
160
|
-
} else {
|
|
161
|
-
that.#console.log(message);
|
|
162
|
-
}
|
|
133
|
+
// 调用的函数名的html输出格式
|
|
134
|
+
if (callerName.trim() == "") {
|
|
135
|
+
// 无调用函数名
|
|
136
|
+
} else {
|
|
137
|
+
consoleHTML = `${consoleHTML}%c${callerName}`;
|
|
138
|
+
msgColorDetails.push(that.#commonStyleConfig.commonStyle + that.#commonStyleConfig.callerNameStyle);
|
|
163
139
|
}
|
|
164
140
|
if (Array.isArray(msg)) {
|
|
165
|
-
|
|
166
|
-
consoleMsg(msg[index]);
|
|
167
|
-
}
|
|
141
|
+
that.#console.log(`${consoleHTML}`, ...msgColorDetails, ...msg);
|
|
168
142
|
} else {
|
|
169
|
-
|
|
143
|
+
that.#console.log(`${consoleHTML}`, ...msgColorDetails, msg);
|
|
170
144
|
}
|
|
171
145
|
if (this.#details.debug) {
|
|
172
146
|
/* 如果开启调试模式,输出堆栈位置 */
|
|
@@ -191,7 +165,8 @@ export class Log {
|
|
|
191
165
|
*/
|
|
192
166
|
warn(...args: any[]) {
|
|
193
167
|
if (this.#disable) return;
|
|
194
|
-
|
|
168
|
+
// , "background: #FEF6D5;padding: 4px 6px 4px 0px;"
|
|
169
|
+
this.printContent(args, this.#details.warnColor);
|
|
195
170
|
}
|
|
196
171
|
/**
|
|
197
172
|
* 控制台-错误输出
|
|
@@ -230,11 +205,11 @@ export class Log {
|
|
|
230
205
|
/** 堆栈位置 */
|
|
231
206
|
const stackFunctionNamePosition = errorStackParse.position;
|
|
232
207
|
const callerName = stackFunctionName;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
);
|
|
208
|
+
const msgColorDetails: string[] = [
|
|
209
|
+
`${this.#commonStyleConfig.commonStyle + this.#details.infoColor}`,
|
|
210
|
+
`${this.#commonStyleConfig.commonStyle + this.#commonStyleConfig.callerNameStyle}`,
|
|
211
|
+
];
|
|
212
|
+
this.#console.log(`%c${this.tag}%c${callerName}%c`, msgColorDetails);
|
|
238
213
|
this.#console.table(msg);
|
|
239
214
|
if (this.#details.debug) {
|
|
240
215
|
this.#console.log(stackFunctionNamePosition);
|
package/src/Utils.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
clearInterval as WorkerClearInterval,
|
|
3
|
+
clearTimeout as WorkerClearTimeout,
|
|
4
|
+
setInterval as WorkerSetInterval,
|
|
5
|
+
setTimeout as WorkerSetTimeout,
|
|
6
|
+
} from "worker-timers";
|
|
7
|
+
import { version } from "./../package.json";
|
|
4
8
|
import { ajaxHooker } from "./ajaxHooker/ajaxHooker.js";
|
|
5
9
|
import { AjaxHooker1_2_4 } from "./ajaxHooker/ajaxHooker1.2.4";
|
|
6
|
-
import {
|
|
10
|
+
import { ColorConversion } from "./ColorConversion";
|
|
11
|
+
import { CommonUtil } from "./CommonUtil";
|
|
12
|
+
import { UtilsDictionary } from "./Dictionary";
|
|
13
|
+
import { domUtils } from "./DOMUtils";
|
|
14
|
+
import { GBKEncoder } from "./GBKEncoder";
|
|
7
15
|
import { Hooks } from "./Hooks";
|
|
8
16
|
import { Httpx } from "./Httpx";
|
|
9
17
|
import { indexedDB } from "./indexedDB";
|
|
10
18
|
import { LockFunction } from "./LockFunction";
|
|
11
19
|
import { Log } from "./Log";
|
|
20
|
+
import { ModuleRaid } from "./ModuleRaid";
|
|
12
21
|
import { Progress } from "./Progress";
|
|
13
22
|
import { TryCatch } from "./TryCatch";
|
|
14
|
-
import { UtilsDictionary } from "./Dictionary";
|
|
15
23
|
import type { UtilsAjaxHookResult } from "./types/ajaxHooker";
|
|
16
|
-
import { GenerateUUID } from "./UtilsCommon";
|
|
17
|
-
import { WindowApi } from "./WindowApi";
|
|
18
|
-
import { Vue } from "./Vue";
|
|
19
24
|
import { type ArgsType, type JSTypeNames, type UtilsOwnObject } from "./types/global";
|
|
20
|
-
import type { WindowApiOption } from "./types/WindowApi";
|
|
21
|
-
import {
|
|
22
|
-
clearInterval as WorkerClearInterval,
|
|
23
|
-
clearTimeout as WorkerClearTimeout,
|
|
24
|
-
setInterval as WorkerSetInterval,
|
|
25
|
-
setTimeout as WorkerSetTimeout,
|
|
26
|
-
} from "worker-timers";
|
|
27
|
-
import { ModuleRaid } from "./ModuleRaid";
|
|
28
|
-
import { domUtils } from "./DOMUtils";
|
|
29
|
-
import { CommonUtil } from "./CommonUtil";
|
|
30
25
|
import type { ReactInstance } from "./types/React";
|
|
31
|
-
import {
|
|
26
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
27
|
+
import { GenerateUUID } from "./UtilsCommon";
|
|
28
|
+
import { UtilsGMCookie } from "./UtilsGMCookie";
|
|
29
|
+
import { GMMenu } from "./UtilsGMMenu";
|
|
30
|
+
import { Vue } from "./Vue";
|
|
31
|
+
import { WindowApi } from "./WindowApi";
|
|
32
32
|
|
|
33
33
|
class Utils {
|
|
34
34
|
private windowApi: typeof WindowApi.prototype;
|
|
@@ -1293,43 +1293,43 @@ class Utils {
|
|
|
1293
1293
|
Hooks = Hooks;
|
|
1294
1294
|
|
|
1295
1295
|
/**
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1296
|
+
* 为减少代码量和回调,把GM_xmlhttpRequest封装
|
|
1297
|
+
* 文档地址: https://www.tampermonkey.net/documentation.php?ext=iikm
|
|
1298
|
+
* 其中onloadstart、onprogress、onreadystatechange是回调形式,onabort、ontimeout、onerror可以设置全局回调函数
|
|
1299
|
+
* @param _GM_xmlHttpRequest_ 油猴中的GM_xmlhttpRequest
|
|
1300
|
+
* @example
|
|
1301
|
+
let httpx = new Utils.Httpx(GM_xmlhttpRequest);
|
|
1302
|
+
let postResp = await httpx.post({
|
|
1303
|
+
url:url,
|
|
1304
|
+
data:JSON.stringify({
|
|
1305
|
+
test:1
|
|
1306
|
+
}),
|
|
1307
|
+
timeout: 5000
|
|
1308
|
+
});
|
|
1309
|
+
console.log(postResp);
|
|
1310
|
+
> {
|
|
1311
|
+
status: true,
|
|
1312
|
+
data: {responseText: "...", response: xxx,...},
|
|
1313
|
+
msg: "请求完毕",
|
|
1314
|
+
type: "onload",
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
if(postResp === "onload" && postResp.status){
|
|
1318
|
+
// onload
|
|
1319
|
+
}else if(postResp === "ontimeout"){
|
|
1320
|
+
// ontimeout
|
|
1321
|
+
}
|
|
1322
|
+
* @example
|
|
1323
|
+
// 也可以先配置全局参数
|
|
1324
|
+
let httpx = new Utils.Httpx(GM_xmlhttpRequest);
|
|
1325
|
+
httpx.config({
|
|
1326
|
+
timeout: 5000,
|
|
1327
|
+
async: false,
|
|
1328
|
+
responseType: "html",
|
|
1329
|
+
redirect: "follow",
|
|
1330
|
+
})
|
|
1331
|
+
// 优先级为 默认details < 全局details < 单独的details
|
|
1332
|
+
*/
|
|
1333
1333
|
Httpx = Httpx;
|
|
1334
1334
|
/**
|
|
1335
1335
|
* 浏览器端的indexedDB操作封装
|
|
@@ -3209,7 +3209,7 @@ class Utils {
|
|
|
3209
3209
|
*/
|
|
3210
3210
|
tryCatch = TryCatch;
|
|
3211
3211
|
/**
|
|
3212
|
-
*
|
|
3212
|
+
* 数组去重,去除重复的值,返回新的数组(不修改原数组)
|
|
3213
3213
|
* @param uniqueArrayData 需要去重的数组
|
|
3214
3214
|
* @param compareArrayData 用来比较的数组
|
|
3215
3215
|
* @param compareFun 数组比较方法,如果值相同,去除该数据
|
|
@@ -89,7 +89,9 @@ export declare interface UtilsAjaxHookFilterOptions {
|
|
|
89
89
|
/** Utils.ajaxHooker */
|
|
90
90
|
export declare interface UtilsAjaxHookResult {
|
|
91
91
|
/**
|
|
92
|
-
* 劫持
|
|
92
|
+
* 劫持xhr和fetch
|
|
93
|
+
*
|
|
94
|
+
* 提示:如果多次调用.hook方法,将会多次处理同一个请求
|
|
93
95
|
* @example
|
|
94
96
|
ajaxHooker.hook(request => {
|
|
95
97
|
if (request.url === 'https://www.example.com/') {
|