@whitesev/utils 2.7.1 → 2.7.3
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 +260 -409
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +260 -409
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +260 -409
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +260 -409
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +260 -409
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +260 -409
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/ColorConversion.d.ts +3 -8
- package/dist/types/src/Dictionary.d.ts +21 -14
- package/dist/types/src/GBKEncoder.d.ts +1 -2
- package/dist/types/src/Hooks.d.ts +1 -2
- package/dist/types/src/Httpx.d.ts +45 -46
- package/dist/types/src/LockFunction.d.ts +1 -2
- package/dist/types/src/Log.d.ts +1 -2
- package/dist/types/src/Progress.d.ts +1 -2
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/UtilsGMMenu.d.ts +1 -2
- package/dist/types/src/WindowApi.d.ts +1 -2
- package/dist/types/src/indexedDB.d.ts +1 -2
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +75 -86
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/dist/types/src/types/env.d.ts +2 -0
- package/dist/types/src/types/global.d.ts +3 -0
- package/package.json +1 -1
- package/src/ColorConversion.ts +13 -37
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -24
- package/src/Dictionary.ts +37 -38
- package/src/GBKEncoder.ts +9 -18
- package/src/Hooks.ts +2 -7
- package/src/Httpx.ts +257 -412
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +8 -26
- package/src/Progress.ts +3 -13
- package/src/TryCatch.ts +4 -12
- package/src/Utils.ts +233 -595
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +29 -51
- package/src/Vue.ts +6 -18
- package/src/WindowApi.ts +2 -5
- package/src/indexedDB.ts +11 -20
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +75 -86
- package/src/types/ajaxHooker.d.ts +1 -5
- package/src/types/env.d.ts +2 -0
- package/src/types/global.d.ts +3 -0
package/dist/index.cjs.js
CHANGED
|
@@ -17,14 +17,13 @@ class ColorConversion {
|
|
|
17
17
|
/**
|
|
18
18
|
* 16进制颜色转rgba
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* 例如:`#ff0000` 转为 `rgba(123,123,123, 0.4)`
|
|
21
21
|
* @param hex
|
|
22
22
|
* @param opacity
|
|
23
23
|
*/
|
|
24
24
|
hexToRgba(hex, opacity) {
|
|
25
25
|
if (!this.isHex(hex)) {
|
|
26
|
-
|
|
27
|
-
throw new TypeError("输入错误的hex", hex);
|
|
26
|
+
throw new TypeError("输入错误的hex:" + hex);
|
|
28
27
|
}
|
|
29
28
|
return hex && hex.replace(/\s+/g, "").length === 7
|
|
30
29
|
? "rgba(" +
|
|
@@ -41,19 +40,16 @@ class ColorConversion {
|
|
|
41
40
|
/**
|
|
42
41
|
* hex转rgb
|
|
43
42
|
* @param str
|
|
44
|
-
* @returns
|
|
45
43
|
*/
|
|
46
44
|
hexToRgb(str) {
|
|
47
45
|
if (!this.isHex(str)) {
|
|
48
|
-
|
|
49
|
-
throw new TypeError("输入错误的hex", str);
|
|
46
|
+
throw new TypeError("输入错误的hex:" + str);
|
|
50
47
|
}
|
|
51
48
|
/* replace替换查找的到的字符串 */
|
|
52
49
|
str = str.replace("#", "");
|
|
53
50
|
/* match得到查询数组 */
|
|
54
51
|
let hxs = str.match(/../g);
|
|
55
52
|
for (let index = 0; index < 3; index++) {
|
|
56
|
-
// @ts-ignore
|
|
57
53
|
hxs[index] = parseInt(hxs[index], 16);
|
|
58
54
|
}
|
|
59
55
|
return hxs;
|
|
@@ -63,7 +59,6 @@ class ColorConversion {
|
|
|
63
59
|
* @param redValue
|
|
64
60
|
* @param greenValue
|
|
65
61
|
* @param blueValue
|
|
66
|
-
* @returns
|
|
67
62
|
*/
|
|
68
63
|
rgbToHex(redValue, greenValue, blueValue) {
|
|
69
64
|
/* 验证输入的rgb值是否合法 */
|
|
@@ -72,11 +67,7 @@ class ColorConversion {
|
|
|
72
67
|
!validPattern.test(greenValue.toString()) ||
|
|
73
68
|
!validPattern.test(blueValue.toString()))
|
|
74
69
|
throw new TypeError("输入错误的rgb颜色值");
|
|
75
|
-
let hexs = [
|
|
76
|
-
redValue.toString(16),
|
|
77
|
-
greenValue.toString(16),
|
|
78
|
-
blueValue.toString(16),
|
|
79
|
-
];
|
|
70
|
+
let hexs = [redValue.toString(16), greenValue.toString(16), blueValue.toString(16)];
|
|
80
71
|
for (let index = 0; index < 3; index++)
|
|
81
72
|
if (hexs[index].length == 1)
|
|
82
73
|
hexs[index] = "0" + hexs[index];
|
|
@@ -86,38 +77,30 @@ class ColorConversion {
|
|
|
86
77
|
* 获取颜色变暗或亮
|
|
87
78
|
* @param color 颜色
|
|
88
79
|
* @param level 0~1.0
|
|
89
|
-
* @returns
|
|
90
80
|
*/
|
|
91
81
|
getDarkColor(color, level) {
|
|
92
82
|
if (!this.isHex(color)) {
|
|
93
|
-
|
|
94
|
-
throw new TypeError("输入错误的hex", color);
|
|
83
|
+
throw new TypeError("输入错误的hex:" + color);
|
|
95
84
|
}
|
|
96
85
|
let rgbc = this.hexToRgb(color);
|
|
97
86
|
for (let index = 0; index < 3; index++) {
|
|
98
|
-
// @ts-ignore
|
|
99
87
|
rgbc[index] = Math.floor(rgbc[index] * (1 - level));
|
|
100
88
|
}
|
|
101
|
-
// @ts-ignore
|
|
102
89
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
103
90
|
}
|
|
104
91
|
/**
|
|
105
92
|
* 获取颜色变亮
|
|
106
93
|
* @param color 颜色
|
|
107
94
|
* @param level 0~1.0
|
|
108
|
-
* @returns
|
|
109
95
|
*/
|
|
110
96
|
getLightColor(color, level) {
|
|
111
97
|
if (!this.isHex(color)) {
|
|
112
|
-
|
|
113
|
-
throw new TypeError("输入错误的hex", color);
|
|
98
|
+
throw new TypeError("输入错误的hex:" + color);
|
|
114
99
|
}
|
|
115
100
|
let rgbc = this.hexToRgb(color);
|
|
116
101
|
for (let index = 0; index < 3; index++) {
|
|
117
|
-
// @ts-ignore
|
|
118
102
|
rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
|
|
119
103
|
}
|
|
120
|
-
// @ts-ignore
|
|
121
104
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
122
105
|
}
|
|
123
106
|
}
|
|
@@ -132,10 +115,7 @@ class GBKEncoder {
|
|
|
132
115
|
this.#data = dataText.match(/..../g);
|
|
133
116
|
for (let i = 0x81; i <= 0xfe; i++) {
|
|
134
117
|
for (let j = 0x40; j <= 0xfe; j++) {
|
|
135
|
-
this.#U2Ghash[this.#data[index++]] = ("%" +
|
|
136
|
-
i.toString(16) +
|
|
137
|
-
"%" +
|
|
138
|
-
j.toString(16)).toUpperCase();
|
|
118
|
+
this.#U2Ghash[this.#data[index++]] = ("%" + i.toString(16) + "%" + j.toString(16)).toUpperCase();
|
|
139
119
|
}
|
|
140
120
|
}
|
|
141
121
|
for (let key in this.#U2Ghash) {
|
|
@@ -205,20 +185,20 @@ class GBKEncoder {
|
|
|
205
185
|
* @param str
|
|
206
186
|
*/
|
|
207
187
|
decode(str) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
//
|
|
211
|
-
|
|
212
|
-
|
|
188
|
+
let GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
|
|
189
|
+
let UTFMatcher = /%[0-9A-F]{2}/;
|
|
190
|
+
// let gbk = true;
|
|
191
|
+
let utf = true;
|
|
192
|
+
const that = this;
|
|
213
193
|
while (utf) {
|
|
214
194
|
let gbkMatch = str.match(GBKMatcher);
|
|
215
195
|
let utfMatch = str.match(UTFMatcher);
|
|
196
|
+
// gbk = Boolean(gbkMatch);
|
|
216
197
|
utf = Boolean(utfMatch);
|
|
217
198
|
if (gbkMatch && gbkMatch in that.#G2Uhash) {
|
|
218
199
|
str = str.replace(gbkMatch, String.fromCharCode(("0x" + that.#G2Uhash[gbkMatch])));
|
|
219
200
|
}
|
|
220
201
|
else {
|
|
221
|
-
// @ts-ignore
|
|
222
202
|
str = str.replace(utfMatch, decodeURIComponent(utfMatch));
|
|
223
203
|
}
|
|
224
204
|
}
|
|
@@ -249,7 +229,6 @@ const TryCatch = function (...args) {
|
|
|
249
229
|
* @param handler
|
|
250
230
|
*/
|
|
251
231
|
error(handler) {
|
|
252
|
-
// @ts-ignore
|
|
253
232
|
handleError = handler;
|
|
254
233
|
return TryCatchCore;
|
|
255
234
|
},
|
|
@@ -264,7 +243,6 @@ const TryCatch = function (...args) {
|
|
|
264
243
|
callbackFunction = callback;
|
|
265
244
|
context = __context__ || this;
|
|
266
245
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
267
|
-
// @ts-ignore
|
|
268
246
|
return result !== void 0 ? result : TryCatchCore;
|
|
269
247
|
},
|
|
270
248
|
};
|
|
@@ -294,10 +272,7 @@ const TryCatch = function (...args) {
|
|
|
294
272
|
}
|
|
295
273
|
if (handleErrorFunc) {
|
|
296
274
|
if (typeof handleErrorFunc === "string") {
|
|
297
|
-
result = new Function(handleErrorFunc).apply(funcThis, [
|
|
298
|
-
...args,
|
|
299
|
-
error,
|
|
300
|
-
]);
|
|
275
|
+
result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
|
|
301
276
|
}
|
|
302
277
|
else {
|
|
303
278
|
result = handleErrorFunc.apply(funcThis, [...args, error]);
|
|
@@ -385,10 +360,7 @@ class CommonUtil {
|
|
|
385
360
|
itemResult = objItem === 0;
|
|
386
361
|
break;
|
|
387
362
|
case "string":
|
|
388
|
-
itemResult =
|
|
389
|
-
objItem.trim() === "" ||
|
|
390
|
-
objItem === "null" ||
|
|
391
|
-
objItem === "undefined";
|
|
363
|
+
itemResult = objItem.trim() === "" || objItem === "null" || objItem === "undefined";
|
|
392
364
|
break;
|
|
393
365
|
case "boolean":
|
|
394
366
|
itemResult = !objItem;
|
|
@@ -429,8 +401,7 @@ class CommonUtil {
|
|
|
429
401
|
return null;
|
|
430
402
|
let clone = obj instanceof Array ? [] : {};
|
|
431
403
|
for (const [key, value] of Object.entries(obj)) {
|
|
432
|
-
clone[key] =
|
|
433
|
-
typeof value === "object" ? UtilsContext.deepClone(value) : value;
|
|
404
|
+
clone[key] = typeof value === "object" ? UtilsContext.deepClone(value) : value;
|
|
434
405
|
}
|
|
435
406
|
return clone;
|
|
436
407
|
}
|
|
@@ -1949,35 +1920,30 @@ class GMMenu {
|
|
|
1949
1920
|
let defaultEnable = Boolean(this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable));
|
|
1950
1921
|
/** 油猴菜单上显示的文本 */
|
|
1951
1922
|
let showText = menuOption.showText(menuOption.text, defaultEnable);
|
|
1952
|
-
//
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
});
|
|
1923
|
+
// const GMMenuOptions = {
|
|
1924
|
+
// /**
|
|
1925
|
+
// * 菜单的id
|
|
1926
|
+
// */
|
|
1927
|
+
// id: menuOption.id,
|
|
1928
|
+
// /**
|
|
1929
|
+
// * 点击菜单项后是否应关闭弹出菜单
|
|
1930
|
+
// */
|
|
1931
|
+
// autoClose: menuOption.autoClose,
|
|
1932
|
+
// /**
|
|
1933
|
+
// * 菜单项的可选访问键
|
|
1934
|
+
// */
|
|
1935
|
+
// accessKey: menuOption.accessKey,
|
|
1936
|
+
// /**
|
|
1937
|
+
// * 菜单项的鼠标悬浮上的工具提示
|
|
1938
|
+
// */
|
|
1939
|
+
// title: menuOption.title,
|
|
1940
|
+
// };
|
|
1971
1941
|
/* 点击菜单后触发callback后的网页是否刷新 */
|
|
1972
1942
|
menuOption.autoReload =
|
|
1973
|
-
typeof menuOption.autoReload !== "boolean"
|
|
1974
|
-
? this.$default.autoReload
|
|
1975
|
-
: menuOption.autoReload;
|
|
1943
|
+
typeof menuOption.autoReload !== "boolean" ? this.$default.autoReload : menuOption.autoReload;
|
|
1976
1944
|
/* 点击菜单后触发callback后的网页是否存储值 */
|
|
1977
1945
|
menuOption.isStoreValue =
|
|
1978
|
-
typeof menuOption.isStoreValue !== "boolean"
|
|
1979
|
-
? this.$default.isStoreValue
|
|
1980
|
-
: menuOption.isStoreValue;
|
|
1946
|
+
typeof menuOption.isStoreValue !== "boolean" ? this.$default.isStoreValue : menuOption.isStoreValue;
|
|
1981
1947
|
/**
|
|
1982
1948
|
* 用户点击菜单后的回调函数
|
|
1983
1949
|
* @param event
|
|
@@ -2030,8 +1996,7 @@ class GMMenu {
|
|
|
2030
1996
|
* @param menuKey 菜单-键key
|
|
2031
1997
|
*/
|
|
2032
1998
|
getMenuHandledOption(menuKey) {
|
|
2033
|
-
return this.$data.data.find((item) => item.handleData.key === menuKey)
|
|
2034
|
-
?.handleData;
|
|
1999
|
+
return this.$data.data.find((item) => item.handleData.key === menuKey)?.handleData;
|
|
2035
2000
|
},
|
|
2036
2001
|
};
|
|
2037
2002
|
constructor(details) {
|
|
@@ -2039,8 +2004,7 @@ class GMMenu {
|
|
|
2039
2004
|
this.GM_Api.setValue = details.GM_setValue;
|
|
2040
2005
|
this.GM_Api.registerMenuCommand = details.GM_registerMenuCommand;
|
|
2041
2006
|
this.GM_Api.unregisterMenuCommand = details.GM_unregisterMenuCommand;
|
|
2042
|
-
this.MenuHandle.$default.autoReload =
|
|
2043
|
-
typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
2007
|
+
this.MenuHandle.$default.autoReload = typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
2044
2008
|
for (const keyName of Object.keys(this.GM_Api)) {
|
|
2045
2009
|
if (typeof this.GM_Api[keyName] !== "function") {
|
|
2046
2010
|
throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
|
|
@@ -2272,8 +2236,7 @@ class Hooks {
|
|
|
2272
2236
|
_context = context || window;
|
|
2273
2237
|
_funcName = getFuncName(this);
|
|
2274
2238
|
_context["realFunc_" + _funcName] = this;
|
|
2275
|
-
if (_context[_funcName].prototype &&
|
|
2276
|
-
_context[_funcName].prototype.isHooked) {
|
|
2239
|
+
if (_context[_funcName].prototype && _context[_funcName].prototype.isHooked) {
|
|
2277
2240
|
console.log("Already has been hooked,unhook first");
|
|
2278
2241
|
return false;
|
|
2279
2242
|
}
|
|
@@ -2451,8 +2414,7 @@ class Httpx {
|
|
|
2451
2414
|
if (details.allowInterceptConfig != null) {
|
|
2452
2415
|
// 配置存在
|
|
2453
2416
|
// 细分处理是否拦截
|
|
2454
|
-
if (typeof details.allowInterceptConfig.afterResponseSuccess ===
|
|
2455
|
-
"boolean" &&
|
|
2417
|
+
if (typeof details.allowInterceptConfig.afterResponseSuccess === "boolean" &&
|
|
2456
2418
|
!details.allowInterceptConfig.afterResponseSuccess) {
|
|
2457
2419
|
// 设置了禁止拦截
|
|
2458
2420
|
return details;
|
|
@@ -2487,8 +2449,7 @@ class Httpx {
|
|
|
2487
2449
|
if (data.details.allowInterceptConfig != null) {
|
|
2488
2450
|
// 配置存在
|
|
2489
2451
|
// 细分处理是否拦截
|
|
2490
|
-
if (typeof data.details.allowInterceptConfig.afterResponseError ===
|
|
2491
|
-
"boolean" &&
|
|
2452
|
+
if (typeof data.details.allowInterceptConfig.afterResponseError === "boolean" &&
|
|
2492
2453
|
!data.details.allowInterceptConfig.afterResponseError) {
|
|
2493
2454
|
// 设置了禁止拦截
|
|
2494
2455
|
return data;
|
|
@@ -2545,7 +2506,9 @@ class Httpx {
|
|
|
2545
2506
|
* 对请求的参数进行合并处理
|
|
2546
2507
|
*/
|
|
2547
2508
|
handleBeforeRequestOptionArgs(...args) {
|
|
2548
|
-
let option = {
|
|
2509
|
+
let option = {
|
|
2510
|
+
url: void 0,
|
|
2511
|
+
};
|
|
2549
2512
|
if (typeof args[0] === "string") {
|
|
2550
2513
|
/* 传入的是url,转为配置 */
|
|
2551
2514
|
let url = args[0];
|
|
@@ -2569,7 +2532,7 @@ class Httpx {
|
|
|
2569
2532
|
* @param method 当前请求方法,默认get
|
|
2570
2533
|
* @param userRequestOption 用户的请求配置
|
|
2571
2534
|
* @param resolve promise回调
|
|
2572
|
-
* @param reject 抛出错误回调
|
|
2535
|
+
* @param reject promise抛出错误回调
|
|
2573
2536
|
*/
|
|
2574
2537
|
getRequestOption(method, userRequestOption, resolve, reject) {
|
|
2575
2538
|
let that = this;
|
|
@@ -2588,64 +2551,51 @@ class Httpx {
|
|
|
2588
2551
|
let requestOption = {
|
|
2589
2552
|
url: url,
|
|
2590
2553
|
method: (method || "GET").toString().toUpperCase().trim(),
|
|
2591
|
-
timeout: userRequestOption.timeout ||
|
|
2592
|
-
|
|
2593
|
-
responseType: userRequestOption.responseType ||
|
|
2594
|
-
this.context.#defaultRequestOption.responseType,
|
|
2554
|
+
timeout: userRequestOption.timeout || this.context.#defaultRequestOption.timeout,
|
|
2555
|
+
responseType: userRequestOption.responseType || this.context.#defaultRequestOption.responseType,
|
|
2595
2556
|
/* 对象使用深拷贝 */
|
|
2596
2557
|
headers: commonUtil.deepClone(this.context.#defaultRequestOption.headers),
|
|
2597
2558
|
data: userRequestOption.data || this.context.#defaultRequestOption.data,
|
|
2598
|
-
redirect: userRequestOption.redirect ||
|
|
2599
|
-
this.context.#defaultRequestOption.redirect,
|
|
2559
|
+
redirect: userRequestOption.redirect || this.context.#defaultRequestOption.redirect,
|
|
2600
2560
|
cookie: userRequestOption.cookie || this.context.#defaultRequestOption.cookie,
|
|
2601
|
-
cookiePartition: userRequestOption.cookiePartition ||
|
|
2602
|
-
this.context.#defaultRequestOption.cookiePartition,
|
|
2561
|
+
cookiePartition: userRequestOption.cookiePartition || this.context.#defaultRequestOption.cookiePartition,
|
|
2603
2562
|
binary: userRequestOption.binary || this.context.#defaultRequestOption.binary,
|
|
2604
|
-
nocache: userRequestOption.nocache ||
|
|
2605
|
-
|
|
2606
|
-
revalidate: userRequestOption.revalidate ||
|
|
2607
|
-
this.context.#defaultRequestOption.revalidate,
|
|
2563
|
+
nocache: userRequestOption.nocache || this.context.#defaultRequestOption.nocache,
|
|
2564
|
+
revalidate: userRequestOption.revalidate || this.context.#defaultRequestOption.revalidate,
|
|
2608
2565
|
/* 对象使用深拷贝 */
|
|
2609
|
-
context: commonUtil.deepClone(userRequestOption.context ||
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
this.context.#defaultRequestOption.overrideMimeType,
|
|
2613
|
-
anonymous: userRequestOption.anonymous ||
|
|
2614
|
-
this.context.#defaultRequestOption.anonymous,
|
|
2566
|
+
context: commonUtil.deepClone(userRequestOption.context || this.context.#defaultRequestOption.context),
|
|
2567
|
+
overrideMimeType: userRequestOption.overrideMimeType || this.context.#defaultRequestOption.overrideMimeType,
|
|
2568
|
+
anonymous: userRequestOption.anonymous || this.context.#defaultRequestOption.anonymous,
|
|
2615
2569
|
fetch: userRequestOption.fetch || this.context.#defaultRequestOption.fetch,
|
|
2616
2570
|
/* 对象使用深拷贝 */
|
|
2617
2571
|
fetchInit: commonUtil.deepClone(this.context.#defaultRequestOption.fetchInit),
|
|
2618
2572
|
allowInterceptConfig: {
|
|
2619
|
-
beforeRequest: this.context.#defaultRequestOption
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
.allowInterceptConfig.afterResponseSuccess,
|
|
2623
|
-
afterResponseError: this.context.#defaultRequestOption
|
|
2624
|
-
.allowInterceptConfig.afterResponseError,
|
|
2573
|
+
beforeRequest: this.context.#defaultRequestOption.allowInterceptConfig.beforeRequest,
|
|
2574
|
+
afterResponseSuccess: this.context.#defaultRequestOption.allowInterceptConfig.afterResponseSuccess,
|
|
2575
|
+
afterResponseError: this.context.#defaultRequestOption.allowInterceptConfig.afterResponseError,
|
|
2625
2576
|
},
|
|
2626
2577
|
user: userRequestOption.user || this.context.#defaultRequestOption.user,
|
|
2627
|
-
password: userRequestOption.password ||
|
|
2628
|
-
this.context.#defaultRequestOption.password,
|
|
2578
|
+
password: userRequestOption.password || this.context.#defaultRequestOption.password,
|
|
2629
2579
|
onabort(...args) {
|
|
2630
|
-
that.context.
|
|
2580
|
+
that.context.HttpxResponseCallBack.onAbort(userRequestOption, resolve, reject, args);
|
|
2631
2581
|
},
|
|
2632
2582
|
onerror(...args) {
|
|
2633
|
-
that.context.
|
|
2583
|
+
that.context.HttpxResponseCallBack.onError(userRequestOption, resolve, reject, args);
|
|
2634
2584
|
},
|
|
2635
2585
|
onloadstart(...args) {
|
|
2636
|
-
that.context.
|
|
2586
|
+
that.context.HttpxResponseCallBack.onLoadStart(userRequestOption, args);
|
|
2637
2587
|
},
|
|
2638
2588
|
onprogress(...args) {
|
|
2639
|
-
that.context.
|
|
2589
|
+
that.context.HttpxResponseCallBack.onProgress(userRequestOption, args);
|
|
2640
2590
|
},
|
|
2641
2591
|
onreadystatechange(...args) {
|
|
2642
|
-
that.context.
|
|
2592
|
+
that.context.HttpxResponseCallBack.onReadyStateChange(userRequestOption, args);
|
|
2643
2593
|
},
|
|
2644
2594
|
ontimeout(...args) {
|
|
2645
|
-
that.context.
|
|
2595
|
+
that.context.HttpxResponseCallBack.onTimeout(userRequestOption, resolve, reject, args);
|
|
2646
2596
|
},
|
|
2647
2597
|
onload(...args) {
|
|
2648
|
-
that.context.
|
|
2598
|
+
that.context.HttpxResponseCallBack.onLoad(userRequestOption, resolve, reject, args);
|
|
2649
2599
|
},
|
|
2650
2600
|
};
|
|
2651
2601
|
// 补全allowInterceptConfig参数
|
|
@@ -2673,14 +2623,12 @@ class Httpx {
|
|
|
2673
2623
|
if (typeof requestOption.headers === "object") {
|
|
2674
2624
|
if (typeof userRequestOption.headers === "object") {
|
|
2675
2625
|
Object.keys(userRequestOption.headers).forEach((keyName, index) => {
|
|
2676
|
-
if (keyName in requestOption.headers &&
|
|
2677
|
-
userRequestOption.headers?.[keyName] == null) {
|
|
2626
|
+
if (keyName in requestOption.headers && userRequestOption.headers?.[keyName] == null) {
|
|
2678
2627
|
/* 在默认的header中存在,且设置它新的值为空,那么就是默认的值 */
|
|
2679
2628
|
Reflect.deleteProperty(requestOption.headers, keyName);
|
|
2680
2629
|
}
|
|
2681
2630
|
else {
|
|
2682
|
-
requestOption.headers[keyName] =
|
|
2683
|
-
userRequestOption?.headers?.[keyName];
|
|
2631
|
+
requestOption.headers[keyName] = userRequestOption?.headers?.[keyName];
|
|
2684
2632
|
}
|
|
2685
2633
|
});
|
|
2686
2634
|
}
|
|
@@ -2693,8 +2641,7 @@ class Httpx {
|
|
|
2693
2641
|
/* 使用assign替换且添加 */
|
|
2694
2642
|
if (typeof userRequestOption.fetchInit === "object") {
|
|
2695
2643
|
Object.keys(userRequestOption.fetchInit).forEach((keyName, index) => {
|
|
2696
|
-
if (keyName in requestOption.fetchInit &&
|
|
2697
|
-
userRequestOption.fetchInit[keyName] == null) {
|
|
2644
|
+
if (keyName in requestOption.fetchInit && userRequestOption.fetchInit[keyName] == null) {
|
|
2698
2645
|
/* 在默认的fetchInit中存在,且设置它新的值为空,那么就是默认的值 */
|
|
2699
2646
|
Reflect.deleteProperty(requestOption.fetchInit, keyName);
|
|
2700
2647
|
}
|
|
@@ -2708,8 +2655,7 @@ class Httpx {
|
|
|
2708
2655
|
Reflect.set(requestOption, "fetchInit", userRequestOption.fetchInit);
|
|
2709
2656
|
}
|
|
2710
2657
|
// 处理新的cookiePartition
|
|
2711
|
-
if (typeof requestOption.cookiePartition === "object" &&
|
|
2712
|
-
requestOption.cookiePartition != null) {
|
|
2658
|
+
if (typeof requestOption.cookiePartition === "object" && requestOption.cookiePartition != null) {
|
|
2713
2659
|
if (Reflect.has(requestOption.cookiePartition, "topLevelSite") &&
|
|
2714
2660
|
typeof requestOption.cookiePartition.topLevelSite !== "string") {
|
|
2715
2661
|
// topLevelSite必须是字符串
|
|
@@ -2731,8 +2677,7 @@ class Httpx {
|
|
|
2731
2677
|
}
|
|
2732
2678
|
else {
|
|
2733
2679
|
// 补充origin+/
|
|
2734
|
-
requestOption.url =
|
|
2735
|
-
globalThis.location.origin + "/" + requestOption.url;
|
|
2680
|
+
requestOption.url = globalThis.location.origin + "/" + requestOption.url;
|
|
2736
2681
|
}
|
|
2737
2682
|
}
|
|
2738
2683
|
if (requestOption.fetchInit && !requestOption.fetch) {
|
|
@@ -2757,7 +2702,6 @@ class Httpx {
|
|
|
2757
2702
|
else if (typeof requestOption.data === "object") {
|
|
2758
2703
|
isHandler = true;
|
|
2759
2704
|
// URLSearchParams参数可以转普通的string:string,包括FormData
|
|
2760
|
-
// @ts-ignore
|
|
2761
2705
|
let searchParams = new URLSearchParams(requestOption.data);
|
|
2762
2706
|
urlSearch = searchParams.toString();
|
|
2763
2707
|
}
|
|
@@ -2812,9 +2756,7 @@ class Httpx {
|
|
|
2812
2756
|
else if (ContentType.includes("application/x-www-form-urlencoded")) {
|
|
2813
2757
|
// application/x-www-form-urlencoded
|
|
2814
2758
|
if (typeof requestOption.data === "object") {
|
|
2815
|
-
requestOption.data = new URLSearchParams(
|
|
2816
|
-
// @ts-ignore
|
|
2817
|
-
requestOption.data).toString();
|
|
2759
|
+
requestOption.data = new URLSearchParams(requestOption.data).toString();
|
|
2818
2760
|
}
|
|
2819
2761
|
}
|
|
2820
2762
|
else if (ContentType.includes("multipart/form-data")) {
|
|
@@ -2834,7 +2776,7 @@ class Httpx {
|
|
|
2834
2776
|
},
|
|
2835
2777
|
/**
|
|
2836
2778
|
* 处理发送请求的配置,去除值为undefined、空function的值
|
|
2837
|
-
* @param option
|
|
2779
|
+
* @param option 请求配置
|
|
2838
2780
|
*/
|
|
2839
2781
|
removeRequestNullOption(option) {
|
|
2840
2782
|
Object.keys(option).forEach((keyName) => {
|
|
@@ -2846,21 +2788,20 @@ class Httpx {
|
|
|
2846
2788
|
}
|
|
2847
2789
|
});
|
|
2848
2790
|
if (commonUtil.isNull(option.url)) {
|
|
2849
|
-
throw new TypeError(`Utils.Httpx 参数
|
|
2791
|
+
throw new TypeError(`Utils.Httpx 参数url不能为空:${option.url}`);
|
|
2850
2792
|
}
|
|
2851
2793
|
return option;
|
|
2852
2794
|
},
|
|
2853
2795
|
/**
|
|
2854
2796
|
* 处理fetch的配置
|
|
2855
|
-
* @param option
|
|
2797
|
+
* @param option 请求配置
|
|
2856
2798
|
*/
|
|
2857
2799
|
handleFetchOption(option) {
|
|
2858
2800
|
/**
|
|
2859
2801
|
* fetch的请求配置
|
|
2860
2802
|
**/
|
|
2861
2803
|
let fetchRequestOption = {};
|
|
2862
|
-
if ((option.method === "GET" || option.method === "HEAD") &&
|
|
2863
|
-
option.data != null) {
|
|
2804
|
+
if ((option.method === "GET" || option.method === "HEAD") && option.data != null) {
|
|
2864
2805
|
/* GET 或 HEAD 方法的请求不能包含 body 信息 */
|
|
2865
2806
|
Reflect.deleteProperty(option, "data");
|
|
2866
2807
|
}
|
|
@@ -2905,21 +2846,21 @@ class Httpx {
|
|
|
2905
2846
|
};
|
|
2906
2847
|
},
|
|
2907
2848
|
};
|
|
2908
|
-
|
|
2849
|
+
HttpxResponseCallBack = {
|
|
2909
2850
|
context: this,
|
|
2910
2851
|
/**
|
|
2911
2852
|
* onabort请求被取消-触发
|
|
2912
2853
|
* @param details 配置
|
|
2913
|
-
* @param resolve 回调
|
|
2914
|
-
* @param reject
|
|
2854
|
+
* @param resolve promise回调
|
|
2855
|
+
* @param reject promise抛出错误回调
|
|
2915
2856
|
* @param argsResult 返回的参数列表
|
|
2916
2857
|
*/
|
|
2917
2858
|
async onAbort(details, resolve, reject, argsResult) {
|
|
2918
2859
|
// console.log(argsResult);
|
|
2919
|
-
if (
|
|
2860
|
+
if (typeof details?.onabort === "function") {
|
|
2920
2861
|
details.onabort.apply(this, argsResult);
|
|
2921
2862
|
}
|
|
2922
|
-
else if (
|
|
2863
|
+
else if (typeof this.context.#defaultRequestOption?.onabort === "function") {
|
|
2923
2864
|
this.context.#defaultRequestOption.onabort.apply(this, argsResult);
|
|
2924
2865
|
}
|
|
2925
2866
|
let response = argsResult;
|
|
@@ -2928,11 +2869,11 @@ class Httpx {
|
|
|
2928
2869
|
}
|
|
2929
2870
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2930
2871
|
type: "onabort",
|
|
2931
|
-
error: new
|
|
2872
|
+
error: new Error("request canceled"),
|
|
2932
2873
|
response: null,
|
|
2933
2874
|
details: details,
|
|
2934
2875
|
})) == null) {
|
|
2935
|
-
// reject(new
|
|
2876
|
+
// reject(new Error("response is intercept with onabort"));
|
|
2936
2877
|
return;
|
|
2937
2878
|
}
|
|
2938
2879
|
resolve({
|
|
@@ -2945,93 +2886,83 @@ class Httpx {
|
|
|
2945
2886
|
});
|
|
2946
2887
|
},
|
|
2947
2888
|
/**
|
|
2948
|
-
*
|
|
2889
|
+
* ontimeout请求超时-触发
|
|
2949
2890
|
* @param details 配置
|
|
2950
2891
|
* @param resolve 回调
|
|
2951
2892
|
* @param reject 抛出错误
|
|
2952
2893
|
* @param argsResult 返回的参数列表
|
|
2953
2894
|
*/
|
|
2954
|
-
async
|
|
2895
|
+
async onTimeout(details, resolve, reject, argsResult) {
|
|
2955
2896
|
// console.log(argsResult);
|
|
2956
|
-
if ("
|
|
2957
|
-
|
|
2897
|
+
if (typeof details?.ontimeout === "function") {
|
|
2898
|
+
// 执行配置中的ontime回调
|
|
2899
|
+
details.ontimeout.apply(this, argsResult);
|
|
2958
2900
|
}
|
|
2959
|
-
else if (
|
|
2960
|
-
|
|
2901
|
+
else if (typeof this.context.#defaultRequestOption?.ontimeout === "function") {
|
|
2902
|
+
// 执行默认配置的ontime回调
|
|
2903
|
+
this.context.#defaultRequestOption.ontimeout.apply(this, argsResult);
|
|
2961
2904
|
}
|
|
2905
|
+
// 获取响应结果
|
|
2962
2906
|
let response = argsResult;
|
|
2963
2907
|
if (response.length) {
|
|
2964
2908
|
response = response[0];
|
|
2965
2909
|
}
|
|
2910
|
+
// 执行错误回调的钩子
|
|
2966
2911
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2967
|
-
type: "
|
|
2968
|
-
error: new
|
|
2912
|
+
type: "ontimeout",
|
|
2913
|
+
error: new Error("request timeout"),
|
|
2969
2914
|
response: response,
|
|
2970
2915
|
details: details,
|
|
2971
2916
|
})) == null) {
|
|
2972
|
-
// reject(new
|
|
2917
|
+
// reject(new Error("response is intercept with ontimeout"));
|
|
2973
2918
|
return;
|
|
2974
2919
|
}
|
|
2975
2920
|
resolve({
|
|
2976
2921
|
data: response,
|
|
2977
2922
|
details: details,
|
|
2978
|
-
msg: "
|
|
2923
|
+
msg: "请求超时",
|
|
2979
2924
|
status: false,
|
|
2980
|
-
statusCode:
|
|
2981
|
-
type: "
|
|
2925
|
+
statusCode: 0,
|
|
2926
|
+
type: "ontimeout",
|
|
2982
2927
|
});
|
|
2983
2928
|
},
|
|
2984
2929
|
/**
|
|
2985
|
-
*
|
|
2930
|
+
* onerror请求异常-触发
|
|
2986
2931
|
* @param details 配置
|
|
2987
2932
|
* @param resolve 回调
|
|
2988
2933
|
* @param reject 抛出错误
|
|
2989
2934
|
* @param argsResult 返回的参数列表
|
|
2990
2935
|
*/
|
|
2991
|
-
async
|
|
2936
|
+
async onError(details, resolve, reject, argsResult) {
|
|
2992
2937
|
// console.log(argsResult);
|
|
2993
|
-
if ("
|
|
2994
|
-
details.
|
|
2938
|
+
if (typeof details?.onerror === "function") {
|
|
2939
|
+
details.onerror.apply(this, argsResult);
|
|
2995
2940
|
}
|
|
2996
|
-
else if (
|
|
2997
|
-
this.context.#defaultRequestOption.
|
|
2941
|
+
else if (typeof this.context.#defaultRequestOption?.onerror === "function") {
|
|
2942
|
+
this.context.#defaultRequestOption.onerror.apply(this, argsResult);
|
|
2998
2943
|
}
|
|
2999
2944
|
let response = argsResult;
|
|
3000
2945
|
if (response.length) {
|
|
3001
2946
|
response = response[0];
|
|
3002
2947
|
}
|
|
3003
2948
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
3004
|
-
type: "
|
|
3005
|
-
error: new
|
|
3006
|
-
response:
|
|
2949
|
+
type: "onerror",
|
|
2950
|
+
error: new Error("request error"),
|
|
2951
|
+
response: response,
|
|
3007
2952
|
details: details,
|
|
3008
2953
|
})) == null) {
|
|
3009
|
-
// reject(new
|
|
2954
|
+
// reject(new Error("response is intercept with onerror"));
|
|
3010
2955
|
return;
|
|
3011
2956
|
}
|
|
3012
2957
|
resolve({
|
|
3013
2958
|
data: response,
|
|
3014
2959
|
details: details,
|
|
3015
|
-
msg: "
|
|
2960
|
+
msg: "请求异常",
|
|
3016
2961
|
status: false,
|
|
3017
|
-
statusCode:
|
|
3018
|
-
type: "
|
|
2962
|
+
statusCode: response["status"],
|
|
2963
|
+
type: "onerror",
|
|
3019
2964
|
});
|
|
3020
2965
|
},
|
|
3021
|
-
/**
|
|
3022
|
-
* onloadstart请求开始-触发
|
|
3023
|
-
* @param details 配置
|
|
3024
|
-
* @param argsResult 返回的参数列表
|
|
3025
|
-
*/
|
|
3026
|
-
onLoadStart(details, argsResult) {
|
|
3027
|
-
// console.log(argsResult);
|
|
3028
|
-
if ("onloadstart" in details) {
|
|
3029
|
-
details.onloadstart.apply(this, argsResult);
|
|
3030
|
-
}
|
|
3031
|
-
else if ("onloadstart" in this.context.#defaultRequestOption) {
|
|
3032
|
-
this.context.#defaultRequestOption.onloadstart.apply(this, argsResult);
|
|
3033
|
-
}
|
|
3034
|
-
},
|
|
3035
2966
|
/**
|
|
3036
2967
|
* onload加载完毕-触发
|
|
3037
2968
|
* @param details 请求的配置
|
|
@@ -3111,7 +3042,7 @@ class Httpx {
|
|
|
3111
3042
|
/* 状态码2xx都是成功的 */
|
|
3112
3043
|
if (Math.floor(originResponse.status / 100) === 2) {
|
|
3113
3044
|
if ((await this.context.HttpxResponseHook.successResponseCallBack(originResponse, details)) == null) {
|
|
3114
|
-
// reject(new
|
|
3045
|
+
// reject(new Error("response is intercept with onloada"));
|
|
3115
3046
|
return;
|
|
3116
3047
|
}
|
|
3117
3048
|
resolve({
|
|
@@ -3124,21 +3055,21 @@ class Httpx {
|
|
|
3124
3055
|
});
|
|
3125
3056
|
}
|
|
3126
3057
|
else {
|
|
3127
|
-
this.context.
|
|
3058
|
+
this.context.HttpxResponseCallBack.onError(details, resolve, reject, argsResult);
|
|
3128
3059
|
}
|
|
3129
3060
|
},
|
|
3130
3061
|
/**
|
|
3131
|
-
*
|
|
3062
|
+
* onloadstart请求开始-触发
|
|
3132
3063
|
* @param details 配置
|
|
3133
3064
|
* @param argsResult 返回的参数列表
|
|
3134
3065
|
*/
|
|
3135
|
-
|
|
3066
|
+
onLoadStart(details, argsResult) {
|
|
3136
3067
|
// console.log(argsResult);
|
|
3137
|
-
if ("
|
|
3138
|
-
details.
|
|
3068
|
+
if (typeof details?.onloadstart === "function") {
|
|
3069
|
+
details.onloadstart.apply(this, argsResult);
|
|
3139
3070
|
}
|
|
3140
|
-
else if (
|
|
3141
|
-
this.context.#defaultRequestOption.
|
|
3071
|
+
else if (typeof this.context.#defaultRequestOption?.onloadstart === "function") {
|
|
3072
|
+
this.context.#defaultRequestOption.onloadstart.apply(this, argsResult);
|
|
3142
3073
|
}
|
|
3143
3074
|
},
|
|
3144
3075
|
/**
|
|
@@ -3148,13 +3079,27 @@ class Httpx {
|
|
|
3148
3079
|
*/
|
|
3149
3080
|
onReadyStateChange(details, argsResult) {
|
|
3150
3081
|
// console.log(argsResult);
|
|
3151
|
-
if (
|
|
3082
|
+
if (typeof details?.onreadystatechange === "function") {
|
|
3152
3083
|
details.onreadystatechange.apply(this, argsResult);
|
|
3153
3084
|
}
|
|
3154
|
-
else if (
|
|
3085
|
+
else if (typeof this.context.#defaultRequestOption?.onreadystatechange === "function") {
|
|
3155
3086
|
this.context.#defaultRequestOption.onreadystatechange.apply(this, argsResult);
|
|
3156
3087
|
}
|
|
3157
3088
|
},
|
|
3089
|
+
/**
|
|
3090
|
+
* onprogress上传进度-触发
|
|
3091
|
+
* @param details 配置
|
|
3092
|
+
* @param argsResult 返回的参数列表
|
|
3093
|
+
*/
|
|
3094
|
+
onProgress(details, argsResult) {
|
|
3095
|
+
// console.log(argsResult);
|
|
3096
|
+
if (typeof details?.onprogress === "function") {
|
|
3097
|
+
details.onprogress.apply(this, argsResult);
|
|
3098
|
+
}
|
|
3099
|
+
else if (typeof this.context.#defaultRequestOption?.onprogress === "function") {
|
|
3100
|
+
this.context.#defaultRequestOption.onprogress.apply(this, argsResult);
|
|
3101
|
+
}
|
|
3102
|
+
},
|
|
3158
3103
|
};
|
|
3159
3104
|
HttpxRequest = {
|
|
3160
3105
|
context: this,
|
|
@@ -3166,8 +3111,7 @@ class Httpx {
|
|
|
3166
3111
|
if (this.context.#defaultInitOption.logDetails) {
|
|
3167
3112
|
console.log("[Httpx-HttpxRequest.request] 请求前的配置👇", details);
|
|
3168
3113
|
}
|
|
3169
|
-
if (typeof this.context.HttpxRequestHook.beforeRequestCallBack ===
|
|
3170
|
-
"function") {
|
|
3114
|
+
if (typeof this.context.HttpxRequestHook.beforeRequestCallBack === "function") {
|
|
3171
3115
|
let hookResult = await this.context.HttpxRequestHook.beforeRequestCallBack(details);
|
|
3172
3116
|
if (hookResult == null) {
|
|
3173
3117
|
return;
|
|
@@ -3204,15 +3148,12 @@ class Httpx {
|
|
|
3204
3148
|
isFetch: true,
|
|
3205
3149
|
finalUrl: fetchResponse.url,
|
|
3206
3150
|
readyState: 4,
|
|
3207
|
-
// @ts-ignore
|
|
3208
3151
|
status: fetchResponse.status,
|
|
3209
3152
|
statusText: fetchResponse.statusText,
|
|
3210
|
-
|
|
3211
|
-
response: void 0,
|
|
3153
|
+
response: "",
|
|
3212
3154
|
responseFetchHeaders: fetchResponse.headers,
|
|
3213
3155
|
responseHeaders: "",
|
|
3214
|
-
|
|
3215
|
-
responseText: void 0,
|
|
3156
|
+
responseText: "",
|
|
3216
3157
|
responseType: option.responseType,
|
|
3217
3158
|
responseXML: void 0,
|
|
3218
3159
|
};
|
|
@@ -3226,9 +3167,7 @@ class Httpx {
|
|
|
3226
3167
|
/* 如果需要stream,且获取到的是stream,那直接返回 */
|
|
3227
3168
|
if (option.responseType === "stream" ||
|
|
3228
3169
|
(fetchResponse.headers.has("Content-Type") &&
|
|
3229
|
-
fetchResponse.headers
|
|
3230
|
-
.get("Content-Type")
|
|
3231
|
-
.includes("text/event-stream"))) {
|
|
3170
|
+
fetchResponse.headers.get("Content-Type").includes("text/event-stream"))) {
|
|
3232
3171
|
Reflect.set(httpxResponse, "isStream", true);
|
|
3233
3172
|
Reflect.set(httpxResponse, "response", fetchResponse.body);
|
|
3234
3173
|
Reflect.deleteProperty(httpxResponse, "responseText");
|
|
@@ -3247,9 +3186,7 @@ class Httpx {
|
|
|
3247
3186
|
/** 数据编码 */
|
|
3248
3187
|
let encoding = "utf-8";
|
|
3249
3188
|
if (fetchResponse.headers.has("Content-Type")) {
|
|
3250
|
-
let charsetMatched = fetchResponse.headers
|
|
3251
|
-
.get("Content-Type")
|
|
3252
|
-
?.match(/charset=(.+)/);
|
|
3189
|
+
let charsetMatched = fetchResponse.headers.get("Content-Type")?.match(/charset=(.+)/);
|
|
3253
3190
|
if (charsetMatched) {
|
|
3254
3191
|
encoding = charsetMatched[1];
|
|
3255
3192
|
encoding = encoding.toLowerCase();
|
|
@@ -3271,13 +3208,11 @@ class Httpx {
|
|
|
3271
3208
|
response = new Blob([arrayBuffer]);
|
|
3272
3209
|
}
|
|
3273
3210
|
else if (option.responseType === "json" ||
|
|
3274
|
-
(typeof fetchResponseType === "string" &&
|
|
3275
|
-
fetchResponseType.includes("application/json"))) {
|
|
3211
|
+
(typeof fetchResponseType === "string" && fetchResponseType.includes("application/json"))) {
|
|
3276
3212
|
// response返回格式是JSON格式
|
|
3277
3213
|
response = commonUtil.toJSON(responseText);
|
|
3278
3214
|
}
|
|
3279
|
-
else if (option.responseType === "document" ||
|
|
3280
|
-
option.responseType == null) {
|
|
3215
|
+
else if (option.responseType === "document" || option.responseType == null) {
|
|
3281
3216
|
// response返回格式是文档格式
|
|
3282
3217
|
let parser = new DOMParser();
|
|
3283
3218
|
response = parser.parseFromString(responseText, "text/html");
|
|
@@ -3285,9 +3220,9 @@ class Httpx {
|
|
|
3285
3220
|
// 转为XML结构
|
|
3286
3221
|
let parser = new DOMParser();
|
|
3287
3222
|
responseXML = parser.parseFromString(responseText, "text/xml");
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3223
|
+
httpxResponse.response = response;
|
|
3224
|
+
httpxResponse.responseText = responseText;
|
|
3225
|
+
httpxResponse.responseXML = responseXML;
|
|
3291
3226
|
// 执行回调
|
|
3292
3227
|
option.onload(httpxResponse);
|
|
3293
3228
|
})
|
|
@@ -3468,7 +3403,7 @@ class Httpx {
|
|
|
3468
3403
|
}
|
|
3469
3404
|
/**
|
|
3470
3405
|
* GET 请求
|
|
3471
|
-
* @param url
|
|
3406
|
+
* @param url 请求的url
|
|
3472
3407
|
* @param details 配置
|
|
3473
3408
|
*/
|
|
3474
3409
|
get(...args) {
|
|
@@ -3534,27 +3469,21 @@ class Httpx {
|
|
|
3534
3469
|
/** 取消请求 */
|
|
3535
3470
|
let abortFn = null;
|
|
3536
3471
|
let promise = new globalThis.Promise(async (resolve, reject) => {
|
|
3537
|
-
let requestOption = this.HttpxRequestOption.getRequestOption(useRequestOption.method, useRequestOption, resolve, reject);
|
|
3472
|
+
let requestOption = (this.HttpxRequestOption.getRequestOption(useRequestOption.method, useRequestOption, resolve, reject));
|
|
3538
3473
|
if (typeof beforeRequestOption === "function") {
|
|
3539
|
-
// @ts-ignore
|
|
3540
3474
|
beforeRequestOption(requestOption);
|
|
3541
3475
|
}
|
|
3542
|
-
|
|
3543
|
-
requestOption =
|
|
3544
|
-
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
3476
|
+
requestOption = this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
3545
3477
|
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
3546
|
-
if (requestResult != null &&
|
|
3547
|
-
typeof requestResult.abort === "function") {
|
|
3478
|
+
if (requestResult != null && typeof requestResult.abort === "function") {
|
|
3548
3479
|
abortFn = requestResult.abort;
|
|
3549
3480
|
}
|
|
3550
3481
|
});
|
|
3551
|
-
// @ts-ignore
|
|
3552
3482
|
promise.abort = () => {
|
|
3553
3483
|
if (typeof abortFn === "function") {
|
|
3554
3484
|
abortFn();
|
|
3555
3485
|
}
|
|
3556
3486
|
};
|
|
3557
|
-
// @ts-ignore
|
|
3558
3487
|
return promise;
|
|
3559
3488
|
}
|
|
3560
3489
|
}
|
|
@@ -3564,8 +3493,7 @@ class indexedDB {
|
|
|
3564
3493
|
#storeName;
|
|
3565
3494
|
#dbVersion;
|
|
3566
3495
|
/* websql的版本号,由于ios的问题,版本号的写法不一样 */
|
|
3567
|
-
//
|
|
3568
|
-
#slqVersion = "1";
|
|
3496
|
+
// #slqVersion = "1";
|
|
3569
3497
|
/* 监听IndexDB */
|
|
3570
3498
|
#indexedDB = window.indexedDB ||
|
|
3571
3499
|
window.mozIndexedDB ||
|
|
@@ -3573,8 +3501,7 @@ class indexedDB {
|
|
|
3573
3501
|
window.msIndexedDB;
|
|
3574
3502
|
/* 缓存数据库,避免同一个页面重复创建和销毁 */
|
|
3575
3503
|
#db = {};
|
|
3576
|
-
//
|
|
3577
|
-
#store = null;
|
|
3504
|
+
// #store: IDBObjectStore = null as any;
|
|
3578
3505
|
/** 状态码 */
|
|
3579
3506
|
#statusCode = {
|
|
3580
3507
|
operationSuccess: {
|
|
@@ -3619,7 +3546,7 @@ class indexedDB {
|
|
|
3619
3546
|
txn = this.#db[dbName].transaction(this.#storeName, "readwrite");
|
|
3620
3547
|
/* IndexDB的读写权限 */
|
|
3621
3548
|
store = txn.objectStore(this.#storeName);
|
|
3622
|
-
this.#store = store;
|
|
3549
|
+
// this.#store = store;
|
|
3623
3550
|
return store;
|
|
3624
3551
|
}
|
|
3625
3552
|
/**
|
|
@@ -4039,8 +3966,7 @@ class Log {
|
|
|
4039
3966
|
if (typeof __GM_info === "string") {
|
|
4040
3967
|
this.tag = __GM_info;
|
|
4041
3968
|
}
|
|
4042
|
-
else if (typeof __GM_info === "object" &&
|
|
4043
|
-
typeof __GM_info?.script?.name === "string") {
|
|
3969
|
+
else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
|
|
4044
3970
|
this.tag = __GM_info.script.name;
|
|
4045
3971
|
}
|
|
4046
3972
|
this.#console = console;
|
|
@@ -4096,8 +4022,7 @@ class Log {
|
|
|
4096
4022
|
*/
|
|
4097
4023
|
checkClearConsole() {
|
|
4098
4024
|
this.#logCount++;
|
|
4099
|
-
if (this.#details.autoClearConsole &&
|
|
4100
|
-
this.#logCount > this.#details.logMaxCount) {
|
|
4025
|
+
if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
|
|
4101
4026
|
this.#console.clear();
|
|
4102
4027
|
this.#logCount = 0;
|
|
4103
4028
|
}
|
|
@@ -4344,12 +4269,40 @@ class Progress {
|
|
|
4344
4269
|
}
|
|
4345
4270
|
|
|
4346
4271
|
class UtilsDictionary {
|
|
4347
|
-
items
|
|
4272
|
+
items;
|
|
4348
4273
|
constructor(key, value) {
|
|
4274
|
+
this.items = {};
|
|
4349
4275
|
if (key != null) {
|
|
4350
4276
|
this.set(key, value);
|
|
4351
4277
|
}
|
|
4352
4278
|
}
|
|
4279
|
+
/**
|
|
4280
|
+
* 获取字典的长度,同this.size
|
|
4281
|
+
*/
|
|
4282
|
+
get length() {
|
|
4283
|
+
return this.size();
|
|
4284
|
+
}
|
|
4285
|
+
/**
|
|
4286
|
+
* 迭代器
|
|
4287
|
+
*/
|
|
4288
|
+
get entries() {
|
|
4289
|
+
let that = this;
|
|
4290
|
+
return function* () {
|
|
4291
|
+
let itemKeys = Object.keys(that.getItems());
|
|
4292
|
+
for (const keyName of itemKeys) {
|
|
4293
|
+
yield [keyName, that.get(keyName)];
|
|
4294
|
+
}
|
|
4295
|
+
};
|
|
4296
|
+
}
|
|
4297
|
+
/**
|
|
4298
|
+
* 是否可遍历
|
|
4299
|
+
*/
|
|
4300
|
+
get [Symbol.iterator]() {
|
|
4301
|
+
let that = this;
|
|
4302
|
+
return function () {
|
|
4303
|
+
return that.entries();
|
|
4304
|
+
};
|
|
4305
|
+
}
|
|
4353
4306
|
/**
|
|
4354
4307
|
* 检查是否有某一个键
|
|
4355
4308
|
* @param key 键
|
|
@@ -4450,7 +4403,6 @@ class UtilsDictionary {
|
|
|
4450
4403
|
* 返回字典本身
|
|
4451
4404
|
*/
|
|
4452
4405
|
getItems() {
|
|
4453
|
-
// @ts-ignore
|
|
4454
4406
|
return this.items;
|
|
4455
4407
|
}
|
|
4456
4408
|
/**
|
|
@@ -4460,38 +4412,15 @@ class UtilsDictionary {
|
|
|
4460
4412
|
concat(data) {
|
|
4461
4413
|
this.items = commonUtil.assign(this.items, data.getItems());
|
|
4462
4414
|
}
|
|
4415
|
+
/**
|
|
4416
|
+
* 迭代字典
|
|
4417
|
+
* @param callbackfn 回调函数
|
|
4418
|
+
*/
|
|
4463
4419
|
forEach(callbackfn) {
|
|
4464
4420
|
for (const key in this.getItems()) {
|
|
4465
4421
|
callbackfn(this.get(key), key, this.getItems());
|
|
4466
4422
|
}
|
|
4467
4423
|
}
|
|
4468
|
-
/**
|
|
4469
|
-
* 获取字典的长度,同this.size
|
|
4470
|
-
*/
|
|
4471
|
-
get length() {
|
|
4472
|
-
return this.size();
|
|
4473
|
-
}
|
|
4474
|
-
/**
|
|
4475
|
-
* 迭代器
|
|
4476
|
-
*/
|
|
4477
|
-
get entries() {
|
|
4478
|
-
let that = this;
|
|
4479
|
-
return function* () {
|
|
4480
|
-
let itemKeys = Object.keys(that.getItems());
|
|
4481
|
-
for (const keyName of itemKeys) {
|
|
4482
|
-
yield [keyName, that.get(keyName)];
|
|
4483
|
-
}
|
|
4484
|
-
};
|
|
4485
|
-
}
|
|
4486
|
-
/**
|
|
4487
|
-
* 是否可遍历
|
|
4488
|
-
*/
|
|
4489
|
-
get [Symbol.iterator]() {
|
|
4490
|
-
let that = this;
|
|
4491
|
-
return function () {
|
|
4492
|
-
return that.entries();
|
|
4493
|
-
};
|
|
4494
|
-
}
|
|
4495
4424
|
}
|
|
4496
4425
|
|
|
4497
4426
|
class WindowApi {
|
|
@@ -4517,7 +4446,6 @@ class WindowApi {
|
|
|
4517
4446
|
if (!option) {
|
|
4518
4447
|
option = Object.assign({}, this.defaultApi);
|
|
4519
4448
|
}
|
|
4520
|
-
// @ts-ignore
|
|
4521
4449
|
this.api = Object.assign({}, option);
|
|
4522
4450
|
}
|
|
4523
4451
|
get document() {
|
|
@@ -4575,11 +4503,10 @@ class ReactiveEffect {
|
|
|
4575
4503
|
deps = [];
|
|
4576
4504
|
active = true;
|
|
4577
4505
|
fn;
|
|
4578
|
-
//
|
|
4579
|
-
scheduler;
|
|
4506
|
+
// private scheduler;
|
|
4580
4507
|
constructor(fn, scheduler) {
|
|
4581
4508
|
this.fn = fn;
|
|
4582
|
-
this.scheduler = scheduler;
|
|
4509
|
+
// this.scheduler = scheduler;
|
|
4583
4510
|
}
|
|
4584
4511
|
run(cb) {
|
|
4585
4512
|
if (!this.active) {
|
|
@@ -4646,8 +4573,7 @@ class Vue {
|
|
|
4646
4573
|
reactive(target) {
|
|
4647
4574
|
const that = this;
|
|
4648
4575
|
if (!(typeof target === "object" && target !== null)) {
|
|
4649
|
-
|
|
4650
|
-
return;
|
|
4576
|
+
return void 0;
|
|
4651
4577
|
}
|
|
4652
4578
|
if (VueUtils.isReactive(target)) {
|
|
4653
4579
|
return target;
|
|
@@ -4717,7 +4643,6 @@ class Vue {
|
|
|
4717
4643
|
toRefs(object) {
|
|
4718
4644
|
const result = VueUtils.isArray(object) ? new Array(object.length) : {};
|
|
4719
4645
|
for (let key in object) {
|
|
4720
|
-
// @ts-ignore
|
|
4721
4646
|
result[key] = this.toRef(object, key);
|
|
4722
4647
|
}
|
|
4723
4648
|
return result;
|
|
@@ -5013,7 +4938,7 @@ const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
|
5013
4938
|
};
|
|
5014
4939
|
|
|
5015
4940
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
5016
|
-
const worker = `(()=>{var e={455:function(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),
|
|
4941
|
+
const worker = `(()=>{var e={455:function(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),l=t(c);e.addUniqueNumber=l,e.generateUniqueNumber=c}(t)}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(()=>{"use strict";const e=-32603,t=-32602,n=-32601,o=(e,t)=>Object.assign(new Error(e),{status:t}),s=t=>o('The handler of the method called "'.concat(t,'" returned an unexpected result.'),e),a=(t,r)=>async({data:{id:a,method:i,params:u}})=>{const c=r[i];try{if(void 0===c)throw(e=>o('The requested method called "'.concat(e,'" is not supported.'),n))(i);const r=void 0===u?c():c(u);if(void 0===r)throw(t=>o('The handler of the method called "'.concat(t,'" returned no required result.'),e))(i);const l=r instanceof Promise?await r:r;if(null===a){if(void 0!==l.result)throw s(i)}else{if(void 0===l.result)throw s(i);const{result:e,transferables:r=[]}=l;t.postMessage({id:a,result:e},r)}}catch(e){const{message:r,status:n=-32603}=e;t.postMessage({error:{code:n,message:r},id:a})}};var i=r(455);const u=new Map,c=(e,r,n)=>({...r,connect:({port:t})=>{t.start();const n=e(t,r),o=(0,i.generateUniqueNumber)(u);return u.set(o,(()=>{n(),t.close(),u.delete(o)})),{result:o}},disconnect:({portId:e})=>{const r=u.get(e);if(void 0===r)throw(e=>o('The specified parameter called "portId" with the given value "'.concat(e,'" does not identify a port connected to this worker.'),t))(e);return r(),{result:null}},isSupported:async()=>{if(await new Promise((e=>{const t=new ArrayBuffer(0),{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:t})=>e(null!==t),n.postMessage(t,[t])}))){const e=n();return{result:e instanceof Promise?await e:e}}return{result:!1}}}),l=(e,t,r=()=>!0)=>{const n=c(l,t,r),o=a(e,n);return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},d=(e,t)=>r=>{const n=t.get(r);if(void 0===n)return Promise.resolve(!1);const[o,s]=n;return e(o),t.delete(r),s(!1),Promise.resolve(!0)},f=(e,t,r,n)=>(o,s,a)=>{const i=o+s-t.timeOrigin,u=i-t.now();return new Promise((t=>{e.set(a,[r(n,u,i,e,t,a),t])}))},m=new Map,h=d(globalThis.clearTimeout,m),p=new Map,v=d(globalThis.clearTimeout,p),w=((e,t)=>{const r=(n,o,s,a)=>{const i=n-e.now();i>0?o.set(a,[t(r,i,n,o,s,a),s]):(o.delete(a),s(!0))};return r})(performance,globalThis.setTimeout),g=f(m,performance,globalThis.setTimeout,w),T=f(p,performance,globalThis.setTimeout,w);l(self,{clear:async({timerId:e,timerType:t})=>({result:await("interval"===t?h(e):v(e))}),set:async({delay:e,now:t,timerId:r,timerType:n})=>({result:await("interval"===n?g:T)(e,t,r)})})})()})();`; // tslint:disable-line:max-line-length
|
|
5017
4942
|
|
|
5018
4943
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
5019
4944
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -5445,7 +5370,6 @@ class DOMUtils {
|
|
|
5445
5370
|
let text = textMatch[2];
|
|
5446
5371
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5447
5372
|
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5448
|
-
// @ts-ignore
|
|
5449
5373
|
return ($ele?.textContent || $ele?.innerText)?.includes(text);
|
|
5450
5374
|
});
|
|
5451
5375
|
}
|
|
@@ -5463,7 +5387,6 @@ class DOMUtils {
|
|
|
5463
5387
|
let regexp = new RegExp(pattern, flags);
|
|
5464
5388
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5465
5389
|
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5466
|
-
// @ts-ignore
|
|
5467
5390
|
return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
|
|
5468
5391
|
});
|
|
5469
5392
|
}
|
|
@@ -5509,7 +5432,6 @@ class DOMUtils {
|
|
|
5509
5432
|
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
5510
5433
|
let text = textMatch[2];
|
|
5511
5434
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5512
|
-
// @ts-ignore
|
|
5513
5435
|
let content = $el?.textContent || $el?.innerText;
|
|
5514
5436
|
if (typeof content !== "string") {
|
|
5515
5437
|
content = "";
|
|
@@ -5529,7 +5451,6 @@ class DOMUtils {
|
|
|
5529
5451
|
}
|
|
5530
5452
|
let regexp = new RegExp(pattern, flags);
|
|
5531
5453
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5532
|
-
// @ts-ignore
|
|
5533
5454
|
let content = $el?.textContent || $el?.innerText;
|
|
5534
5455
|
if (typeof content !== "string") {
|
|
5535
5456
|
content = "";
|
|
@@ -5560,7 +5481,6 @@ class DOMUtils {
|
|
|
5560
5481
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5561
5482
|
let $closest = $el?.closest(selector);
|
|
5562
5483
|
if ($closest) {
|
|
5563
|
-
// @ts-ignore
|
|
5564
5484
|
let content = $el?.textContent || $el?.innerText;
|
|
5565
5485
|
if (typeof content === "string" && content.includes(text)) {
|
|
5566
5486
|
return $closest;
|
|
@@ -5583,7 +5503,6 @@ class DOMUtils {
|
|
|
5583
5503
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5584
5504
|
let $closest = $el?.closest(selector);
|
|
5585
5505
|
if ($closest) {
|
|
5586
|
-
// @ts-ignore
|
|
5587
5506
|
let content = $el?.textContent || $el?.innerText;
|
|
5588
5507
|
if (typeof content === "string" && content.match(regexp)) {
|
|
5589
5508
|
return $closest;
|
|
@@ -5606,7 +5525,7 @@ class Utils {
|
|
|
5606
5525
|
this.windowApi = new WindowApi(option);
|
|
5607
5526
|
}
|
|
5608
5527
|
/** 版本号 */
|
|
5609
|
-
version = "2025.
|
|
5528
|
+
version = "2025.8.11";
|
|
5610
5529
|
addStyle(cssText) {
|
|
5611
5530
|
if (typeof cssText !== "string") {
|
|
5612
5531
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5703,7 +5622,7 @@ class Utils {
|
|
|
5703
5622
|
return ajaxHooker();
|
|
5704
5623
|
}
|
|
5705
5624
|
};
|
|
5706
|
-
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view =
|
|
5625
|
+
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = this.windowApi.window) {
|
|
5707
5626
|
if (!(canvasElement instanceof HTMLCanvasElement)) {
|
|
5708
5627
|
throw new Error("Utils.canvasClickByPosition 参数canvasElement必须是canvas元素");
|
|
5709
5628
|
}
|
|
@@ -5714,7 +5633,6 @@ class Utils {
|
|
|
5714
5633
|
cancelable: true,
|
|
5715
5634
|
clientX: clientX,
|
|
5716
5635
|
clientY: clientY,
|
|
5717
|
-
// @ts-ignore
|
|
5718
5636
|
view: view,
|
|
5719
5637
|
detail: 1,
|
|
5720
5638
|
};
|
|
@@ -5730,13 +5648,9 @@ class Utils {
|
|
|
5730
5648
|
let touchEvent = UtilsContext.windowApi.window.event;
|
|
5731
5649
|
let $click = clickEvent?.composedPath()?.[0];
|
|
5732
5650
|
// 点击的x坐标
|
|
5733
|
-
let clickPosX = clickEvent?.clientX != null
|
|
5734
|
-
? clickEvent.clientX
|
|
5735
|
-
: touchEvent.touches[0].clientX;
|
|
5651
|
+
let clickPosX = clickEvent?.clientX != null ? clickEvent.clientX : touchEvent.touches[0].clientX;
|
|
5736
5652
|
// 点击的y坐标
|
|
5737
|
-
let clickPosY = clickEvent?.clientY != null
|
|
5738
|
-
? clickEvent.clientY
|
|
5739
|
-
: touchEvent.touches[0].clientY;
|
|
5653
|
+
let clickPosY = clickEvent?.clientY != null ? clickEvent.clientY : touchEvent.touches[0].clientY;
|
|
5740
5654
|
let {
|
|
5741
5655
|
/* 要检测的元素的相对屏幕的横坐标最左边 */
|
|
5742
5656
|
left: elementPosXLeft,
|
|
@@ -5899,9 +5813,7 @@ class Utils {
|
|
|
5899
5813
|
/* CODE FOR BROWSERS THAT SUPPORT window.find */
|
|
5900
5814
|
let windowFind = this.windowApi.self.find;
|
|
5901
5815
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
5902
|
-
if (strFound &&
|
|
5903
|
-
this.windowApi.self.getSelection &&
|
|
5904
|
-
!this.windowApi.self.getSelection().anchorNode) {
|
|
5816
|
+
if (strFound && this.windowApi.self.getSelection && !this.windowApi.self.getSelection().anchorNode) {
|
|
5905
5817
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
5906
5818
|
}
|
|
5907
5819
|
if (!strFound) {
|
|
@@ -6004,9 +5916,7 @@ class Utils {
|
|
|
6004
5916
|
}
|
|
6005
5917
|
}
|
|
6006
5918
|
result = result.toFixed(2);
|
|
6007
|
-
result = addType
|
|
6008
|
-
? result + resultType.toString()
|
|
6009
|
-
: parseFloat(result.toString());
|
|
5919
|
+
result = addType ? result + resultType.toString() : parseFloat(result.toString());
|
|
6010
5920
|
return result;
|
|
6011
5921
|
}
|
|
6012
5922
|
getNodeListValue(...args) {
|
|
@@ -6085,14 +5995,7 @@ class Utils {
|
|
|
6085
5995
|
if (text.length === 8) {
|
|
6086
5996
|
/* 该字符串只有时分秒 */
|
|
6087
5997
|
let today = new Date();
|
|
6088
|
-
text =
|
|
6089
|
-
today.getFullYear() +
|
|
6090
|
-
"-" +
|
|
6091
|
-
(today.getMonth() + 1) +
|
|
6092
|
-
"-" +
|
|
6093
|
-
today.getDate() +
|
|
6094
|
-
" " +
|
|
6095
|
-
text;
|
|
5998
|
+
text = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + " " + text;
|
|
6096
5999
|
}
|
|
6097
6000
|
text = text.substring(0, 19);
|
|
6098
6001
|
text = text.replace(/-/g, "/");
|
|
@@ -6113,25 +6016,13 @@ class Utils {
|
|
|
6113
6016
|
* 获取 transitionend 的在各个浏览器的兼容名
|
|
6114
6017
|
*/
|
|
6115
6018
|
getTransitionEndNameList() {
|
|
6116
|
-
return [
|
|
6117
|
-
"webkitTransitionEnd",
|
|
6118
|
-
"mozTransitionEnd",
|
|
6119
|
-
"MSTransitionEnd",
|
|
6120
|
-
"otransitionend",
|
|
6121
|
-
"transitionend",
|
|
6122
|
-
];
|
|
6019
|
+
return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
|
|
6123
6020
|
}
|
|
6124
6021
|
/**
|
|
6125
6022
|
* 获取 animationend 的在各个浏览器的兼容名
|
|
6126
6023
|
*/
|
|
6127
6024
|
getAnimationEndNameList() {
|
|
6128
|
-
return [
|
|
6129
|
-
"webkitAnimationEnd",
|
|
6130
|
-
"mozAnimationEnd",
|
|
6131
|
-
"MSAnimationEnd",
|
|
6132
|
-
"oanimationend",
|
|
6133
|
-
"animationend",
|
|
6134
|
-
];
|
|
6025
|
+
return ["webkitAnimationEnd", "mozAnimationEnd", "MSAnimationEnd", "oanimationend", "animationend"];
|
|
6135
6026
|
}
|
|
6136
6027
|
getArrayLastValue(targetObj) {
|
|
6137
6028
|
return targetObj[targetObj.length - 1];
|
|
@@ -6221,12 +6112,10 @@ class Utils {
|
|
|
6221
6112
|
}
|
|
6222
6113
|
getElementSelector(element) {
|
|
6223
6114
|
let UtilsContext = this;
|
|
6224
|
-
// @ts-ignore
|
|
6225
6115
|
if (!element)
|
|
6226
|
-
return;
|
|
6227
|
-
// @ts-ignore
|
|
6116
|
+
return void 0;
|
|
6228
6117
|
if (!element.parentElement)
|
|
6229
|
-
return;
|
|
6118
|
+
return void 0;
|
|
6230
6119
|
/* 如果元素有id属性,则直接返回id选择器 */
|
|
6231
6120
|
if (element.id)
|
|
6232
6121
|
return "#" + element.id;
|
|
@@ -6237,10 +6126,8 @@ class Utils {
|
|
|
6237
6126
|
}
|
|
6238
6127
|
/* 如果有多个相同类型的兄弟元素,则需要添加索引 */
|
|
6239
6128
|
if (element.parentElement.querySelectorAll(element.tagName).length > 1) {
|
|
6240
|
-
let index = Array.prototype.indexOf.call(element.parentElement.children, element) +
|
|
6241
|
-
|
|
6242
|
-
selector +=
|
|
6243
|
-
" > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
|
|
6129
|
+
let index = Array.prototype.indexOf.call(element.parentElement.children, element) + 1;
|
|
6130
|
+
selector += " > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
|
|
6244
6131
|
}
|
|
6245
6132
|
else {
|
|
6246
6133
|
selector += " > " + element.tagName.toLowerCase();
|
|
@@ -6257,13 +6144,10 @@ class Utils {
|
|
|
6257
6144
|
let result = [...args];
|
|
6258
6145
|
let newResult = [];
|
|
6259
6146
|
if (result.length === 0) {
|
|
6260
|
-
|
|
6261
|
-
return;
|
|
6147
|
+
return void 0;
|
|
6262
6148
|
}
|
|
6263
6149
|
if (result.length > 1) {
|
|
6264
|
-
if (result.length === 2 &&
|
|
6265
|
-
typeof result[0] === "object" &&
|
|
6266
|
-
typeof result[1] === "function") {
|
|
6150
|
+
if (result.length === 2 && typeof result[0] === "object" && typeof result[1] === "function") {
|
|
6267
6151
|
let data = result[0];
|
|
6268
6152
|
let handleDataFunc = result[1];
|
|
6269
6153
|
Object.keys(data).forEach((keyName) => {
|
|
@@ -6298,7 +6182,6 @@ class Utils {
|
|
|
6298
6182
|
// 当前页面最大的z-index
|
|
6299
6183
|
let zIndex = 0;
|
|
6300
6184
|
// 当前的最大z-index的元素,调试使用
|
|
6301
|
-
// @ts-ignore
|
|
6302
6185
|
let maxZIndexNode = null;
|
|
6303
6186
|
/**
|
|
6304
6187
|
* 元素是否可见
|
|
@@ -6359,13 +6242,10 @@ class Utils {
|
|
|
6359
6242
|
let result = [...args];
|
|
6360
6243
|
let newResult = [];
|
|
6361
6244
|
if (result.length === 0) {
|
|
6362
|
-
|
|
6363
|
-
return;
|
|
6245
|
+
return void 0;
|
|
6364
6246
|
}
|
|
6365
6247
|
if (result.length > 1) {
|
|
6366
|
-
if (result.length === 2 &&
|
|
6367
|
-
typeof result[0] === "object" &&
|
|
6368
|
-
typeof result[1] === "function") {
|
|
6248
|
+
if (result.length === 2 && typeof result[0] === "object" && typeof result[1] === "function") {
|
|
6369
6249
|
let data = result[0];
|
|
6370
6250
|
let handleDataFunc = result[1];
|
|
6371
6251
|
Object.keys(data).forEach((keyName) => {
|
|
@@ -6455,12 +6335,10 @@ class Utils {
|
|
|
6455
6335
|
getRandomValue(...args) {
|
|
6456
6336
|
let result = [...args];
|
|
6457
6337
|
if (result.length > 1) {
|
|
6458
|
-
if (result.length === 2 &&
|
|
6459
|
-
typeof result[0] === "number" &&
|
|
6460
|
-
typeof result[1] === "number") {
|
|
6338
|
+
if (result.length === 2 && typeof result[0] === "number" && typeof result[1] === "number") {
|
|
6461
6339
|
let leftNumber = result[0] > result[1] ? result[1] : result[0];
|
|
6462
6340
|
let rightNumber = result[0] > result[1] ? result[0] : result[1];
|
|
6463
|
-
return
|
|
6341
|
+
return Math.round(Math.random() * (rightNumber - leftNumber)) + leftNumber;
|
|
6464
6342
|
}
|
|
6465
6343
|
else {
|
|
6466
6344
|
return result[Math.floor(Math.random() * result.length)];
|
|
@@ -6471,8 +6349,7 @@ class Utils {
|
|
|
6471
6349
|
if (Array.isArray(paramData)) {
|
|
6472
6350
|
return paramData[Math.floor(Math.random() * paramData.length)];
|
|
6473
6351
|
}
|
|
6474
|
-
else if (typeof paramData === "object" &&
|
|
6475
|
-
Object.keys(paramData).length > 0) {
|
|
6352
|
+
else if (typeof paramData === "object" && Object.keys(paramData).length > 0) {
|
|
6476
6353
|
let paramObjDataKey = Object.keys(paramData)[Math.floor(Math.random() * Object.keys(paramData).length)];
|
|
6477
6354
|
return paramData[paramObjDataKey];
|
|
6478
6355
|
}
|
|
@@ -6779,11 +6656,9 @@ class Utils {
|
|
|
6779
6656
|
let nearBottomHeight = 50;
|
|
6780
6657
|
let checkWindow = () => {
|
|
6781
6658
|
// 已滚动的距离
|
|
6782
|
-
let scrollTop = this.windowApi.window.pageYOffset ||
|
|
6783
|
-
this.windowApi.document.documentElement.scrollTop;
|
|
6659
|
+
let scrollTop = this.windowApi.window.pageYOffset || this.windowApi.document.documentElement.scrollTop;
|
|
6784
6660
|
// 视窗高度
|
|
6785
|
-
let viewportHeight = this.windowApi.window.innerHeight ||
|
|
6786
|
-
this.windowApi.document.documentElement.clientHeight;
|
|
6661
|
+
let viewportHeight = this.windowApi.window.innerHeight || this.windowApi.document.documentElement.clientHeight;
|
|
6787
6662
|
// 最大滚动距离
|
|
6788
6663
|
let maxScrollHeight = this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
|
|
6789
6664
|
return scrollTop + viewportHeight >= maxScrollHeight;
|
|
@@ -6834,7 +6709,6 @@ class Utils {
|
|
|
6834
6709
|
}
|
|
6835
6710
|
isJQuery(target) {
|
|
6836
6711
|
let result = false;
|
|
6837
|
-
// @ts-ignore
|
|
6838
6712
|
if (typeof jQuery === "object" && target instanceof jQuery) {
|
|
6839
6713
|
result = true;
|
|
6840
6714
|
}
|
|
@@ -7073,8 +6947,7 @@ class Utils {
|
|
|
7073
6947
|
**/
|
|
7074
6948
|
isNull = commonUtil.isNull.bind(commonUtil);
|
|
7075
6949
|
isThemeDark() {
|
|
7076
|
-
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
7077
|
-
.matches;
|
|
6950
|
+
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
7078
6951
|
}
|
|
7079
6952
|
/**
|
|
7080
6953
|
* 判断元素是否在页面中可见
|
|
@@ -7107,10 +6980,8 @@ class Utils {
|
|
|
7107
6980
|
else {
|
|
7108
6981
|
let domClientRect = domItem.getBoundingClientRect();
|
|
7109
6982
|
if (inView) {
|
|
7110
|
-
let viewportWidth = this.windowApi.window.innerWidth ||
|
|
7111
|
-
|
|
7112
|
-
let viewportHeight = this.windowApi.window.innerHeight ||
|
|
7113
|
-
this.windowApi.document.documentElement.clientHeight;
|
|
6983
|
+
let viewportWidth = this.windowApi.window.innerWidth || this.windowApi.document.documentElement.clientWidth;
|
|
6984
|
+
let viewportHeight = this.windowApi.window.innerHeight || this.windowApi.document.documentElement.clientHeight;
|
|
7114
6985
|
result = !(domClientRect.right < 0 ||
|
|
7115
6986
|
domClientRect.left > viewportWidth ||
|
|
7116
6987
|
domClientRect.bottom < 0 ||
|
|
@@ -7134,8 +7005,7 @@ class Utils {
|
|
|
7134
7005
|
for (const key in Object.values(this.windowApi.top.window.via)) {
|
|
7135
7006
|
if (Reflect.has(this.windowApi.top.window.via, key)) {
|
|
7136
7007
|
let objValueFunc = this.windowApi.top.window.via[key];
|
|
7137
|
-
if (typeof objValueFunc === "function" &&
|
|
7138
|
-
UtilsContext.isNativeFunc(objValueFunc)) {
|
|
7008
|
+
if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
|
|
7139
7009
|
result = true;
|
|
7140
7010
|
}
|
|
7141
7011
|
else {
|
|
@@ -7157,8 +7027,7 @@ class Utils {
|
|
|
7157
7027
|
for (const key in Object.values(this.windowApi.top.window.mbrowser)) {
|
|
7158
7028
|
if (Reflect.has(this.windowApi.top.window.mbrowser, key)) {
|
|
7159
7029
|
let objValueFunc = this.windowApi.top.window.mbrowser[key];
|
|
7160
|
-
if (typeof objValueFunc === "function" &&
|
|
7161
|
-
UtilsContext.isNativeFunc(objValueFunc)) {
|
|
7030
|
+
if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
|
|
7162
7031
|
result = true;
|
|
7163
7032
|
}
|
|
7164
7033
|
else {
|
|
@@ -7395,13 +7264,11 @@ class Utils {
|
|
|
7395
7264
|
* 释放所有
|
|
7396
7265
|
*/
|
|
7397
7266
|
function releaseAll() {
|
|
7398
|
-
if (typeof UtilsContext.windowApi.window[needReleaseKey] !==
|
|
7399
|
-
"undefined") {
|
|
7267
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] !== "undefined") {
|
|
7400
7268
|
/* 已存在 */
|
|
7401
7269
|
return;
|
|
7402
7270
|
}
|
|
7403
|
-
UtilsContext.windowApi.window[needReleaseKey] =
|
|
7404
|
-
UtilsContext.deepClone(needReleaseObject);
|
|
7271
|
+
UtilsContext.windowApi.window[needReleaseKey] = UtilsContext.deepClone(needReleaseObject);
|
|
7405
7272
|
Object.values(needReleaseObject).forEach((value) => {
|
|
7406
7273
|
if (typeof value === "function") {
|
|
7407
7274
|
needReleaseObject[value.name] = () => { };
|
|
@@ -7415,8 +7282,7 @@ class Utils {
|
|
|
7415
7282
|
Array.from(functionNameList).forEach((item) => {
|
|
7416
7283
|
Object.values(needReleaseObject).forEach((value) => {
|
|
7417
7284
|
if (typeof value === "function") {
|
|
7418
|
-
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
7419
|
-
"undefined") {
|
|
7285
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
|
|
7420
7286
|
UtilsContext.windowApi.window[needReleaseKey] = {};
|
|
7421
7287
|
}
|
|
7422
7288
|
if (item === value.name) {
|
|
@@ -7431,8 +7297,7 @@ class Utils {
|
|
|
7431
7297
|
* 恢复所有
|
|
7432
7298
|
*/
|
|
7433
7299
|
function recoveryAll() {
|
|
7434
|
-
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
7435
|
-
"undefined") {
|
|
7300
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
|
|
7436
7301
|
/* 未存在 */
|
|
7437
7302
|
return;
|
|
7438
7303
|
}
|
|
@@ -7443,8 +7308,7 @@ class Utils {
|
|
|
7443
7308
|
* 恢复单个
|
|
7444
7309
|
*/
|
|
7445
7310
|
function recoveryOne() {
|
|
7446
|
-
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
7447
|
-
"undefined") {
|
|
7311
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
|
|
7448
7312
|
/* 未存在 */
|
|
7449
7313
|
return;
|
|
7450
7314
|
}
|
|
@@ -7452,8 +7316,7 @@ class Utils {
|
|
|
7452
7316
|
if (UtilsContext.windowApi.window[needReleaseKey][item]) {
|
|
7453
7317
|
needReleaseObject[item] = UtilsContext.windowApi.window[needReleaseKey][item];
|
|
7454
7318
|
Reflect.deleteProperty(UtilsContext.windowApi.window[needReleaseKey], item);
|
|
7455
|
-
if (Object.keys(UtilsContext.windowApi.window[needReleaseKey])
|
|
7456
|
-
.length === 0) {
|
|
7319
|
+
if (Object.keys(UtilsContext.windowApi.window[needReleaseKey]).length === 0) {
|
|
7457
7320
|
Reflect.deleteProperty(window, needReleaseKey);
|
|
7458
7321
|
}
|
|
7459
7322
|
}
|
|
@@ -7615,29 +7478,27 @@ class Utils {
|
|
|
7615
7478
|
EventTarget.prototype.addEventListener = function (...args) {
|
|
7616
7479
|
let type = args[0];
|
|
7617
7480
|
let callback = args[1];
|
|
7618
|
-
//
|
|
7619
|
-
args[2];
|
|
7481
|
+
// let options = args[2];
|
|
7620
7482
|
if (filter(type)) {
|
|
7621
7483
|
if (typeof callback === "function") {
|
|
7622
7484
|
args[1] = function (event) {
|
|
7623
7485
|
callback.call(this, trustEvent(event));
|
|
7624
7486
|
};
|
|
7625
7487
|
}
|
|
7626
|
-
else if (typeof callback === "object" &&
|
|
7627
|
-
"handleEvent" in callback) {
|
|
7488
|
+
else if (typeof callback === "object" && "handleEvent" in callback) {
|
|
7628
7489
|
let oldHandleEvent = callback["handleEvent"];
|
|
7629
7490
|
args[1]["handleEvent"] = function (event) {
|
|
7630
7491
|
if (event == null) {
|
|
7631
7492
|
return;
|
|
7632
7493
|
}
|
|
7633
7494
|
try {
|
|
7634
|
-
|
|
7495
|
+
// Proxy对象使用instanceof会报错
|
|
7496
|
+
// 这里故意尝试一下,如果报错,则说明是Proxy对象
|
|
7635
7497
|
event instanceof Proxy;
|
|
7636
7498
|
oldHandleEvent.call(this, trustEvent(event));
|
|
7637
7499
|
}
|
|
7638
7500
|
catch (error) {
|
|
7639
|
-
|
|
7640
|
-
event["isTrusted"] = isTrustValue;
|
|
7501
|
+
Reflect.set(event, "isTrusted", isTrustValue);
|
|
7641
7502
|
}
|
|
7642
7503
|
};
|
|
7643
7504
|
}
|
|
@@ -7710,10 +7571,9 @@ class Utils {
|
|
|
7710
7571
|
}
|
|
7711
7572
|
async init() {
|
|
7712
7573
|
let copyStatus = false;
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
if (this.hasClipboard() &&
|
|
7716
|
-
(this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
7574
|
+
let requestPermissionStatus = await this.requestClipboardPermission();
|
|
7575
|
+
console.log(requestPermissionStatus);
|
|
7576
|
+
if (this.hasClipboard() && (this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
7717
7577
|
try {
|
|
7718
7578
|
copyStatus = await this.copyDataByClipboard();
|
|
7719
7579
|
}
|
|
@@ -7729,11 +7589,8 @@ class Utils {
|
|
|
7729
7589
|
this.destroy();
|
|
7730
7590
|
}
|
|
7731
7591
|
destroy() {
|
|
7732
|
-
// @ts-ignore
|
|
7733
7592
|
this.#resolve = null;
|
|
7734
|
-
// @ts-ignore
|
|
7735
7593
|
this.#copyData = null;
|
|
7736
|
-
// @ts-ignore
|
|
7737
7594
|
this.#copyDataType = null;
|
|
7738
7595
|
}
|
|
7739
7596
|
isText() {
|
|
@@ -7777,7 +7634,6 @@ class Utils {
|
|
|
7777
7634
|
if (navigator.permissions && navigator.permissions.query) {
|
|
7778
7635
|
navigator.permissions
|
|
7779
7636
|
.query({
|
|
7780
|
-
// @ts-ignore
|
|
7781
7637
|
name: "clipboard-write",
|
|
7782
7638
|
})
|
|
7783
7639
|
.then((permissionStatus) => {
|
|
@@ -7873,17 +7729,13 @@ class Utils {
|
|
|
7873
7729
|
dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
|
|
7874
7730
|
let UtilsContext = this;
|
|
7875
7731
|
function initMouseEvent(eventName, offSetX, offSetY) {
|
|
7876
|
-
// @ts-ignore
|
|
7877
7732
|
let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
|
|
7878
7733
|
let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
7879
7734
|
mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
|
|
7880
7735
|
return mouseEvent;
|
|
7881
7736
|
}
|
|
7882
|
-
let sliderElement = typeof selector === "string"
|
|
7883
|
-
|
|
7884
|
-
: selector;
|
|
7885
|
-
if (!(sliderElement instanceof Node) ||
|
|
7886
|
-
!(sliderElement instanceof Element)) {
|
|
7737
|
+
let sliderElement = typeof selector === "string" ? domUtils.selector(selector) : selector;
|
|
7738
|
+
if (!(sliderElement instanceof Node) || !(sliderElement instanceof Element)) {
|
|
7887
7739
|
throw new Error("Utils.dragSlider 参数selector 必须为Node/Element类型");
|
|
7888
7740
|
}
|
|
7889
7741
|
let rect = sliderElement.getBoundingClientRect(), x0 = rect.x || rect.left, y0 = rect.y || rect.top, x1 = x0 + offsetX, y1 = y0;
|
|
@@ -7935,17 +7787,14 @@ class Utils {
|
|
|
7935
7787
|
}
|
|
7936
7788
|
sortListByProperty(data, getPropertyValueFunc, sortByDesc = true) {
|
|
7937
7789
|
let UtilsContext = this;
|
|
7938
|
-
if (typeof getPropertyValueFunc !== "function" &&
|
|
7939
|
-
typeof getPropertyValueFunc !== "string") {
|
|
7790
|
+
if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
|
|
7940
7791
|
throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
|
|
7941
7792
|
}
|
|
7942
7793
|
if (typeof sortByDesc !== "boolean") {
|
|
7943
7794
|
throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
|
|
7944
7795
|
}
|
|
7945
7796
|
let getObjValue = function (obj) {
|
|
7946
|
-
return typeof getPropertyValueFunc === "string"
|
|
7947
|
-
? obj[getPropertyValueFunc]
|
|
7948
|
-
: getPropertyValueFunc(obj);
|
|
7797
|
+
return typeof getPropertyValueFunc === "string" ? obj[getPropertyValueFunc] : getPropertyValueFunc(obj);
|
|
7949
7798
|
};
|
|
7950
7799
|
/**
|
|
7951
7800
|
* 排序方法
|
|
@@ -8020,8 +7869,7 @@ class Utils {
|
|
|
8020
7869
|
if (Array.isArray(data)) {
|
|
8021
7870
|
data.sort(sortFunc);
|
|
8022
7871
|
}
|
|
8023
|
-
else if (data instanceof NodeList ||
|
|
8024
|
-
UtilsContext.isJQuery(data)) {
|
|
7872
|
+
else if (data instanceof NodeList || UtilsContext.isJQuery(data)) {
|
|
8025
7873
|
sortNodeFunc(data, getDataFunc);
|
|
8026
7874
|
result = getDataFunc();
|
|
8027
7875
|
}
|
|
@@ -8032,7 +7880,6 @@ class Utils {
|
|
|
8032
7880
|
}
|
|
8033
7881
|
stringToRegular(targetString, flags = "ig") {
|
|
8034
7882
|
let reg;
|
|
8035
|
-
// @ts-ignore
|
|
8036
7883
|
flags = flags.toLowerCase();
|
|
8037
7884
|
if (typeof targetString === "string") {
|
|
8038
7885
|
reg = new RegExp(targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"), flags);
|
|
@@ -8125,10 +7972,8 @@ class Utils {
|
|
|
8125
7972
|
*/
|
|
8126
7973
|
searchParamStrToObj(searhParamsStr) {
|
|
8127
7974
|
if (typeof searhParamsStr !== "string") {
|
|
8128
|
-
// @ts-ignore
|
|
8129
7975
|
return {};
|
|
8130
7976
|
}
|
|
8131
|
-
// @ts-ignore
|
|
8132
7977
|
return Object.fromEntries(new URLSearchParams(searhParamsStr));
|
|
8133
7978
|
}
|
|
8134
7979
|
/**
|
|
@@ -8217,9 +8062,7 @@ class Utils {
|
|
|
8217
8062
|
let parent = UtilsContext.windowApi.document;
|
|
8218
8063
|
// 超时时间
|
|
8219
8064
|
let timeout = 0;
|
|
8220
|
-
if (typeof args[0] !== "string" &&
|
|
8221
|
-
!Array.isArray(args[0]) &&
|
|
8222
|
-
typeof args[0] !== "function") {
|
|
8065
|
+
if (typeof args[0] !== "string" && !Array.isArray(args[0]) && typeof args[0] !== "function") {
|
|
8223
8066
|
throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
|
|
8224
8067
|
}
|
|
8225
8068
|
if (args.length === 1) ;
|
|
@@ -8229,8 +8072,7 @@ class Utils {
|
|
|
8229
8072
|
// "div",10000
|
|
8230
8073
|
timeout = secondParam;
|
|
8231
8074
|
}
|
|
8232
|
-
else if (typeof secondParam === "object" &&
|
|
8233
|
-
secondParam instanceof Node) {
|
|
8075
|
+
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8234
8076
|
// "div",document
|
|
8235
8077
|
parent = secondParam;
|
|
8236
8078
|
}
|
|
@@ -8316,8 +8158,7 @@ class Utils {
|
|
|
8316
8158
|
// "div",10000
|
|
8317
8159
|
timeout = secondParam;
|
|
8318
8160
|
}
|
|
8319
|
-
else if (typeof secondParam === "object" &&
|
|
8320
|
-
secondParam instanceof Node) {
|
|
8161
|
+
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8321
8162
|
// "div",document
|
|
8322
8163
|
parent = secondParam;
|
|
8323
8164
|
}
|
|
@@ -8372,8 +8213,7 @@ class Utils {
|
|
|
8372
8213
|
// "div",10000
|
|
8373
8214
|
timeout = secondParam;
|
|
8374
8215
|
}
|
|
8375
|
-
else if (typeof secondParam === "object" &&
|
|
8376
|
-
secondParam instanceof Node) {
|
|
8216
|
+
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8377
8217
|
// "div",document
|
|
8378
8218
|
parent = secondParam;
|
|
8379
8219
|
}
|
|
@@ -8459,8 +8299,7 @@ class Utils {
|
|
|
8459
8299
|
// "div",10000
|
|
8460
8300
|
timeout = secondParam;
|
|
8461
8301
|
}
|
|
8462
|
-
else if (typeof secondParam === "object" &&
|
|
8463
|
-
secondParam instanceof Node) {
|
|
8302
|
+
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8464
8303
|
// "div",document
|
|
8465
8304
|
parent = secondParam;
|
|
8466
8305
|
}
|
|
@@ -8593,8 +8432,7 @@ class Utils {
|
|
|
8593
8432
|
return flag;
|
|
8594
8433
|
}
|
|
8595
8434
|
watchObject(target, propertyName, getCallBack, setCallBack) {
|
|
8596
|
-
if (typeof getCallBack !== "function" &&
|
|
8597
|
-
typeof setCallBack !== "function") {
|
|
8435
|
+
if (typeof getCallBack !== "function" && typeof setCallBack !== "function") {
|
|
8598
8436
|
return;
|
|
8599
8437
|
}
|
|
8600
8438
|
if (typeof getCallBack === "function") {
|
|
@@ -8646,13 +8484,27 @@ class Utils {
|
|
|
8646
8484
|
return;
|
|
8647
8485
|
}
|
|
8648
8486
|
let handleResult = handler(target);
|
|
8649
|
-
if (handleResult &&
|
|
8650
|
-
typeof handleResult.isFind === "boolean" &&
|
|
8651
|
-
handleResult.isFind) {
|
|
8487
|
+
if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) {
|
|
8652
8488
|
return handleResult.data;
|
|
8653
8489
|
}
|
|
8654
8490
|
return this.queryProperty(handleResult.data, handler);
|
|
8655
8491
|
}
|
|
8492
|
+
/**
|
|
8493
|
+
* 异步-深度获取对象属性
|
|
8494
|
+
* @param target 待获取的对象
|
|
8495
|
+
* @param handler 获取属性的回调
|
|
8496
|
+
*/
|
|
8497
|
+
async asyncQueryProperty(target, handler) {
|
|
8498
|
+
if (target == null) {
|
|
8499
|
+
// @ts-ignore
|
|
8500
|
+
return;
|
|
8501
|
+
}
|
|
8502
|
+
let handleResult = await handler(target);
|
|
8503
|
+
if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) {
|
|
8504
|
+
return handleResult.data;
|
|
8505
|
+
}
|
|
8506
|
+
return await this.asyncQueryProperty(handleResult.data, handler);
|
|
8507
|
+
}
|
|
8656
8508
|
/**
|
|
8657
8509
|
* 创建一个新的Utils实例
|
|
8658
8510
|
* @param option
|
|
@@ -8831,7 +8683,6 @@ class Utils {
|
|
|
8831
8683
|
function requestPermissionsWithClipboard() {
|
|
8832
8684
|
navigator.permissions
|
|
8833
8685
|
.query({
|
|
8834
|
-
// @ts-ignore
|
|
8835
8686
|
name: "clipboard-read",
|
|
8836
8687
|
})
|
|
8837
8688
|
.then((permissionStatus) => {
|