@whitesev/utils 2.7.0 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -19
- package/dist/index.amd.js +205 -235
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +205 -235
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +205 -235
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +205 -235
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +205 -235
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +205 -235
- 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 +1 -1
- 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/Httpx.d.ts +73 -67
- 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 +14 -25
- package/src/DOMUtils.ts +14 -16
- package/src/Dictionary.ts +39 -35
- package/src/GBKEncoder.ts +8 -12
- package/src/Hooks.ts +1 -3
- package/src/Httpx.ts +194 -174
- package/src/LockFunction.ts +3 -3
- package/src/Log.ts +1 -3
- package/src/Progress.ts +1 -3
- package/src/TryCatch.ts +4 -4
- package/src/Utils.ts +29 -45
- package/src/UtilsGMMenu.ts +19 -22
- package/src/Vue.ts +4 -7
- package/src/WindowApi.ts +2 -5
- package/src/ajaxHooker/ajaxHooker.js +35 -21
- package/src/indexedDB.ts +8 -8
- package/src/types/Httpx.d.ts +73 -67
- package/src/types/env.d.ts +2 -0
- package/src/types/global.d.ts +3 -0
package/dist/index.esm.js
CHANGED
|
@@ -15,14 +15,13 @@ class ColorConversion {
|
|
|
15
15
|
/**
|
|
16
16
|
* 16进制颜色转rgba
|
|
17
17
|
*
|
|
18
|
-
*
|
|
18
|
+
* 例如:`#ff0000` 转为 `rgba(123,123,123, 0.4)`
|
|
19
19
|
* @param hex
|
|
20
20
|
* @param opacity
|
|
21
21
|
*/
|
|
22
22
|
hexToRgba(hex, opacity) {
|
|
23
23
|
if (!this.isHex(hex)) {
|
|
24
|
-
|
|
25
|
-
throw new TypeError("输入错误的hex", hex);
|
|
24
|
+
throw new TypeError("输入错误的hex:" + hex);
|
|
26
25
|
}
|
|
27
26
|
return hex && hex.replace(/\s+/g, "").length === 7
|
|
28
27
|
? "rgba(" +
|
|
@@ -39,19 +38,16 @@ class ColorConversion {
|
|
|
39
38
|
/**
|
|
40
39
|
* hex转rgb
|
|
41
40
|
* @param str
|
|
42
|
-
* @returns
|
|
43
41
|
*/
|
|
44
42
|
hexToRgb(str) {
|
|
45
43
|
if (!this.isHex(str)) {
|
|
46
|
-
|
|
47
|
-
throw new TypeError("输入错误的hex", str);
|
|
44
|
+
throw new TypeError("输入错误的hex:" + str);
|
|
48
45
|
}
|
|
49
46
|
/* replace替换查找的到的字符串 */
|
|
50
47
|
str = str.replace("#", "");
|
|
51
48
|
/* match得到查询数组 */
|
|
52
49
|
let hxs = str.match(/../g);
|
|
53
50
|
for (let index = 0; index < 3; index++) {
|
|
54
|
-
// @ts-ignore
|
|
55
51
|
hxs[index] = parseInt(hxs[index], 16);
|
|
56
52
|
}
|
|
57
53
|
return hxs;
|
|
@@ -61,7 +57,6 @@ class ColorConversion {
|
|
|
61
57
|
* @param redValue
|
|
62
58
|
* @param greenValue
|
|
63
59
|
* @param blueValue
|
|
64
|
-
* @returns
|
|
65
60
|
*/
|
|
66
61
|
rgbToHex(redValue, greenValue, blueValue) {
|
|
67
62
|
/* 验证输入的rgb值是否合法 */
|
|
@@ -84,38 +79,30 @@ class ColorConversion {
|
|
|
84
79
|
* 获取颜色变暗或亮
|
|
85
80
|
* @param color 颜色
|
|
86
81
|
* @param level 0~1.0
|
|
87
|
-
* @returns
|
|
88
82
|
*/
|
|
89
83
|
getDarkColor(color, level) {
|
|
90
84
|
if (!this.isHex(color)) {
|
|
91
|
-
|
|
92
|
-
throw new TypeError("输入错误的hex", color);
|
|
85
|
+
throw new TypeError("输入错误的hex:" + color);
|
|
93
86
|
}
|
|
94
87
|
let rgbc = this.hexToRgb(color);
|
|
95
88
|
for (let index = 0; index < 3; index++) {
|
|
96
|
-
// @ts-ignore
|
|
97
89
|
rgbc[index] = Math.floor(rgbc[index] * (1 - level));
|
|
98
90
|
}
|
|
99
|
-
// @ts-ignore
|
|
100
91
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
101
92
|
}
|
|
102
93
|
/**
|
|
103
94
|
* 获取颜色变亮
|
|
104
95
|
* @param color 颜色
|
|
105
96
|
* @param level 0~1.0
|
|
106
|
-
* @returns
|
|
107
97
|
*/
|
|
108
98
|
getLightColor(color, level) {
|
|
109
99
|
if (!this.isHex(color)) {
|
|
110
|
-
|
|
111
|
-
throw new TypeError("输入错误的hex", color);
|
|
100
|
+
throw new TypeError("输入错误的hex:" + color);
|
|
112
101
|
}
|
|
113
102
|
let rgbc = this.hexToRgb(color);
|
|
114
103
|
for (let index = 0; index < 3; index++) {
|
|
115
|
-
// @ts-ignore
|
|
116
104
|
rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
|
|
117
105
|
}
|
|
118
|
-
// @ts-ignore
|
|
119
106
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
120
107
|
}
|
|
121
108
|
}
|
|
@@ -203,20 +190,20 @@ class GBKEncoder {
|
|
|
203
190
|
* @param str
|
|
204
191
|
*/
|
|
205
192
|
decode(str) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
193
|
+
let GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
|
|
194
|
+
let UTFMatcher = /%[0-9A-F]{2}/;
|
|
195
|
+
// let gbk = true;
|
|
196
|
+
let utf = true;
|
|
197
|
+
const that = this;
|
|
211
198
|
while (utf) {
|
|
212
199
|
let gbkMatch = str.match(GBKMatcher);
|
|
213
200
|
let utfMatch = str.match(UTFMatcher);
|
|
201
|
+
// gbk = Boolean(gbkMatch);
|
|
214
202
|
utf = Boolean(utfMatch);
|
|
215
203
|
if (gbkMatch && gbkMatch in that.#G2Uhash) {
|
|
216
204
|
str = str.replace(gbkMatch, String.fromCharCode(("0x" + that.#G2Uhash[gbkMatch])));
|
|
217
205
|
}
|
|
218
206
|
else {
|
|
219
|
-
// @ts-ignore
|
|
220
207
|
str = str.replace(utfMatch, decodeURIComponent(utfMatch));
|
|
221
208
|
}
|
|
222
209
|
}
|
|
@@ -247,7 +234,6 @@ const TryCatch = function (...args) {
|
|
|
247
234
|
* @param handler
|
|
248
235
|
*/
|
|
249
236
|
error(handler) {
|
|
250
|
-
// @ts-ignore
|
|
251
237
|
handleError = handler;
|
|
252
238
|
return TryCatchCore;
|
|
253
239
|
},
|
|
@@ -262,8 +248,9 @@ const TryCatch = function (...args) {
|
|
|
262
248
|
callbackFunction = callback;
|
|
263
249
|
context = __context__ || this;
|
|
264
250
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
265
|
-
|
|
266
|
-
|
|
251
|
+
return result !== void 0
|
|
252
|
+
? result
|
|
253
|
+
: TryCatchCore;
|
|
267
254
|
},
|
|
268
255
|
};
|
|
269
256
|
/**
|
|
@@ -746,13 +733,13 @@ class UtilsGMCookie {
|
|
|
746
733
|
// ==UserScript==
|
|
747
734
|
// @name ajaxHooker
|
|
748
735
|
// @author cxxjackie
|
|
749
|
-
// @version 1.4.
|
|
736
|
+
// @version 1.4.7
|
|
750
737
|
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
751
738
|
// @license GNU LGPL-3.0
|
|
752
739
|
// ==/UserScript==
|
|
753
740
|
|
|
754
741
|
const ajaxHooker = function () {
|
|
755
|
-
const version = "1.4.
|
|
742
|
+
const version = "1.4.7";
|
|
756
743
|
const hookInst = {
|
|
757
744
|
hookFns: [],
|
|
758
745
|
filters: [],
|
|
@@ -762,20 +749,18 @@ const ajaxHooker = function () {
|
|
|
762
749
|
const resProto = win.Response.prototype;
|
|
763
750
|
const xhrResponses = ["response", "responseText", "responseXML"];
|
|
764
751
|
const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
|
|
765
|
-
const
|
|
766
|
-
|
|
767
|
-
"headers",
|
|
768
|
-
"body",
|
|
769
|
-
"mode",
|
|
770
|
-
"credentials",
|
|
752
|
+
const xhrExtraProps = ["responseType", "timeout", "withCredentials"];
|
|
753
|
+
const fetchExtraProps = [
|
|
771
754
|
"cache",
|
|
755
|
+
"credentials",
|
|
756
|
+
"integrity",
|
|
757
|
+
"keepalive",
|
|
758
|
+
"mode",
|
|
759
|
+
"priority",
|
|
772
760
|
"redirect",
|
|
773
761
|
"referrer",
|
|
774
762
|
"referrerPolicy",
|
|
775
|
-
"integrity",
|
|
776
|
-
"keepalive",
|
|
777
763
|
"signal",
|
|
778
|
-
"priority",
|
|
779
764
|
];
|
|
780
765
|
const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
|
|
781
766
|
const getType = {}.toString.call.bind({}.toString);
|
|
@@ -853,6 +838,10 @@ const ajaxHooker = function () {
|
|
|
853
838
|
this.request = request;
|
|
854
839
|
this.requestClone = { ...this.request };
|
|
855
840
|
}
|
|
841
|
+
_recoverRequestKey(key) {
|
|
842
|
+
if (key in this.requestClone) this.request[key] = this.requestClone[key];
|
|
843
|
+
else delete this.request[key];
|
|
844
|
+
}
|
|
856
845
|
shouldFilter(filters) {
|
|
857
846
|
const { type, url, method, async } = this.request;
|
|
858
847
|
return (
|
|
@@ -873,7 +862,6 @@ const ajaxHooker = function () {
|
|
|
873
862
|
);
|
|
874
863
|
}
|
|
875
864
|
waitForRequestKeys() {
|
|
876
|
-
const requestKeys = ["url", "method", "abort", "headers", "data"];
|
|
877
865
|
if (!this.request.async) {
|
|
878
866
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
879
867
|
if (this.shouldFilter(filters)) return;
|
|
@@ -881,27 +869,31 @@ const ajaxHooker = function () {
|
|
|
881
869
|
if (getType(fn) === "[object Function]")
|
|
882
870
|
catchError(fn, this.request);
|
|
883
871
|
});
|
|
884
|
-
|
|
885
|
-
if (isThenable(this.request[key]))
|
|
886
|
-
|
|
887
|
-
});
|
|
872
|
+
for (const key in this.request) {
|
|
873
|
+
if (isThenable(this.request[key])) this._recoverRequestKey(key);
|
|
874
|
+
}
|
|
888
875
|
});
|
|
889
876
|
return new SyncThenable();
|
|
890
877
|
}
|
|
891
878
|
const promises = [];
|
|
879
|
+
const ignoreKeys = new Set(["type", "async", "response"]);
|
|
892
880
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
893
881
|
if (this.shouldFilter(filters)) return;
|
|
894
882
|
promises.push(
|
|
895
883
|
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
896
|
-
() =>
|
|
897
|
-
|
|
884
|
+
() => {
|
|
885
|
+
const requestKeys = [];
|
|
886
|
+
for (const key in this.request)
|
|
887
|
+
!ignoreKeys.has(key) && requestKeys.push(key);
|
|
888
|
+
return Promise.all(
|
|
898
889
|
requestKeys.map((key) =>
|
|
899
890
|
Promise.resolve(this.request[key]).then(
|
|
900
891
|
(val) => (this.request[key] = val),
|
|
901
|
-
() =>
|
|
892
|
+
() => this._recoverRequestKey(key)
|
|
902
893
|
)
|
|
903
894
|
)
|
|
904
|
-
)
|
|
895
|
+
);
|
|
896
|
+
}
|
|
905
897
|
)
|
|
906
898
|
);
|
|
907
899
|
});
|
|
@@ -1082,6 +1074,7 @@ const ajaxHooker = function () {
|
|
|
1082
1074
|
e.stopImmediatePropagation = stopImmediatePropagation;
|
|
1083
1075
|
defineProp(e, "target", () => this.proxyXhr);
|
|
1084
1076
|
defineProp(e, "currentTarget", () => this.proxyXhr);
|
|
1077
|
+
defineProp(e, "srcElement", () => this.proxyXhr);
|
|
1085
1078
|
this.proxyEvents[e.type] &&
|
|
1086
1079
|
this.proxyEvents[e.type].forEach((fn) => {
|
|
1087
1080
|
this.resThenable.then(
|
|
@@ -1159,6 +1152,9 @@ const ajaxHooker = function () {
|
|
|
1159
1152
|
for (const header in request.headers) {
|
|
1160
1153
|
xhr.setRequestHeader(header, request.headers[header]);
|
|
1161
1154
|
}
|
|
1155
|
+
for (const prop of xhrExtraProps) {
|
|
1156
|
+
if (prop in request) xhr[prop] = request[prop];
|
|
1157
|
+
}
|
|
1162
1158
|
xhr.send(request.data);
|
|
1163
1159
|
}
|
|
1164
1160
|
});
|
|
@@ -1180,8 +1176,10 @@ const ajaxHooker = function () {
|
|
|
1180
1176
|
return new Promise(async (resolve, reject) => {
|
|
1181
1177
|
const init = {};
|
|
1182
1178
|
if (getType(url) === "[object Request]") {
|
|
1183
|
-
|
|
1179
|
+
init.method = url.method;
|
|
1180
|
+
init.headers = url.headers;
|
|
1184
1181
|
if (url.body) init.body = await url.arrayBuffer();
|
|
1182
|
+
for (const prop of fetchExtraProps) init[prop] = url[prop];
|
|
1185
1183
|
url = url.url;
|
|
1186
1184
|
}
|
|
1187
1185
|
url = url.toString();
|
|
@@ -1228,6 +1226,9 @@ const ajaxHooker = function () {
|
|
|
1228
1226
|
init.method = request.method;
|
|
1229
1227
|
init.headers = request.headers;
|
|
1230
1228
|
init.body = request.data;
|
|
1229
|
+
for (const prop of fetchExtraProps) {
|
|
1230
|
+
if (prop in request) init[prop] = request[prop];
|
|
1231
|
+
}
|
|
1231
1232
|
winAh.realFetch.call(win, request.url, init).then((res) => {
|
|
1232
1233
|
if (typeof request.response === "function") {
|
|
1233
1234
|
const response = {
|
|
@@ -1933,25 +1934,24 @@ class GMMenu {
|
|
|
1933
1934
|
let defaultEnable = Boolean(this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable));
|
|
1934
1935
|
/** 油猴菜单上显示的文本 */
|
|
1935
1936
|
let showText = menuOption.showText(menuOption.text, defaultEnable);
|
|
1936
|
-
//
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
});
|
|
1937
|
+
// const GMMenuOptions = {
|
|
1938
|
+
// /**
|
|
1939
|
+
// * 菜单的id
|
|
1940
|
+
// */
|
|
1941
|
+
// id: menuOption.id,
|
|
1942
|
+
// /**
|
|
1943
|
+
// * 点击菜单项后是否应关闭弹出菜单
|
|
1944
|
+
// */
|
|
1945
|
+
// autoClose: menuOption.autoClose,
|
|
1946
|
+
// /**
|
|
1947
|
+
// * 菜单项的可选访问键
|
|
1948
|
+
// */
|
|
1949
|
+
// accessKey: menuOption.accessKey,
|
|
1950
|
+
// /**
|
|
1951
|
+
// * 菜单项的鼠标悬浮上的工具提示
|
|
1952
|
+
// */
|
|
1953
|
+
// title: menuOption.title,
|
|
1954
|
+
// };
|
|
1955
1955
|
/* 点击菜单后触发callback后的网页是否刷新 */
|
|
1956
1956
|
menuOption.autoReload =
|
|
1957
1957
|
typeof menuOption.autoReload !== "boolean"
|
|
@@ -2529,7 +2529,9 @@ class Httpx {
|
|
|
2529
2529
|
* 对请求的参数进行合并处理
|
|
2530
2530
|
*/
|
|
2531
2531
|
handleBeforeRequestOptionArgs(...args) {
|
|
2532
|
-
let option = {
|
|
2532
|
+
let option = {
|
|
2533
|
+
url: void 0,
|
|
2534
|
+
};
|
|
2533
2535
|
if (typeof args[0] === "string") {
|
|
2534
2536
|
/* 传入的是url,转为配置 */
|
|
2535
2537
|
let url = args[0];
|
|
@@ -2553,7 +2555,7 @@ class Httpx {
|
|
|
2553
2555
|
* @param method 当前请求方法,默认get
|
|
2554
2556
|
* @param userRequestOption 用户的请求配置
|
|
2555
2557
|
* @param resolve promise回调
|
|
2556
|
-
* @param reject 抛出错误回调
|
|
2558
|
+
* @param reject promise抛出错误回调
|
|
2557
2559
|
*/
|
|
2558
2560
|
getRequestOption(method, userRequestOption, resolve, reject) {
|
|
2559
2561
|
let that = this;
|
|
@@ -2611,25 +2613,25 @@ class Httpx {
|
|
|
2611
2613
|
password: userRequestOption.password ||
|
|
2612
2614
|
this.context.#defaultRequestOption.password,
|
|
2613
2615
|
onabort(...args) {
|
|
2614
|
-
that.context.
|
|
2616
|
+
that.context.HttpxResponseCallBack.onAbort(userRequestOption, resolve, reject, args);
|
|
2615
2617
|
},
|
|
2616
2618
|
onerror(...args) {
|
|
2617
|
-
that.context.
|
|
2619
|
+
that.context.HttpxResponseCallBack.onError(userRequestOption, resolve, reject, args);
|
|
2618
2620
|
},
|
|
2619
2621
|
onloadstart(...args) {
|
|
2620
|
-
that.context.
|
|
2622
|
+
that.context.HttpxResponseCallBack.onLoadStart(userRequestOption, args);
|
|
2621
2623
|
},
|
|
2622
2624
|
onprogress(...args) {
|
|
2623
|
-
that.context.
|
|
2625
|
+
that.context.HttpxResponseCallBack.onProgress(userRequestOption, args);
|
|
2624
2626
|
},
|
|
2625
2627
|
onreadystatechange(...args) {
|
|
2626
|
-
that.context.
|
|
2628
|
+
that.context.HttpxResponseCallBack.onReadyStateChange(userRequestOption, args);
|
|
2627
2629
|
},
|
|
2628
2630
|
ontimeout(...args) {
|
|
2629
|
-
that.context.
|
|
2631
|
+
that.context.HttpxResponseCallBack.onTimeout(userRequestOption, resolve, reject, args);
|
|
2630
2632
|
},
|
|
2631
2633
|
onload(...args) {
|
|
2632
|
-
that.context.
|
|
2634
|
+
that.context.HttpxResponseCallBack.onLoad(userRequestOption, resolve, reject, args);
|
|
2633
2635
|
},
|
|
2634
2636
|
};
|
|
2635
2637
|
// 补全allowInterceptConfig参数
|
|
@@ -2741,7 +2743,6 @@ class Httpx {
|
|
|
2741
2743
|
else if (typeof requestOption.data === "object") {
|
|
2742
2744
|
isHandler = true;
|
|
2743
2745
|
// URLSearchParams参数可以转普通的string:string,包括FormData
|
|
2744
|
-
// @ts-ignore
|
|
2745
2746
|
let searchParams = new URLSearchParams(requestOption.data);
|
|
2746
2747
|
urlSearch = searchParams.toString();
|
|
2747
2748
|
}
|
|
@@ -2796,9 +2797,7 @@ class Httpx {
|
|
|
2796
2797
|
else if (ContentType.includes("application/x-www-form-urlencoded")) {
|
|
2797
2798
|
// application/x-www-form-urlencoded
|
|
2798
2799
|
if (typeof requestOption.data === "object") {
|
|
2799
|
-
requestOption.data = new URLSearchParams(
|
|
2800
|
-
// @ts-ignore
|
|
2801
|
-
requestOption.data).toString();
|
|
2800
|
+
requestOption.data = new URLSearchParams(requestOption.data).toString();
|
|
2802
2801
|
}
|
|
2803
2802
|
}
|
|
2804
2803
|
else if (ContentType.includes("multipart/form-data")) {
|
|
@@ -2818,7 +2817,7 @@ class Httpx {
|
|
|
2818
2817
|
},
|
|
2819
2818
|
/**
|
|
2820
2819
|
* 处理发送请求的配置,去除值为undefined、空function的值
|
|
2821
|
-
* @param option
|
|
2820
|
+
* @param option 请求配置
|
|
2822
2821
|
*/
|
|
2823
2822
|
removeRequestNullOption(option) {
|
|
2824
2823
|
Object.keys(option).forEach((keyName) => {
|
|
@@ -2830,13 +2829,13 @@ class Httpx {
|
|
|
2830
2829
|
}
|
|
2831
2830
|
});
|
|
2832
2831
|
if (commonUtil.isNull(option.url)) {
|
|
2833
|
-
throw new TypeError(`Utils.Httpx 参数
|
|
2832
|
+
throw new TypeError(`Utils.Httpx 参数url不能为空:${option.url}`);
|
|
2834
2833
|
}
|
|
2835
2834
|
return option;
|
|
2836
2835
|
},
|
|
2837
2836
|
/**
|
|
2838
2837
|
* 处理fetch的配置
|
|
2839
|
-
* @param option
|
|
2838
|
+
* @param option 请求配置
|
|
2840
2839
|
*/
|
|
2841
2840
|
handleFetchOption(option) {
|
|
2842
2841
|
/**
|
|
@@ -2889,21 +2888,21 @@ class Httpx {
|
|
|
2889
2888
|
};
|
|
2890
2889
|
},
|
|
2891
2890
|
};
|
|
2892
|
-
|
|
2891
|
+
HttpxResponseCallBack = {
|
|
2893
2892
|
context: this,
|
|
2894
2893
|
/**
|
|
2895
2894
|
* onabort请求被取消-触发
|
|
2896
2895
|
* @param details 配置
|
|
2897
|
-
* @param resolve 回调
|
|
2898
|
-
* @param reject
|
|
2896
|
+
* @param resolve promise回调
|
|
2897
|
+
* @param reject promise抛出错误回调
|
|
2899
2898
|
* @param argsResult 返回的参数列表
|
|
2900
2899
|
*/
|
|
2901
2900
|
async onAbort(details, resolve, reject, argsResult) {
|
|
2902
2901
|
// console.log(argsResult);
|
|
2903
|
-
if (
|
|
2902
|
+
if (typeof details?.onabort === "function") {
|
|
2904
2903
|
details.onabort.apply(this, argsResult);
|
|
2905
2904
|
}
|
|
2906
|
-
else if (
|
|
2905
|
+
else if (typeof this.context.#defaultRequestOption?.onabort === "function") {
|
|
2907
2906
|
this.context.#defaultRequestOption.onabort.apply(this, argsResult);
|
|
2908
2907
|
}
|
|
2909
2908
|
let response = argsResult;
|
|
@@ -2912,11 +2911,11 @@ class Httpx {
|
|
|
2912
2911
|
}
|
|
2913
2912
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2914
2913
|
type: "onabort",
|
|
2915
|
-
error: new
|
|
2914
|
+
error: new Error("request canceled"),
|
|
2916
2915
|
response: null,
|
|
2917
2916
|
details: details,
|
|
2918
2917
|
})) == null) {
|
|
2919
|
-
// reject(new
|
|
2918
|
+
// reject(new Error("response is intercept with onabort"));
|
|
2920
2919
|
return;
|
|
2921
2920
|
}
|
|
2922
2921
|
resolve({
|
|
@@ -2929,93 +2928,83 @@ class Httpx {
|
|
|
2929
2928
|
});
|
|
2930
2929
|
},
|
|
2931
2930
|
/**
|
|
2932
|
-
*
|
|
2931
|
+
* ontimeout请求超时-触发
|
|
2933
2932
|
* @param details 配置
|
|
2934
2933
|
* @param resolve 回调
|
|
2935
2934
|
* @param reject 抛出错误
|
|
2936
2935
|
* @param argsResult 返回的参数列表
|
|
2937
2936
|
*/
|
|
2938
|
-
async
|
|
2937
|
+
async onTimeout(details, resolve, reject, argsResult) {
|
|
2939
2938
|
// console.log(argsResult);
|
|
2940
|
-
if ("
|
|
2941
|
-
|
|
2939
|
+
if (typeof details?.ontimeout === "function") {
|
|
2940
|
+
// 执行配置中的ontime回调
|
|
2941
|
+
details.ontimeout.apply(this, argsResult);
|
|
2942
2942
|
}
|
|
2943
|
-
else if (
|
|
2944
|
-
|
|
2943
|
+
else if (typeof this.context.#defaultRequestOption?.ontimeout === "function") {
|
|
2944
|
+
// 执行默认配置的ontime回调
|
|
2945
|
+
this.context.#defaultRequestOption.ontimeout.apply(this, argsResult);
|
|
2945
2946
|
}
|
|
2947
|
+
// 获取响应结果
|
|
2946
2948
|
let response = argsResult;
|
|
2947
2949
|
if (response.length) {
|
|
2948
2950
|
response = response[0];
|
|
2949
2951
|
}
|
|
2952
|
+
// 执行错误回调的钩子
|
|
2950
2953
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2951
|
-
type: "
|
|
2952
|
-
error: new
|
|
2954
|
+
type: "ontimeout",
|
|
2955
|
+
error: new Error("request timeout"),
|
|
2953
2956
|
response: response,
|
|
2954
2957
|
details: details,
|
|
2955
2958
|
})) == null) {
|
|
2956
|
-
// reject(new
|
|
2959
|
+
// reject(new Error("response is intercept with ontimeout"));
|
|
2957
2960
|
return;
|
|
2958
2961
|
}
|
|
2959
2962
|
resolve({
|
|
2960
2963
|
data: response,
|
|
2961
2964
|
details: details,
|
|
2962
|
-
msg: "
|
|
2965
|
+
msg: "请求超时",
|
|
2963
2966
|
status: false,
|
|
2964
|
-
statusCode:
|
|
2965
|
-
type: "
|
|
2967
|
+
statusCode: 0,
|
|
2968
|
+
type: "ontimeout",
|
|
2966
2969
|
});
|
|
2967
2970
|
},
|
|
2968
2971
|
/**
|
|
2969
|
-
*
|
|
2972
|
+
* onerror请求异常-触发
|
|
2970
2973
|
* @param details 配置
|
|
2971
2974
|
* @param resolve 回调
|
|
2972
2975
|
* @param reject 抛出错误
|
|
2973
2976
|
* @param argsResult 返回的参数列表
|
|
2974
2977
|
*/
|
|
2975
|
-
async
|
|
2978
|
+
async onError(details, resolve, reject, argsResult) {
|
|
2976
2979
|
// console.log(argsResult);
|
|
2977
|
-
if ("
|
|
2978
|
-
details.
|
|
2980
|
+
if (typeof details?.onerror === "function") {
|
|
2981
|
+
details.onerror.apply(this, argsResult);
|
|
2979
2982
|
}
|
|
2980
|
-
else if (
|
|
2981
|
-
this.context.#defaultRequestOption.
|
|
2983
|
+
else if (typeof this.context.#defaultRequestOption?.onerror === "function") {
|
|
2984
|
+
this.context.#defaultRequestOption.onerror.apply(this, argsResult);
|
|
2982
2985
|
}
|
|
2983
2986
|
let response = argsResult;
|
|
2984
2987
|
if (response.length) {
|
|
2985
2988
|
response = response[0];
|
|
2986
2989
|
}
|
|
2987
2990
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2988
|
-
type: "
|
|
2989
|
-
error: new
|
|
2990
|
-
response:
|
|
2991
|
+
type: "onerror",
|
|
2992
|
+
error: new Error("request error"),
|
|
2993
|
+
response: response,
|
|
2991
2994
|
details: details,
|
|
2992
2995
|
})) == null) {
|
|
2993
|
-
// reject(new
|
|
2996
|
+
// reject(new Error("response is intercept with onerror"));
|
|
2994
2997
|
return;
|
|
2995
2998
|
}
|
|
2996
2999
|
resolve({
|
|
2997
3000
|
data: response,
|
|
2998
3001
|
details: details,
|
|
2999
|
-
msg: "
|
|
3002
|
+
msg: "请求异常",
|
|
3000
3003
|
status: false,
|
|
3001
|
-
statusCode:
|
|
3002
|
-
type: "
|
|
3004
|
+
statusCode: response["status"],
|
|
3005
|
+
type: "onerror",
|
|
3003
3006
|
});
|
|
3004
3007
|
},
|
|
3005
|
-
/**
|
|
3006
|
-
* onloadstart请求开始-触发
|
|
3007
|
-
* @param details 配置
|
|
3008
|
-
* @param argsResult 返回的参数列表
|
|
3009
|
-
*/
|
|
3010
|
-
onLoadStart(details, argsResult) {
|
|
3011
|
-
// console.log(argsResult);
|
|
3012
|
-
if ("onloadstart" in details) {
|
|
3013
|
-
details.onloadstart.apply(this, argsResult);
|
|
3014
|
-
}
|
|
3015
|
-
else if ("onloadstart" in this.context.#defaultRequestOption) {
|
|
3016
|
-
this.context.#defaultRequestOption.onloadstart.apply(this, argsResult);
|
|
3017
|
-
}
|
|
3018
|
-
},
|
|
3019
3008
|
/**
|
|
3020
3009
|
* onload加载完毕-触发
|
|
3021
3010
|
* @param details 请求的配置
|
|
@@ -3095,7 +3084,7 @@ class Httpx {
|
|
|
3095
3084
|
/* 状态码2xx都是成功的 */
|
|
3096
3085
|
if (Math.floor(originResponse.status / 100) === 2) {
|
|
3097
3086
|
if ((await this.context.HttpxResponseHook.successResponseCallBack(originResponse, details)) == null) {
|
|
3098
|
-
// reject(new
|
|
3087
|
+
// reject(new Error("response is intercept with onloada"));
|
|
3099
3088
|
return;
|
|
3100
3089
|
}
|
|
3101
3090
|
resolve({
|
|
@@ -3108,21 +3097,21 @@ class Httpx {
|
|
|
3108
3097
|
});
|
|
3109
3098
|
}
|
|
3110
3099
|
else {
|
|
3111
|
-
this.context.
|
|
3100
|
+
this.context.HttpxResponseCallBack.onError(details, resolve, reject, argsResult);
|
|
3112
3101
|
}
|
|
3113
3102
|
},
|
|
3114
3103
|
/**
|
|
3115
|
-
*
|
|
3104
|
+
* onloadstart请求开始-触发
|
|
3116
3105
|
* @param details 配置
|
|
3117
3106
|
* @param argsResult 返回的参数列表
|
|
3118
3107
|
*/
|
|
3119
|
-
|
|
3108
|
+
onLoadStart(details, argsResult) {
|
|
3120
3109
|
// console.log(argsResult);
|
|
3121
|
-
if ("
|
|
3122
|
-
details.
|
|
3110
|
+
if (typeof details?.onloadstart === "function") {
|
|
3111
|
+
details.onloadstart.apply(this, argsResult);
|
|
3123
3112
|
}
|
|
3124
|
-
else if (
|
|
3125
|
-
this.context.#defaultRequestOption.
|
|
3113
|
+
else if (typeof this.context.#defaultRequestOption?.onloadstart === "function") {
|
|
3114
|
+
this.context.#defaultRequestOption.onloadstart.apply(this, argsResult);
|
|
3126
3115
|
}
|
|
3127
3116
|
},
|
|
3128
3117
|
/**
|
|
@@ -3132,13 +3121,28 @@ class Httpx {
|
|
|
3132
3121
|
*/
|
|
3133
3122
|
onReadyStateChange(details, argsResult) {
|
|
3134
3123
|
// console.log(argsResult);
|
|
3135
|
-
if (
|
|
3124
|
+
if (typeof details?.onreadystatechange === "function") {
|
|
3136
3125
|
details.onreadystatechange.apply(this, argsResult);
|
|
3137
3126
|
}
|
|
3138
|
-
else if (
|
|
3127
|
+
else if (typeof this.context.#defaultRequestOption?.onreadystatechange ===
|
|
3128
|
+
"function") {
|
|
3139
3129
|
this.context.#defaultRequestOption.onreadystatechange.apply(this, argsResult);
|
|
3140
3130
|
}
|
|
3141
3131
|
},
|
|
3132
|
+
/**
|
|
3133
|
+
* onprogress上传进度-触发
|
|
3134
|
+
* @param details 配置
|
|
3135
|
+
* @param argsResult 返回的参数列表
|
|
3136
|
+
*/
|
|
3137
|
+
onProgress(details, argsResult) {
|
|
3138
|
+
// console.log(argsResult);
|
|
3139
|
+
if (typeof details?.onprogress === "function") {
|
|
3140
|
+
details.onprogress.apply(this, argsResult);
|
|
3141
|
+
}
|
|
3142
|
+
else if (typeof this.context.#defaultRequestOption?.onprogress === "function") {
|
|
3143
|
+
this.context.#defaultRequestOption.onprogress.apply(this, argsResult);
|
|
3144
|
+
}
|
|
3145
|
+
},
|
|
3142
3146
|
};
|
|
3143
3147
|
HttpxRequest = {
|
|
3144
3148
|
context: this,
|
|
@@ -3188,15 +3192,12 @@ class Httpx {
|
|
|
3188
3192
|
isFetch: true,
|
|
3189
3193
|
finalUrl: fetchResponse.url,
|
|
3190
3194
|
readyState: 4,
|
|
3191
|
-
// @ts-ignore
|
|
3192
3195
|
status: fetchResponse.status,
|
|
3193
3196
|
statusText: fetchResponse.statusText,
|
|
3194
|
-
|
|
3195
|
-
response: void 0,
|
|
3197
|
+
response: "",
|
|
3196
3198
|
responseFetchHeaders: fetchResponse.headers,
|
|
3197
3199
|
responseHeaders: "",
|
|
3198
|
-
|
|
3199
|
-
responseText: void 0,
|
|
3200
|
+
responseText: "",
|
|
3200
3201
|
responseType: option.responseType,
|
|
3201
3202
|
responseXML: void 0,
|
|
3202
3203
|
};
|
|
@@ -3269,9 +3270,9 @@ class Httpx {
|
|
|
3269
3270
|
// 转为XML结构
|
|
3270
3271
|
let parser = new DOMParser();
|
|
3271
3272
|
responseXML = parser.parseFromString(responseText, "text/xml");
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3273
|
+
httpxResponse.response = response;
|
|
3274
|
+
httpxResponse.responseText = responseText;
|
|
3275
|
+
httpxResponse.responseXML = responseXML;
|
|
3275
3276
|
// 执行回调
|
|
3276
3277
|
option.onload(httpxResponse);
|
|
3277
3278
|
})
|
|
@@ -3452,7 +3453,7 @@ class Httpx {
|
|
|
3452
3453
|
}
|
|
3453
3454
|
/**
|
|
3454
3455
|
* GET 请求
|
|
3455
|
-
* @param url
|
|
3456
|
+
* @param url 请求的url
|
|
3456
3457
|
* @param details 配置
|
|
3457
3458
|
*/
|
|
3458
3459
|
get(...args) {
|
|
@@ -3518,27 +3519,22 @@ class Httpx {
|
|
|
3518
3519
|
/** 取消请求 */
|
|
3519
3520
|
let abortFn = null;
|
|
3520
3521
|
let promise = new globalThis.Promise(async (resolve, reject) => {
|
|
3521
|
-
let requestOption = this.HttpxRequestOption.getRequestOption(useRequestOption.method, useRequestOption, resolve, reject);
|
|
3522
|
+
let requestOption = (this.HttpxRequestOption.getRequestOption(useRequestOption.method, useRequestOption, resolve, reject));
|
|
3522
3523
|
if (typeof beforeRequestOption === "function") {
|
|
3523
|
-
// @ts-ignore
|
|
3524
3524
|
beforeRequestOption(requestOption);
|
|
3525
3525
|
}
|
|
3526
|
-
|
|
3527
|
-
requestOption =
|
|
3528
|
-
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
3526
|
+
requestOption = this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
3529
3527
|
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
3530
3528
|
if (requestResult != null &&
|
|
3531
3529
|
typeof requestResult.abort === "function") {
|
|
3532
3530
|
abortFn = requestResult.abort;
|
|
3533
3531
|
}
|
|
3534
3532
|
});
|
|
3535
|
-
// @ts-ignore
|
|
3536
3533
|
promise.abort = () => {
|
|
3537
3534
|
if (typeof abortFn === "function") {
|
|
3538
3535
|
abortFn();
|
|
3539
3536
|
}
|
|
3540
3537
|
};
|
|
3541
|
-
// @ts-ignore
|
|
3542
3538
|
return promise;
|
|
3543
3539
|
}
|
|
3544
3540
|
}
|
|
@@ -3548,8 +3544,7 @@ class indexedDB {
|
|
|
3548
3544
|
#storeName;
|
|
3549
3545
|
#dbVersion;
|
|
3550
3546
|
/* websql的版本号,由于ios的问题,版本号的写法不一样 */
|
|
3551
|
-
//
|
|
3552
|
-
#slqVersion = "1";
|
|
3547
|
+
// #slqVersion = "1";
|
|
3553
3548
|
/* 监听IndexDB */
|
|
3554
3549
|
#indexedDB = window.indexedDB ||
|
|
3555
3550
|
window.mozIndexedDB ||
|
|
@@ -3557,8 +3552,7 @@ class indexedDB {
|
|
|
3557
3552
|
window.msIndexedDB;
|
|
3558
3553
|
/* 缓存数据库,避免同一个页面重复创建和销毁 */
|
|
3559
3554
|
#db = {};
|
|
3560
|
-
//
|
|
3561
|
-
#store = null;
|
|
3555
|
+
// #store: IDBObjectStore = null as any;
|
|
3562
3556
|
/** 状态码 */
|
|
3563
3557
|
#statusCode = {
|
|
3564
3558
|
operationSuccess: {
|
|
@@ -3603,7 +3597,7 @@ class indexedDB {
|
|
|
3603
3597
|
txn = this.#db[dbName].transaction(this.#storeName, "readwrite");
|
|
3604
3598
|
/* IndexDB的读写权限 */
|
|
3605
3599
|
store = txn.objectStore(this.#storeName);
|
|
3606
|
-
this.#store = store;
|
|
3600
|
+
// this.#store = store;
|
|
3607
3601
|
return store;
|
|
3608
3602
|
}
|
|
3609
3603
|
/**
|
|
@@ -4328,12 +4322,40 @@ class Progress {
|
|
|
4328
4322
|
}
|
|
4329
4323
|
|
|
4330
4324
|
class UtilsDictionary {
|
|
4331
|
-
items
|
|
4325
|
+
items;
|
|
4332
4326
|
constructor(key, value) {
|
|
4327
|
+
this.items = {};
|
|
4333
4328
|
if (key != null) {
|
|
4334
4329
|
this.set(key, value);
|
|
4335
4330
|
}
|
|
4336
4331
|
}
|
|
4332
|
+
/**
|
|
4333
|
+
* 获取字典的长度,同this.size
|
|
4334
|
+
*/
|
|
4335
|
+
get length() {
|
|
4336
|
+
return this.size();
|
|
4337
|
+
}
|
|
4338
|
+
/**
|
|
4339
|
+
* 迭代器
|
|
4340
|
+
*/
|
|
4341
|
+
get entries() {
|
|
4342
|
+
let that = this;
|
|
4343
|
+
return function* () {
|
|
4344
|
+
let itemKeys = Object.keys(that.getItems());
|
|
4345
|
+
for (const keyName of itemKeys) {
|
|
4346
|
+
yield [keyName, that.get(keyName)];
|
|
4347
|
+
}
|
|
4348
|
+
};
|
|
4349
|
+
}
|
|
4350
|
+
/**
|
|
4351
|
+
* 是否可遍历
|
|
4352
|
+
*/
|
|
4353
|
+
get [Symbol.iterator]() {
|
|
4354
|
+
let that = this;
|
|
4355
|
+
return function () {
|
|
4356
|
+
return that.entries();
|
|
4357
|
+
};
|
|
4358
|
+
}
|
|
4337
4359
|
/**
|
|
4338
4360
|
* 检查是否有某一个键
|
|
4339
4361
|
* @param key 键
|
|
@@ -4434,7 +4456,6 @@ class UtilsDictionary {
|
|
|
4434
4456
|
* 返回字典本身
|
|
4435
4457
|
*/
|
|
4436
4458
|
getItems() {
|
|
4437
|
-
// @ts-ignore
|
|
4438
4459
|
return this.items;
|
|
4439
4460
|
}
|
|
4440
4461
|
/**
|
|
@@ -4444,38 +4465,15 @@ class UtilsDictionary {
|
|
|
4444
4465
|
concat(data) {
|
|
4445
4466
|
this.items = commonUtil.assign(this.items, data.getItems());
|
|
4446
4467
|
}
|
|
4468
|
+
/**
|
|
4469
|
+
* 迭代字典
|
|
4470
|
+
* @param callbackfn 回调函数
|
|
4471
|
+
*/
|
|
4447
4472
|
forEach(callbackfn) {
|
|
4448
4473
|
for (const key in this.getItems()) {
|
|
4449
4474
|
callbackfn(this.get(key), key, this.getItems());
|
|
4450
4475
|
}
|
|
4451
4476
|
}
|
|
4452
|
-
/**
|
|
4453
|
-
* 获取字典的长度,同this.size
|
|
4454
|
-
*/
|
|
4455
|
-
get length() {
|
|
4456
|
-
return this.size();
|
|
4457
|
-
}
|
|
4458
|
-
/**
|
|
4459
|
-
* 迭代器
|
|
4460
|
-
*/
|
|
4461
|
-
get entries() {
|
|
4462
|
-
let that = this;
|
|
4463
|
-
return function* () {
|
|
4464
|
-
let itemKeys = Object.keys(that.getItems());
|
|
4465
|
-
for (const keyName of itemKeys) {
|
|
4466
|
-
yield [keyName, that.get(keyName)];
|
|
4467
|
-
}
|
|
4468
|
-
};
|
|
4469
|
-
}
|
|
4470
|
-
/**
|
|
4471
|
-
* 是否可遍历
|
|
4472
|
-
*/
|
|
4473
|
-
get [Symbol.iterator]() {
|
|
4474
|
-
let that = this;
|
|
4475
|
-
return function () {
|
|
4476
|
-
return that.entries();
|
|
4477
|
-
};
|
|
4478
|
-
}
|
|
4479
4477
|
}
|
|
4480
4478
|
|
|
4481
4479
|
class WindowApi {
|
|
@@ -4501,7 +4499,6 @@ class WindowApi {
|
|
|
4501
4499
|
if (!option) {
|
|
4502
4500
|
option = Object.assign({}, this.defaultApi);
|
|
4503
4501
|
}
|
|
4504
|
-
// @ts-ignore
|
|
4505
4502
|
this.api = Object.assign({}, option);
|
|
4506
4503
|
}
|
|
4507
4504
|
get document() {
|
|
@@ -4559,11 +4556,10 @@ class ReactiveEffect {
|
|
|
4559
4556
|
deps = [];
|
|
4560
4557
|
active = true;
|
|
4561
4558
|
fn;
|
|
4562
|
-
//
|
|
4563
|
-
scheduler;
|
|
4559
|
+
// private scheduler;
|
|
4564
4560
|
constructor(fn, scheduler) {
|
|
4565
4561
|
this.fn = fn;
|
|
4566
|
-
this.scheduler = scheduler;
|
|
4562
|
+
// this.scheduler = scheduler;
|
|
4567
4563
|
}
|
|
4568
4564
|
run(cb) {
|
|
4569
4565
|
if (!this.active) {
|
|
@@ -4630,8 +4626,7 @@ class Vue {
|
|
|
4630
4626
|
reactive(target) {
|
|
4631
4627
|
const that = this;
|
|
4632
4628
|
if (!(typeof target === "object" && target !== null)) {
|
|
4633
|
-
|
|
4634
|
-
return;
|
|
4629
|
+
return void 0;
|
|
4635
4630
|
}
|
|
4636
4631
|
if (VueUtils.isReactive(target)) {
|
|
4637
4632
|
return target;
|
|
@@ -4701,7 +4696,6 @@ class Vue {
|
|
|
4701
4696
|
toRefs(object) {
|
|
4702
4697
|
const result = VueUtils.isArray(object) ? new Array(object.length) : {};
|
|
4703
4698
|
for (let key in object) {
|
|
4704
|
-
// @ts-ignore
|
|
4705
4699
|
result[key] = this.toRef(object, key);
|
|
4706
4700
|
}
|
|
4707
4701
|
return result;
|
|
@@ -4997,7 +4991,7 @@ const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
|
4997
4991
|
};
|
|
4998
4992
|
|
|
4999
4993
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
5000
|
-
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),
|
|
4994
|
+
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
|
|
5001
4995
|
|
|
5002
4996
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
5003
4997
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -5429,7 +5423,6 @@ class DOMUtils {
|
|
|
5429
5423
|
let text = textMatch[2];
|
|
5430
5424
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5431
5425
|
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5432
|
-
// @ts-ignore
|
|
5433
5426
|
return ($ele?.textContent || $ele?.innerText)?.includes(text);
|
|
5434
5427
|
});
|
|
5435
5428
|
}
|
|
@@ -5447,7 +5440,6 @@ class DOMUtils {
|
|
|
5447
5440
|
let regexp = new RegExp(pattern, flags);
|
|
5448
5441
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5449
5442
|
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5450
|
-
// @ts-ignore
|
|
5451
5443
|
return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
|
|
5452
5444
|
});
|
|
5453
5445
|
}
|
|
@@ -5493,7 +5485,6 @@ class DOMUtils {
|
|
|
5493
5485
|
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
5494
5486
|
let text = textMatch[2];
|
|
5495
5487
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5496
|
-
// @ts-ignore
|
|
5497
5488
|
let content = $el?.textContent || $el?.innerText;
|
|
5498
5489
|
if (typeof content !== "string") {
|
|
5499
5490
|
content = "";
|
|
@@ -5513,7 +5504,6 @@ class DOMUtils {
|
|
|
5513
5504
|
}
|
|
5514
5505
|
let regexp = new RegExp(pattern, flags);
|
|
5515
5506
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5516
|
-
// @ts-ignore
|
|
5517
5507
|
let content = $el?.textContent || $el?.innerText;
|
|
5518
5508
|
if (typeof content !== "string") {
|
|
5519
5509
|
content = "";
|
|
@@ -5544,7 +5534,6 @@ class DOMUtils {
|
|
|
5544
5534
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5545
5535
|
let $closest = $el?.closest(selector);
|
|
5546
5536
|
if ($closest) {
|
|
5547
|
-
// @ts-ignore
|
|
5548
5537
|
let content = $el?.textContent || $el?.innerText;
|
|
5549
5538
|
if (typeof content === "string" && content.includes(text)) {
|
|
5550
5539
|
return $closest;
|
|
@@ -5567,7 +5556,6 @@ class DOMUtils {
|
|
|
5567
5556
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5568
5557
|
let $closest = $el?.closest(selector);
|
|
5569
5558
|
if ($closest) {
|
|
5570
|
-
// @ts-ignore
|
|
5571
5559
|
let content = $el?.textContent || $el?.innerText;
|
|
5572
5560
|
if (typeof content === "string" && content.match(regexp)) {
|
|
5573
5561
|
return $closest;
|
|
@@ -5590,7 +5578,7 @@ class Utils {
|
|
|
5590
5578
|
this.windowApi = new WindowApi(option);
|
|
5591
5579
|
}
|
|
5592
5580
|
/** 版本号 */
|
|
5593
|
-
version = "2025.
|
|
5581
|
+
version = "2025.7.29";
|
|
5594
5582
|
addStyle(cssText) {
|
|
5595
5583
|
if (typeof cssText !== "string") {
|
|
5596
5584
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5674,7 +5662,7 @@ class Utils {
|
|
|
5674
5662
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
5675
5663
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
5676
5664
|
* + 作者:cxxjackie
|
|
5677
|
-
* + 版本:1.4.
|
|
5665
|
+
* + 版本:1.4.7
|
|
5678
5666
|
* + 旧版本:1.2.4
|
|
5679
5667
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5680
5668
|
* @param useOldVersion 是否使用旧版本,默认false
|
|
@@ -5687,7 +5675,7 @@ class Utils {
|
|
|
5687
5675
|
return ajaxHooker();
|
|
5688
5676
|
}
|
|
5689
5677
|
};
|
|
5690
|
-
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view =
|
|
5678
|
+
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = this.windowApi.window) {
|
|
5691
5679
|
if (!(canvasElement instanceof HTMLCanvasElement)) {
|
|
5692
5680
|
throw new Error("Utils.canvasClickByPosition 参数canvasElement必须是canvas元素");
|
|
5693
5681
|
}
|
|
@@ -5698,7 +5686,6 @@ class Utils {
|
|
|
5698
5686
|
cancelable: true,
|
|
5699
5687
|
clientX: clientX,
|
|
5700
5688
|
clientY: clientY,
|
|
5701
|
-
// @ts-ignore
|
|
5702
5689
|
view: view,
|
|
5703
5690
|
detail: 1,
|
|
5704
5691
|
};
|
|
@@ -6205,12 +6192,10 @@ class Utils {
|
|
|
6205
6192
|
}
|
|
6206
6193
|
getElementSelector(element) {
|
|
6207
6194
|
let UtilsContext = this;
|
|
6208
|
-
// @ts-ignore
|
|
6209
6195
|
if (!element)
|
|
6210
|
-
return;
|
|
6211
|
-
// @ts-ignore
|
|
6196
|
+
return void 0;
|
|
6212
6197
|
if (!element.parentElement)
|
|
6213
|
-
return;
|
|
6198
|
+
return void 0;
|
|
6214
6199
|
/* 如果元素有id属性,则直接返回id选择器 */
|
|
6215
6200
|
if (element.id)
|
|
6216
6201
|
return "#" + element.id;
|
|
@@ -6241,8 +6226,7 @@ class Utils {
|
|
|
6241
6226
|
let result = [...args];
|
|
6242
6227
|
let newResult = [];
|
|
6243
6228
|
if (result.length === 0) {
|
|
6244
|
-
|
|
6245
|
-
return;
|
|
6229
|
+
return void 0;
|
|
6246
6230
|
}
|
|
6247
6231
|
if (result.length > 1) {
|
|
6248
6232
|
if (result.length === 2 &&
|
|
@@ -6282,7 +6266,6 @@ class Utils {
|
|
|
6282
6266
|
// 当前页面最大的z-index
|
|
6283
6267
|
let zIndex = 0;
|
|
6284
6268
|
// 当前的最大z-index的元素,调试使用
|
|
6285
|
-
// @ts-ignore
|
|
6286
6269
|
let maxZIndexNode = null;
|
|
6287
6270
|
/**
|
|
6288
6271
|
* 元素是否可见
|
|
@@ -6343,8 +6326,7 @@ class Utils {
|
|
|
6343
6326
|
let result = [...args];
|
|
6344
6327
|
let newResult = [];
|
|
6345
6328
|
if (result.length === 0) {
|
|
6346
|
-
|
|
6347
|
-
return;
|
|
6329
|
+
return void 0;
|
|
6348
6330
|
}
|
|
6349
6331
|
if (result.length > 1) {
|
|
6350
6332
|
if (result.length === 2 &&
|
|
@@ -6818,7 +6800,6 @@ class Utils {
|
|
|
6818
6800
|
}
|
|
6819
6801
|
isJQuery(target) {
|
|
6820
6802
|
let result = false;
|
|
6821
|
-
// @ts-ignore
|
|
6822
6803
|
if (typeof jQuery === "object" && target instanceof jQuery) {
|
|
6823
6804
|
result = true;
|
|
6824
6805
|
}
|
|
@@ -7599,29 +7580,27 @@ class Utils {
|
|
|
7599
7580
|
EventTarget.prototype.addEventListener = function (...args) {
|
|
7600
7581
|
let type = args[0];
|
|
7601
7582
|
let callback = args[1];
|
|
7602
|
-
//
|
|
7603
|
-
args[2];
|
|
7583
|
+
// let options = args[2];
|
|
7604
7584
|
if (filter(type)) {
|
|
7605
7585
|
if (typeof callback === "function") {
|
|
7606
7586
|
args[1] = function (event) {
|
|
7607
7587
|
callback.call(this, trustEvent(event));
|
|
7608
7588
|
};
|
|
7609
7589
|
}
|
|
7610
|
-
else if (typeof callback === "object" &&
|
|
7611
|
-
"handleEvent" in callback) {
|
|
7590
|
+
else if (typeof callback === "object" && "handleEvent" in callback) {
|
|
7612
7591
|
let oldHandleEvent = callback["handleEvent"];
|
|
7613
7592
|
args[1]["handleEvent"] = function (event) {
|
|
7614
7593
|
if (event == null) {
|
|
7615
7594
|
return;
|
|
7616
7595
|
}
|
|
7617
7596
|
try {
|
|
7618
|
-
|
|
7597
|
+
// Proxy对象使用instanceof会报错
|
|
7598
|
+
// 这里故意尝试一下,如果报错,则说明是Proxy对象
|
|
7619
7599
|
event instanceof Proxy;
|
|
7620
7600
|
oldHandleEvent.call(this, trustEvent(event));
|
|
7621
7601
|
}
|
|
7622
7602
|
catch (error) {
|
|
7623
|
-
|
|
7624
|
-
event["isTrusted"] = isTrustValue;
|
|
7603
|
+
Reflect.set(event, "isTrusted", isTrustValue);
|
|
7625
7604
|
}
|
|
7626
7605
|
};
|
|
7627
7606
|
}
|
|
@@ -7694,8 +7673,8 @@ class Utils {
|
|
|
7694
7673
|
}
|
|
7695
7674
|
async init() {
|
|
7696
7675
|
let copyStatus = false;
|
|
7697
|
-
|
|
7698
|
-
|
|
7676
|
+
let requestPermissionStatus = await this.requestClipboardPermission();
|
|
7677
|
+
console.log(requestPermissionStatus);
|
|
7699
7678
|
if (this.hasClipboard() &&
|
|
7700
7679
|
(this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
7701
7680
|
try {
|
|
@@ -7713,11 +7692,8 @@ class Utils {
|
|
|
7713
7692
|
this.destroy();
|
|
7714
7693
|
}
|
|
7715
7694
|
destroy() {
|
|
7716
|
-
// @ts-ignore
|
|
7717
7695
|
this.#resolve = null;
|
|
7718
|
-
// @ts-ignore
|
|
7719
7696
|
this.#copyData = null;
|
|
7720
|
-
// @ts-ignore
|
|
7721
7697
|
this.#copyDataType = null;
|
|
7722
7698
|
}
|
|
7723
7699
|
isText() {
|
|
@@ -7761,7 +7737,6 @@ class Utils {
|
|
|
7761
7737
|
if (navigator.permissions && navigator.permissions.query) {
|
|
7762
7738
|
navigator.permissions
|
|
7763
7739
|
.query({
|
|
7764
|
-
// @ts-ignore
|
|
7765
7740
|
name: "clipboard-write",
|
|
7766
7741
|
})
|
|
7767
7742
|
.then((permissionStatus) => {
|
|
@@ -7857,7 +7832,6 @@ class Utils {
|
|
|
7857
7832
|
dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
|
|
7858
7833
|
let UtilsContext = this;
|
|
7859
7834
|
function initMouseEvent(eventName, offSetX, offSetY) {
|
|
7860
|
-
// @ts-ignore
|
|
7861
7835
|
let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
|
|
7862
7836
|
let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
7863
7837
|
mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
|
|
@@ -8016,7 +7990,6 @@ class Utils {
|
|
|
8016
7990
|
}
|
|
8017
7991
|
stringToRegular(targetString, flags = "ig") {
|
|
8018
7992
|
let reg;
|
|
8019
|
-
// @ts-ignore
|
|
8020
7993
|
flags = flags.toLowerCase();
|
|
8021
7994
|
if (typeof targetString === "string") {
|
|
8022
7995
|
reg = new RegExp(targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"), flags);
|
|
@@ -8109,10 +8082,8 @@ class Utils {
|
|
|
8109
8082
|
*/
|
|
8110
8083
|
searchParamStrToObj(searhParamsStr) {
|
|
8111
8084
|
if (typeof searhParamsStr !== "string") {
|
|
8112
|
-
// @ts-ignore
|
|
8113
8085
|
return {};
|
|
8114
8086
|
}
|
|
8115
|
-
// @ts-ignore
|
|
8116
8087
|
return Object.fromEntries(new URLSearchParams(searhParamsStr));
|
|
8117
8088
|
}
|
|
8118
8089
|
/**
|
|
@@ -8815,7 +8786,6 @@ class Utils {
|
|
|
8815
8786
|
function requestPermissionsWithClipboard() {
|
|
8816
8787
|
navigator.permissions
|
|
8817
8788
|
.query({
|
|
8818
|
-
// @ts-ignore
|
|
8819
8789
|
name: "clipboard-read",
|
|
8820
8790
|
})
|
|
8821
8791
|
.then((permissionStatus) => {
|