@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.system.js
CHANGED
|
@@ -20,14 +20,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
20
20
|
/**
|
|
21
21
|
* 16进制颜色转rgba
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* 例如:`#ff0000` 转为 `rgba(123,123,123, 0.4)`
|
|
24
24
|
* @param hex
|
|
25
25
|
* @param opacity
|
|
26
26
|
*/
|
|
27
27
|
hexToRgba(hex, opacity) {
|
|
28
28
|
if (!this.isHex(hex)) {
|
|
29
|
-
|
|
30
|
-
throw new TypeError("输入错误的hex", hex);
|
|
29
|
+
throw new TypeError("输入错误的hex:" + hex);
|
|
31
30
|
}
|
|
32
31
|
return hex && hex.replace(/\s+/g, "").length === 7
|
|
33
32
|
? "rgba(" +
|
|
@@ -44,19 +43,16 @@ System.register('Utils', [], (function (exports) {
|
|
|
44
43
|
/**
|
|
45
44
|
* hex转rgb
|
|
46
45
|
* @param str
|
|
47
|
-
* @returns
|
|
48
46
|
*/
|
|
49
47
|
hexToRgb(str) {
|
|
50
48
|
if (!this.isHex(str)) {
|
|
51
|
-
|
|
52
|
-
throw new TypeError("输入错误的hex", str);
|
|
49
|
+
throw new TypeError("输入错误的hex:" + str);
|
|
53
50
|
}
|
|
54
51
|
/* replace替换查找的到的字符串 */
|
|
55
52
|
str = str.replace("#", "");
|
|
56
53
|
/* match得到查询数组 */
|
|
57
54
|
let hxs = str.match(/../g);
|
|
58
55
|
for (let index = 0; index < 3; index++) {
|
|
59
|
-
// @ts-ignore
|
|
60
56
|
hxs[index] = parseInt(hxs[index], 16);
|
|
61
57
|
}
|
|
62
58
|
return hxs;
|
|
@@ -66,7 +62,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
66
62
|
* @param redValue
|
|
67
63
|
* @param greenValue
|
|
68
64
|
* @param blueValue
|
|
69
|
-
* @returns
|
|
70
65
|
*/
|
|
71
66
|
rgbToHex(redValue, greenValue, blueValue) {
|
|
72
67
|
/* 验证输入的rgb值是否合法 */
|
|
@@ -89,38 +84,30 @@ System.register('Utils', [], (function (exports) {
|
|
|
89
84
|
* 获取颜色变暗或亮
|
|
90
85
|
* @param color 颜色
|
|
91
86
|
* @param level 0~1.0
|
|
92
|
-
* @returns
|
|
93
87
|
*/
|
|
94
88
|
getDarkColor(color, level) {
|
|
95
89
|
if (!this.isHex(color)) {
|
|
96
|
-
|
|
97
|
-
throw new TypeError("输入错误的hex", color);
|
|
90
|
+
throw new TypeError("输入错误的hex:" + color);
|
|
98
91
|
}
|
|
99
92
|
let rgbc = this.hexToRgb(color);
|
|
100
93
|
for (let index = 0; index < 3; index++) {
|
|
101
|
-
// @ts-ignore
|
|
102
94
|
rgbc[index] = Math.floor(rgbc[index] * (1 - level));
|
|
103
95
|
}
|
|
104
|
-
// @ts-ignore
|
|
105
96
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
106
97
|
}
|
|
107
98
|
/**
|
|
108
99
|
* 获取颜色变亮
|
|
109
100
|
* @param color 颜色
|
|
110
101
|
* @param level 0~1.0
|
|
111
|
-
* @returns
|
|
112
102
|
*/
|
|
113
103
|
getLightColor(color, level) {
|
|
114
104
|
if (!this.isHex(color)) {
|
|
115
|
-
|
|
116
|
-
throw new TypeError("输入错误的hex", color);
|
|
105
|
+
throw new TypeError("输入错误的hex:" + color);
|
|
117
106
|
}
|
|
118
107
|
let rgbc = this.hexToRgb(color);
|
|
119
108
|
for (let index = 0; index < 3; index++) {
|
|
120
|
-
// @ts-ignore
|
|
121
109
|
rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
|
|
122
110
|
}
|
|
123
|
-
// @ts-ignore
|
|
124
111
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
125
112
|
}
|
|
126
113
|
}
|
|
@@ -208,20 +195,20 @@ System.register('Utils', [], (function (exports) {
|
|
|
208
195
|
* @param str
|
|
209
196
|
*/
|
|
210
197
|
decode(str) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
//
|
|
214
|
-
|
|
215
|
-
|
|
198
|
+
let GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
|
|
199
|
+
let UTFMatcher = /%[0-9A-F]{2}/;
|
|
200
|
+
// let gbk = true;
|
|
201
|
+
let utf = true;
|
|
202
|
+
const that = this;
|
|
216
203
|
while (utf) {
|
|
217
204
|
let gbkMatch = str.match(GBKMatcher);
|
|
218
205
|
let utfMatch = str.match(UTFMatcher);
|
|
206
|
+
// gbk = Boolean(gbkMatch);
|
|
219
207
|
utf = Boolean(utfMatch);
|
|
220
208
|
if (gbkMatch && gbkMatch in that.#G2Uhash) {
|
|
221
209
|
str = str.replace(gbkMatch, String.fromCharCode(("0x" + that.#G2Uhash[gbkMatch])));
|
|
222
210
|
}
|
|
223
211
|
else {
|
|
224
|
-
// @ts-ignore
|
|
225
212
|
str = str.replace(utfMatch, decodeURIComponent(utfMatch));
|
|
226
213
|
}
|
|
227
214
|
}
|
|
@@ -252,7 +239,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
252
239
|
* @param handler
|
|
253
240
|
*/
|
|
254
241
|
error(handler) {
|
|
255
|
-
// @ts-ignore
|
|
256
242
|
handleError = handler;
|
|
257
243
|
return TryCatchCore;
|
|
258
244
|
},
|
|
@@ -267,8 +253,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
267
253
|
callbackFunction = callback;
|
|
268
254
|
context = __context__ || this;
|
|
269
255
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
270
|
-
|
|
271
|
-
|
|
256
|
+
return result !== void 0
|
|
257
|
+
? result
|
|
258
|
+
: TryCatchCore;
|
|
272
259
|
},
|
|
273
260
|
};
|
|
274
261
|
/**
|
|
@@ -751,13 +738,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
751
738
|
// ==UserScript==
|
|
752
739
|
// @name ajaxHooker
|
|
753
740
|
// @author cxxjackie
|
|
754
|
-
// @version 1.4.
|
|
741
|
+
// @version 1.4.7
|
|
755
742
|
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
756
743
|
// @license GNU LGPL-3.0
|
|
757
744
|
// ==/UserScript==
|
|
758
745
|
|
|
759
746
|
const ajaxHooker = function () {
|
|
760
|
-
const version = "1.4.
|
|
747
|
+
const version = "1.4.7";
|
|
761
748
|
const hookInst = {
|
|
762
749
|
hookFns: [],
|
|
763
750
|
filters: [],
|
|
@@ -767,20 +754,18 @@ System.register('Utils', [], (function (exports) {
|
|
|
767
754
|
const resProto = win.Response.prototype;
|
|
768
755
|
const xhrResponses = ["response", "responseText", "responseXML"];
|
|
769
756
|
const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
"headers",
|
|
773
|
-
"body",
|
|
774
|
-
"mode",
|
|
775
|
-
"credentials",
|
|
757
|
+
const xhrExtraProps = ["responseType", "timeout", "withCredentials"];
|
|
758
|
+
const fetchExtraProps = [
|
|
776
759
|
"cache",
|
|
760
|
+
"credentials",
|
|
761
|
+
"integrity",
|
|
762
|
+
"keepalive",
|
|
763
|
+
"mode",
|
|
764
|
+
"priority",
|
|
777
765
|
"redirect",
|
|
778
766
|
"referrer",
|
|
779
767
|
"referrerPolicy",
|
|
780
|
-
"integrity",
|
|
781
|
-
"keepalive",
|
|
782
768
|
"signal",
|
|
783
|
-
"priority",
|
|
784
769
|
];
|
|
785
770
|
const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
|
|
786
771
|
const getType = {}.toString.call.bind({}.toString);
|
|
@@ -858,6 +843,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
858
843
|
this.request = request;
|
|
859
844
|
this.requestClone = { ...this.request };
|
|
860
845
|
}
|
|
846
|
+
_recoverRequestKey(key) {
|
|
847
|
+
if (key in this.requestClone) this.request[key] = this.requestClone[key];
|
|
848
|
+
else delete this.request[key];
|
|
849
|
+
}
|
|
861
850
|
shouldFilter(filters) {
|
|
862
851
|
const { type, url, method, async } = this.request;
|
|
863
852
|
return (
|
|
@@ -878,7 +867,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
878
867
|
);
|
|
879
868
|
}
|
|
880
869
|
waitForRequestKeys() {
|
|
881
|
-
const requestKeys = ["url", "method", "abort", "headers", "data"];
|
|
882
870
|
if (!this.request.async) {
|
|
883
871
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
884
872
|
if (this.shouldFilter(filters)) return;
|
|
@@ -886,27 +874,31 @@ System.register('Utils', [], (function (exports) {
|
|
|
886
874
|
if (getType(fn) === "[object Function]")
|
|
887
875
|
catchError(fn, this.request);
|
|
888
876
|
});
|
|
889
|
-
|
|
890
|
-
if (isThenable(this.request[key]))
|
|
891
|
-
|
|
892
|
-
});
|
|
877
|
+
for (const key in this.request) {
|
|
878
|
+
if (isThenable(this.request[key])) this._recoverRequestKey(key);
|
|
879
|
+
}
|
|
893
880
|
});
|
|
894
881
|
return new SyncThenable();
|
|
895
882
|
}
|
|
896
883
|
const promises = [];
|
|
884
|
+
const ignoreKeys = new Set(["type", "async", "response"]);
|
|
897
885
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
898
886
|
if (this.shouldFilter(filters)) return;
|
|
899
887
|
promises.push(
|
|
900
888
|
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
901
|
-
() =>
|
|
902
|
-
|
|
889
|
+
() => {
|
|
890
|
+
const requestKeys = [];
|
|
891
|
+
for (const key in this.request)
|
|
892
|
+
!ignoreKeys.has(key) && requestKeys.push(key);
|
|
893
|
+
return Promise.all(
|
|
903
894
|
requestKeys.map((key) =>
|
|
904
895
|
Promise.resolve(this.request[key]).then(
|
|
905
896
|
(val) => (this.request[key] = val),
|
|
906
|
-
() =>
|
|
897
|
+
() => this._recoverRequestKey(key)
|
|
907
898
|
)
|
|
908
899
|
)
|
|
909
|
-
)
|
|
900
|
+
);
|
|
901
|
+
}
|
|
910
902
|
)
|
|
911
903
|
);
|
|
912
904
|
});
|
|
@@ -1087,6 +1079,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1087
1079
|
e.stopImmediatePropagation = stopImmediatePropagation;
|
|
1088
1080
|
defineProp(e, "target", () => this.proxyXhr);
|
|
1089
1081
|
defineProp(e, "currentTarget", () => this.proxyXhr);
|
|
1082
|
+
defineProp(e, "srcElement", () => this.proxyXhr);
|
|
1090
1083
|
this.proxyEvents[e.type] &&
|
|
1091
1084
|
this.proxyEvents[e.type].forEach((fn) => {
|
|
1092
1085
|
this.resThenable.then(
|
|
@@ -1164,6 +1157,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
1164
1157
|
for (const header in request.headers) {
|
|
1165
1158
|
xhr.setRequestHeader(header, request.headers[header]);
|
|
1166
1159
|
}
|
|
1160
|
+
for (const prop of xhrExtraProps) {
|
|
1161
|
+
if (prop in request) xhr[prop] = request[prop];
|
|
1162
|
+
}
|
|
1167
1163
|
xhr.send(request.data);
|
|
1168
1164
|
}
|
|
1169
1165
|
});
|
|
@@ -1185,8 +1181,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
1185
1181
|
return new Promise(async (resolve, reject) => {
|
|
1186
1182
|
const init = {};
|
|
1187
1183
|
if (getType(url) === "[object Request]") {
|
|
1188
|
-
|
|
1184
|
+
init.method = url.method;
|
|
1185
|
+
init.headers = url.headers;
|
|
1189
1186
|
if (url.body) init.body = await url.arrayBuffer();
|
|
1187
|
+
for (const prop of fetchExtraProps) init[prop] = url[prop];
|
|
1190
1188
|
url = url.url;
|
|
1191
1189
|
}
|
|
1192
1190
|
url = url.toString();
|
|
@@ -1233,6 +1231,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
1233
1231
|
init.method = request.method;
|
|
1234
1232
|
init.headers = request.headers;
|
|
1235
1233
|
init.body = request.data;
|
|
1234
|
+
for (const prop of fetchExtraProps) {
|
|
1235
|
+
if (prop in request) init[prop] = request[prop];
|
|
1236
|
+
}
|
|
1236
1237
|
winAh.realFetch.call(win, request.url, init).then((res) => {
|
|
1237
1238
|
if (typeof request.response === "function") {
|
|
1238
1239
|
const response = {
|
|
@@ -1938,25 +1939,24 @@ System.register('Utils', [], (function (exports) {
|
|
|
1938
1939
|
let defaultEnable = Boolean(this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable));
|
|
1939
1940
|
/** 油猴菜单上显示的文本 */
|
|
1940
1941
|
let showText = menuOption.showText(menuOption.text, defaultEnable);
|
|
1941
|
-
//
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
});
|
|
1942
|
+
// const GMMenuOptions = {
|
|
1943
|
+
// /**
|
|
1944
|
+
// * 菜单的id
|
|
1945
|
+
// */
|
|
1946
|
+
// id: menuOption.id,
|
|
1947
|
+
// /**
|
|
1948
|
+
// * 点击菜单项后是否应关闭弹出菜单
|
|
1949
|
+
// */
|
|
1950
|
+
// autoClose: menuOption.autoClose,
|
|
1951
|
+
// /**
|
|
1952
|
+
// * 菜单项的可选访问键
|
|
1953
|
+
// */
|
|
1954
|
+
// accessKey: menuOption.accessKey,
|
|
1955
|
+
// /**
|
|
1956
|
+
// * 菜单项的鼠标悬浮上的工具提示
|
|
1957
|
+
// */
|
|
1958
|
+
// title: menuOption.title,
|
|
1959
|
+
// };
|
|
1960
1960
|
/* 点击菜单后触发callback后的网页是否刷新 */
|
|
1961
1961
|
menuOption.autoReload =
|
|
1962
1962
|
typeof menuOption.autoReload !== "boolean"
|
|
@@ -2534,7 +2534,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
2534
2534
|
* 对请求的参数进行合并处理
|
|
2535
2535
|
*/
|
|
2536
2536
|
handleBeforeRequestOptionArgs(...args) {
|
|
2537
|
-
let option = {
|
|
2537
|
+
let option = {
|
|
2538
|
+
url: void 0,
|
|
2539
|
+
};
|
|
2538
2540
|
if (typeof args[0] === "string") {
|
|
2539
2541
|
/* 传入的是url,转为配置 */
|
|
2540
2542
|
let url = args[0];
|
|
@@ -2558,7 +2560,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
2558
2560
|
* @param method 当前请求方法,默认get
|
|
2559
2561
|
* @param userRequestOption 用户的请求配置
|
|
2560
2562
|
* @param resolve promise回调
|
|
2561
|
-
* @param reject 抛出错误回调
|
|
2563
|
+
* @param reject promise抛出错误回调
|
|
2562
2564
|
*/
|
|
2563
2565
|
getRequestOption(method, userRequestOption, resolve, reject) {
|
|
2564
2566
|
let that = this;
|
|
@@ -2616,25 +2618,25 @@ System.register('Utils', [], (function (exports) {
|
|
|
2616
2618
|
password: userRequestOption.password ||
|
|
2617
2619
|
this.context.#defaultRequestOption.password,
|
|
2618
2620
|
onabort(...args) {
|
|
2619
|
-
that.context.
|
|
2621
|
+
that.context.HttpxResponseCallBack.onAbort(userRequestOption, resolve, reject, args);
|
|
2620
2622
|
},
|
|
2621
2623
|
onerror(...args) {
|
|
2622
|
-
that.context.
|
|
2624
|
+
that.context.HttpxResponseCallBack.onError(userRequestOption, resolve, reject, args);
|
|
2623
2625
|
},
|
|
2624
2626
|
onloadstart(...args) {
|
|
2625
|
-
that.context.
|
|
2627
|
+
that.context.HttpxResponseCallBack.onLoadStart(userRequestOption, args);
|
|
2626
2628
|
},
|
|
2627
2629
|
onprogress(...args) {
|
|
2628
|
-
that.context.
|
|
2630
|
+
that.context.HttpxResponseCallBack.onProgress(userRequestOption, args);
|
|
2629
2631
|
},
|
|
2630
2632
|
onreadystatechange(...args) {
|
|
2631
|
-
that.context.
|
|
2633
|
+
that.context.HttpxResponseCallBack.onReadyStateChange(userRequestOption, args);
|
|
2632
2634
|
},
|
|
2633
2635
|
ontimeout(...args) {
|
|
2634
|
-
that.context.
|
|
2636
|
+
that.context.HttpxResponseCallBack.onTimeout(userRequestOption, resolve, reject, args);
|
|
2635
2637
|
},
|
|
2636
2638
|
onload(...args) {
|
|
2637
|
-
that.context.
|
|
2639
|
+
that.context.HttpxResponseCallBack.onLoad(userRequestOption, resolve, reject, args);
|
|
2638
2640
|
},
|
|
2639
2641
|
};
|
|
2640
2642
|
// 补全allowInterceptConfig参数
|
|
@@ -2746,7 +2748,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
2746
2748
|
else if (typeof requestOption.data === "object") {
|
|
2747
2749
|
isHandler = true;
|
|
2748
2750
|
// URLSearchParams参数可以转普通的string:string,包括FormData
|
|
2749
|
-
// @ts-ignore
|
|
2750
2751
|
let searchParams = new URLSearchParams(requestOption.data);
|
|
2751
2752
|
urlSearch = searchParams.toString();
|
|
2752
2753
|
}
|
|
@@ -2801,9 +2802,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
2801
2802
|
else if (ContentType.includes("application/x-www-form-urlencoded")) {
|
|
2802
2803
|
// application/x-www-form-urlencoded
|
|
2803
2804
|
if (typeof requestOption.data === "object") {
|
|
2804
|
-
requestOption.data = new URLSearchParams(
|
|
2805
|
-
// @ts-ignore
|
|
2806
|
-
requestOption.data).toString();
|
|
2805
|
+
requestOption.data = new URLSearchParams(requestOption.data).toString();
|
|
2807
2806
|
}
|
|
2808
2807
|
}
|
|
2809
2808
|
else if (ContentType.includes("multipart/form-data")) {
|
|
@@ -2823,7 +2822,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
2823
2822
|
},
|
|
2824
2823
|
/**
|
|
2825
2824
|
* 处理发送请求的配置,去除值为undefined、空function的值
|
|
2826
|
-
* @param option
|
|
2825
|
+
* @param option 请求配置
|
|
2827
2826
|
*/
|
|
2828
2827
|
removeRequestNullOption(option) {
|
|
2829
2828
|
Object.keys(option).forEach((keyName) => {
|
|
@@ -2835,13 +2834,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
2835
2834
|
}
|
|
2836
2835
|
});
|
|
2837
2836
|
if (commonUtil.isNull(option.url)) {
|
|
2838
|
-
throw new TypeError(`Utils.Httpx 参数
|
|
2837
|
+
throw new TypeError(`Utils.Httpx 参数url不能为空:${option.url}`);
|
|
2839
2838
|
}
|
|
2840
2839
|
return option;
|
|
2841
2840
|
},
|
|
2842
2841
|
/**
|
|
2843
2842
|
* 处理fetch的配置
|
|
2844
|
-
* @param option
|
|
2843
|
+
* @param option 请求配置
|
|
2845
2844
|
*/
|
|
2846
2845
|
handleFetchOption(option) {
|
|
2847
2846
|
/**
|
|
@@ -2894,21 +2893,21 @@ System.register('Utils', [], (function (exports) {
|
|
|
2894
2893
|
};
|
|
2895
2894
|
},
|
|
2896
2895
|
};
|
|
2897
|
-
|
|
2896
|
+
HttpxResponseCallBack = {
|
|
2898
2897
|
context: this,
|
|
2899
2898
|
/**
|
|
2900
2899
|
* onabort请求被取消-触发
|
|
2901
2900
|
* @param details 配置
|
|
2902
|
-
* @param resolve 回调
|
|
2903
|
-
* @param reject
|
|
2901
|
+
* @param resolve promise回调
|
|
2902
|
+
* @param reject promise抛出错误回调
|
|
2904
2903
|
* @param argsResult 返回的参数列表
|
|
2905
2904
|
*/
|
|
2906
2905
|
async onAbort(details, resolve, reject, argsResult) {
|
|
2907
2906
|
// console.log(argsResult);
|
|
2908
|
-
if (
|
|
2907
|
+
if (typeof details?.onabort === "function") {
|
|
2909
2908
|
details.onabort.apply(this, argsResult);
|
|
2910
2909
|
}
|
|
2911
|
-
else if (
|
|
2910
|
+
else if (typeof this.context.#defaultRequestOption?.onabort === "function") {
|
|
2912
2911
|
this.context.#defaultRequestOption.onabort.apply(this, argsResult);
|
|
2913
2912
|
}
|
|
2914
2913
|
let response = argsResult;
|
|
@@ -2917,11 +2916,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
2917
2916
|
}
|
|
2918
2917
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2919
2918
|
type: "onabort",
|
|
2920
|
-
error: new
|
|
2919
|
+
error: new Error("request canceled"),
|
|
2921
2920
|
response: null,
|
|
2922
2921
|
details: details,
|
|
2923
2922
|
})) == null) {
|
|
2924
|
-
// reject(new
|
|
2923
|
+
// reject(new Error("response is intercept with onabort"));
|
|
2925
2924
|
return;
|
|
2926
2925
|
}
|
|
2927
2926
|
resolve({
|
|
@@ -2934,93 +2933,83 @@ System.register('Utils', [], (function (exports) {
|
|
|
2934
2933
|
});
|
|
2935
2934
|
},
|
|
2936
2935
|
/**
|
|
2937
|
-
*
|
|
2936
|
+
* ontimeout请求超时-触发
|
|
2938
2937
|
* @param details 配置
|
|
2939
2938
|
* @param resolve 回调
|
|
2940
2939
|
* @param reject 抛出错误
|
|
2941
2940
|
* @param argsResult 返回的参数列表
|
|
2942
2941
|
*/
|
|
2943
|
-
async
|
|
2942
|
+
async onTimeout(details, resolve, reject, argsResult) {
|
|
2944
2943
|
// console.log(argsResult);
|
|
2945
|
-
if ("
|
|
2946
|
-
|
|
2944
|
+
if (typeof details?.ontimeout === "function") {
|
|
2945
|
+
// 执行配置中的ontime回调
|
|
2946
|
+
details.ontimeout.apply(this, argsResult);
|
|
2947
2947
|
}
|
|
2948
|
-
else if (
|
|
2949
|
-
|
|
2948
|
+
else if (typeof this.context.#defaultRequestOption?.ontimeout === "function") {
|
|
2949
|
+
// 执行默认配置的ontime回调
|
|
2950
|
+
this.context.#defaultRequestOption.ontimeout.apply(this, argsResult);
|
|
2950
2951
|
}
|
|
2952
|
+
// 获取响应结果
|
|
2951
2953
|
let response = argsResult;
|
|
2952
2954
|
if (response.length) {
|
|
2953
2955
|
response = response[0];
|
|
2954
2956
|
}
|
|
2957
|
+
// 执行错误回调的钩子
|
|
2955
2958
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2956
|
-
type: "
|
|
2957
|
-
error: new
|
|
2959
|
+
type: "ontimeout",
|
|
2960
|
+
error: new Error("request timeout"),
|
|
2958
2961
|
response: response,
|
|
2959
2962
|
details: details,
|
|
2960
2963
|
})) == null) {
|
|
2961
|
-
// reject(new
|
|
2964
|
+
// reject(new Error("response is intercept with ontimeout"));
|
|
2962
2965
|
return;
|
|
2963
2966
|
}
|
|
2964
2967
|
resolve({
|
|
2965
2968
|
data: response,
|
|
2966
2969
|
details: details,
|
|
2967
|
-
msg: "
|
|
2970
|
+
msg: "请求超时",
|
|
2968
2971
|
status: false,
|
|
2969
|
-
statusCode:
|
|
2970
|
-
type: "
|
|
2972
|
+
statusCode: 0,
|
|
2973
|
+
type: "ontimeout",
|
|
2971
2974
|
});
|
|
2972
2975
|
},
|
|
2973
2976
|
/**
|
|
2974
|
-
*
|
|
2977
|
+
* onerror请求异常-触发
|
|
2975
2978
|
* @param details 配置
|
|
2976
2979
|
* @param resolve 回调
|
|
2977
2980
|
* @param reject 抛出错误
|
|
2978
2981
|
* @param argsResult 返回的参数列表
|
|
2979
2982
|
*/
|
|
2980
|
-
async
|
|
2983
|
+
async onError(details, resolve, reject, argsResult) {
|
|
2981
2984
|
// console.log(argsResult);
|
|
2982
|
-
if ("
|
|
2983
|
-
details.
|
|
2985
|
+
if (typeof details?.onerror === "function") {
|
|
2986
|
+
details.onerror.apply(this, argsResult);
|
|
2984
2987
|
}
|
|
2985
|
-
else if (
|
|
2986
|
-
this.context.#defaultRequestOption.
|
|
2988
|
+
else if (typeof this.context.#defaultRequestOption?.onerror === "function") {
|
|
2989
|
+
this.context.#defaultRequestOption.onerror.apply(this, argsResult);
|
|
2987
2990
|
}
|
|
2988
2991
|
let response = argsResult;
|
|
2989
2992
|
if (response.length) {
|
|
2990
2993
|
response = response[0];
|
|
2991
2994
|
}
|
|
2992
2995
|
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2993
|
-
type: "
|
|
2994
|
-
error: new
|
|
2995
|
-
response:
|
|
2996
|
+
type: "onerror",
|
|
2997
|
+
error: new Error("request error"),
|
|
2998
|
+
response: response,
|
|
2996
2999
|
details: details,
|
|
2997
3000
|
})) == null) {
|
|
2998
|
-
// reject(new
|
|
3001
|
+
// reject(new Error("response is intercept with onerror"));
|
|
2999
3002
|
return;
|
|
3000
3003
|
}
|
|
3001
3004
|
resolve({
|
|
3002
3005
|
data: response,
|
|
3003
3006
|
details: details,
|
|
3004
|
-
msg: "
|
|
3007
|
+
msg: "请求异常",
|
|
3005
3008
|
status: false,
|
|
3006
|
-
statusCode:
|
|
3007
|
-
type: "
|
|
3009
|
+
statusCode: response["status"],
|
|
3010
|
+
type: "onerror",
|
|
3008
3011
|
});
|
|
3009
3012
|
},
|
|
3010
|
-
/**
|
|
3011
|
-
* onloadstart请求开始-触发
|
|
3012
|
-
* @param details 配置
|
|
3013
|
-
* @param argsResult 返回的参数列表
|
|
3014
|
-
*/
|
|
3015
|
-
onLoadStart(details, argsResult) {
|
|
3016
|
-
// console.log(argsResult);
|
|
3017
|
-
if ("onloadstart" in details) {
|
|
3018
|
-
details.onloadstart.apply(this, argsResult);
|
|
3019
|
-
}
|
|
3020
|
-
else if ("onloadstart" in this.context.#defaultRequestOption) {
|
|
3021
|
-
this.context.#defaultRequestOption.onloadstart.apply(this, argsResult);
|
|
3022
|
-
}
|
|
3023
|
-
},
|
|
3024
3013
|
/**
|
|
3025
3014
|
* onload加载完毕-触发
|
|
3026
3015
|
* @param details 请求的配置
|
|
@@ -3100,7 +3089,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3100
3089
|
/* 状态码2xx都是成功的 */
|
|
3101
3090
|
if (Math.floor(originResponse.status / 100) === 2) {
|
|
3102
3091
|
if ((await this.context.HttpxResponseHook.successResponseCallBack(originResponse, details)) == null) {
|
|
3103
|
-
// reject(new
|
|
3092
|
+
// reject(new Error("response is intercept with onloada"));
|
|
3104
3093
|
return;
|
|
3105
3094
|
}
|
|
3106
3095
|
resolve({
|
|
@@ -3113,21 +3102,21 @@ System.register('Utils', [], (function (exports) {
|
|
|
3113
3102
|
});
|
|
3114
3103
|
}
|
|
3115
3104
|
else {
|
|
3116
|
-
this.context.
|
|
3105
|
+
this.context.HttpxResponseCallBack.onError(details, resolve, reject, argsResult);
|
|
3117
3106
|
}
|
|
3118
3107
|
},
|
|
3119
3108
|
/**
|
|
3120
|
-
*
|
|
3109
|
+
* onloadstart请求开始-触发
|
|
3121
3110
|
* @param details 配置
|
|
3122
3111
|
* @param argsResult 返回的参数列表
|
|
3123
3112
|
*/
|
|
3124
|
-
|
|
3113
|
+
onLoadStart(details, argsResult) {
|
|
3125
3114
|
// console.log(argsResult);
|
|
3126
|
-
if ("
|
|
3127
|
-
details.
|
|
3115
|
+
if (typeof details?.onloadstart === "function") {
|
|
3116
|
+
details.onloadstart.apply(this, argsResult);
|
|
3128
3117
|
}
|
|
3129
|
-
else if (
|
|
3130
|
-
this.context.#defaultRequestOption.
|
|
3118
|
+
else if (typeof this.context.#defaultRequestOption?.onloadstart === "function") {
|
|
3119
|
+
this.context.#defaultRequestOption.onloadstart.apply(this, argsResult);
|
|
3131
3120
|
}
|
|
3132
3121
|
},
|
|
3133
3122
|
/**
|
|
@@ -3137,13 +3126,28 @@ System.register('Utils', [], (function (exports) {
|
|
|
3137
3126
|
*/
|
|
3138
3127
|
onReadyStateChange(details, argsResult) {
|
|
3139
3128
|
// console.log(argsResult);
|
|
3140
|
-
if (
|
|
3129
|
+
if (typeof details?.onreadystatechange === "function") {
|
|
3141
3130
|
details.onreadystatechange.apply(this, argsResult);
|
|
3142
3131
|
}
|
|
3143
|
-
else if (
|
|
3132
|
+
else if (typeof this.context.#defaultRequestOption?.onreadystatechange ===
|
|
3133
|
+
"function") {
|
|
3144
3134
|
this.context.#defaultRequestOption.onreadystatechange.apply(this, argsResult);
|
|
3145
3135
|
}
|
|
3146
3136
|
},
|
|
3137
|
+
/**
|
|
3138
|
+
* onprogress上传进度-触发
|
|
3139
|
+
* @param details 配置
|
|
3140
|
+
* @param argsResult 返回的参数列表
|
|
3141
|
+
*/
|
|
3142
|
+
onProgress(details, argsResult) {
|
|
3143
|
+
// console.log(argsResult);
|
|
3144
|
+
if (typeof details?.onprogress === "function") {
|
|
3145
|
+
details.onprogress.apply(this, argsResult);
|
|
3146
|
+
}
|
|
3147
|
+
else if (typeof this.context.#defaultRequestOption?.onprogress === "function") {
|
|
3148
|
+
this.context.#defaultRequestOption.onprogress.apply(this, argsResult);
|
|
3149
|
+
}
|
|
3150
|
+
},
|
|
3147
3151
|
};
|
|
3148
3152
|
HttpxRequest = {
|
|
3149
3153
|
context: this,
|
|
@@ -3193,15 +3197,12 @@ System.register('Utils', [], (function (exports) {
|
|
|
3193
3197
|
isFetch: true,
|
|
3194
3198
|
finalUrl: fetchResponse.url,
|
|
3195
3199
|
readyState: 4,
|
|
3196
|
-
// @ts-ignore
|
|
3197
3200
|
status: fetchResponse.status,
|
|
3198
3201
|
statusText: fetchResponse.statusText,
|
|
3199
|
-
|
|
3200
|
-
response: void 0,
|
|
3202
|
+
response: "",
|
|
3201
3203
|
responseFetchHeaders: fetchResponse.headers,
|
|
3202
3204
|
responseHeaders: "",
|
|
3203
|
-
|
|
3204
|
-
responseText: void 0,
|
|
3205
|
+
responseText: "",
|
|
3205
3206
|
responseType: option.responseType,
|
|
3206
3207
|
responseXML: void 0,
|
|
3207
3208
|
};
|
|
@@ -3274,9 +3275,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
3274
3275
|
// 转为XML结构
|
|
3275
3276
|
let parser = new DOMParser();
|
|
3276
3277
|
responseXML = parser.parseFromString(responseText, "text/xml");
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3278
|
+
httpxResponse.response = response;
|
|
3279
|
+
httpxResponse.responseText = responseText;
|
|
3280
|
+
httpxResponse.responseXML = responseXML;
|
|
3280
3281
|
// 执行回调
|
|
3281
3282
|
option.onload(httpxResponse);
|
|
3282
3283
|
})
|
|
@@ -3457,7 +3458,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3457
3458
|
}
|
|
3458
3459
|
/**
|
|
3459
3460
|
* GET 请求
|
|
3460
|
-
* @param url
|
|
3461
|
+
* @param url 请求的url
|
|
3461
3462
|
* @param details 配置
|
|
3462
3463
|
*/
|
|
3463
3464
|
get(...args) {
|
|
@@ -3523,27 +3524,22 @@ System.register('Utils', [], (function (exports) {
|
|
|
3523
3524
|
/** 取消请求 */
|
|
3524
3525
|
let abortFn = null;
|
|
3525
3526
|
let promise = new globalThis.Promise(async (resolve, reject) => {
|
|
3526
|
-
let requestOption = this.HttpxRequestOption.getRequestOption(useRequestOption.method, useRequestOption, resolve, reject);
|
|
3527
|
+
let requestOption = (this.HttpxRequestOption.getRequestOption(useRequestOption.method, useRequestOption, resolve, reject));
|
|
3527
3528
|
if (typeof beforeRequestOption === "function") {
|
|
3528
|
-
// @ts-ignore
|
|
3529
3529
|
beforeRequestOption(requestOption);
|
|
3530
3530
|
}
|
|
3531
|
-
|
|
3532
|
-
requestOption =
|
|
3533
|
-
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
3531
|
+
requestOption = this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
3534
3532
|
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
3535
3533
|
if (requestResult != null &&
|
|
3536
3534
|
typeof requestResult.abort === "function") {
|
|
3537
3535
|
abortFn = requestResult.abort;
|
|
3538
3536
|
}
|
|
3539
3537
|
});
|
|
3540
|
-
// @ts-ignore
|
|
3541
3538
|
promise.abort = () => {
|
|
3542
3539
|
if (typeof abortFn === "function") {
|
|
3543
3540
|
abortFn();
|
|
3544
3541
|
}
|
|
3545
3542
|
};
|
|
3546
|
-
// @ts-ignore
|
|
3547
3543
|
return promise;
|
|
3548
3544
|
}
|
|
3549
3545
|
}
|
|
@@ -3553,8 +3549,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3553
3549
|
#storeName;
|
|
3554
3550
|
#dbVersion;
|
|
3555
3551
|
/* websql的版本号,由于ios的问题,版本号的写法不一样 */
|
|
3556
|
-
//
|
|
3557
|
-
#slqVersion = "1";
|
|
3552
|
+
// #slqVersion = "1";
|
|
3558
3553
|
/* 监听IndexDB */
|
|
3559
3554
|
#indexedDB = window.indexedDB ||
|
|
3560
3555
|
window.mozIndexedDB ||
|
|
@@ -3562,8 +3557,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3562
3557
|
window.msIndexedDB;
|
|
3563
3558
|
/* 缓存数据库,避免同一个页面重复创建和销毁 */
|
|
3564
3559
|
#db = {};
|
|
3565
|
-
//
|
|
3566
|
-
#store = null;
|
|
3560
|
+
// #store: IDBObjectStore = null as any;
|
|
3567
3561
|
/** 状态码 */
|
|
3568
3562
|
#statusCode = {
|
|
3569
3563
|
operationSuccess: {
|
|
@@ -3608,7 +3602,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3608
3602
|
txn = this.#db[dbName].transaction(this.#storeName, "readwrite");
|
|
3609
3603
|
/* IndexDB的读写权限 */
|
|
3610
3604
|
store = txn.objectStore(this.#storeName);
|
|
3611
|
-
this.#store = store;
|
|
3605
|
+
// this.#store = store;
|
|
3612
3606
|
return store;
|
|
3613
3607
|
}
|
|
3614
3608
|
/**
|
|
@@ -4333,12 +4327,40 @@ System.register('Utils', [], (function (exports) {
|
|
|
4333
4327
|
}
|
|
4334
4328
|
|
|
4335
4329
|
class UtilsDictionary {
|
|
4336
|
-
items
|
|
4330
|
+
items;
|
|
4337
4331
|
constructor(key, value) {
|
|
4332
|
+
this.items = {};
|
|
4338
4333
|
if (key != null) {
|
|
4339
4334
|
this.set(key, value);
|
|
4340
4335
|
}
|
|
4341
4336
|
}
|
|
4337
|
+
/**
|
|
4338
|
+
* 获取字典的长度,同this.size
|
|
4339
|
+
*/
|
|
4340
|
+
get length() {
|
|
4341
|
+
return this.size();
|
|
4342
|
+
}
|
|
4343
|
+
/**
|
|
4344
|
+
* 迭代器
|
|
4345
|
+
*/
|
|
4346
|
+
get entries() {
|
|
4347
|
+
let that = this;
|
|
4348
|
+
return function* () {
|
|
4349
|
+
let itemKeys = Object.keys(that.getItems());
|
|
4350
|
+
for (const keyName of itemKeys) {
|
|
4351
|
+
yield [keyName, that.get(keyName)];
|
|
4352
|
+
}
|
|
4353
|
+
};
|
|
4354
|
+
}
|
|
4355
|
+
/**
|
|
4356
|
+
* 是否可遍历
|
|
4357
|
+
*/
|
|
4358
|
+
get [Symbol.iterator]() {
|
|
4359
|
+
let that = this;
|
|
4360
|
+
return function () {
|
|
4361
|
+
return that.entries();
|
|
4362
|
+
};
|
|
4363
|
+
}
|
|
4342
4364
|
/**
|
|
4343
4365
|
* 检查是否有某一个键
|
|
4344
4366
|
* @param key 键
|
|
@@ -4439,7 +4461,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
4439
4461
|
* 返回字典本身
|
|
4440
4462
|
*/
|
|
4441
4463
|
getItems() {
|
|
4442
|
-
// @ts-ignore
|
|
4443
4464
|
return this.items;
|
|
4444
4465
|
}
|
|
4445
4466
|
/**
|
|
@@ -4449,38 +4470,15 @@ System.register('Utils', [], (function (exports) {
|
|
|
4449
4470
|
concat(data) {
|
|
4450
4471
|
this.items = commonUtil.assign(this.items, data.getItems());
|
|
4451
4472
|
}
|
|
4473
|
+
/**
|
|
4474
|
+
* 迭代字典
|
|
4475
|
+
* @param callbackfn 回调函数
|
|
4476
|
+
*/
|
|
4452
4477
|
forEach(callbackfn) {
|
|
4453
4478
|
for (const key in this.getItems()) {
|
|
4454
4479
|
callbackfn(this.get(key), key, this.getItems());
|
|
4455
4480
|
}
|
|
4456
4481
|
}
|
|
4457
|
-
/**
|
|
4458
|
-
* 获取字典的长度,同this.size
|
|
4459
|
-
*/
|
|
4460
|
-
get length() {
|
|
4461
|
-
return this.size();
|
|
4462
|
-
}
|
|
4463
|
-
/**
|
|
4464
|
-
* 迭代器
|
|
4465
|
-
*/
|
|
4466
|
-
get entries() {
|
|
4467
|
-
let that = this;
|
|
4468
|
-
return function* () {
|
|
4469
|
-
let itemKeys = Object.keys(that.getItems());
|
|
4470
|
-
for (const keyName of itemKeys) {
|
|
4471
|
-
yield [keyName, that.get(keyName)];
|
|
4472
|
-
}
|
|
4473
|
-
};
|
|
4474
|
-
}
|
|
4475
|
-
/**
|
|
4476
|
-
* 是否可遍历
|
|
4477
|
-
*/
|
|
4478
|
-
get [Symbol.iterator]() {
|
|
4479
|
-
let that = this;
|
|
4480
|
-
return function () {
|
|
4481
|
-
return that.entries();
|
|
4482
|
-
};
|
|
4483
|
-
}
|
|
4484
4482
|
}
|
|
4485
4483
|
|
|
4486
4484
|
class WindowApi {
|
|
@@ -4506,7 +4504,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
4506
4504
|
if (!option) {
|
|
4507
4505
|
option = Object.assign({}, this.defaultApi);
|
|
4508
4506
|
}
|
|
4509
|
-
// @ts-ignore
|
|
4510
4507
|
this.api = Object.assign({}, option);
|
|
4511
4508
|
}
|
|
4512
4509
|
get document() {
|
|
@@ -4564,11 +4561,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
4564
4561
|
deps = [];
|
|
4565
4562
|
active = true;
|
|
4566
4563
|
fn;
|
|
4567
|
-
//
|
|
4568
|
-
scheduler;
|
|
4564
|
+
// private scheduler;
|
|
4569
4565
|
constructor(fn, scheduler) {
|
|
4570
4566
|
this.fn = fn;
|
|
4571
|
-
this.scheduler = scheduler;
|
|
4567
|
+
// this.scheduler = scheduler;
|
|
4572
4568
|
}
|
|
4573
4569
|
run(cb) {
|
|
4574
4570
|
if (!this.active) {
|
|
@@ -4635,8 +4631,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4635
4631
|
reactive(target) {
|
|
4636
4632
|
const that = this;
|
|
4637
4633
|
if (!(typeof target === "object" && target !== null)) {
|
|
4638
|
-
|
|
4639
|
-
return;
|
|
4634
|
+
return void 0;
|
|
4640
4635
|
}
|
|
4641
4636
|
if (VueUtils.isReactive(target)) {
|
|
4642
4637
|
return target;
|
|
@@ -4706,7 +4701,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
4706
4701
|
toRefs(object) {
|
|
4707
4702
|
const result = VueUtils.isArray(object) ? new Array(object.length) : {};
|
|
4708
4703
|
for (let key in object) {
|
|
4709
|
-
// @ts-ignore
|
|
4710
4704
|
result[key] = this.toRef(object, key);
|
|
4711
4705
|
}
|
|
4712
4706
|
return result;
|
|
@@ -5002,7 +4996,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5002
4996
|
};
|
|
5003
4997
|
|
|
5004
4998
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
5005
|
-
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),
|
|
4999
|
+
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
|
|
5006
5000
|
|
|
5007
5001
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
5008
5002
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -5434,7 +5428,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
5434
5428
|
let text = textMatch[2];
|
|
5435
5429
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5436
5430
|
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5437
|
-
// @ts-ignore
|
|
5438
5431
|
return ($ele?.textContent || $ele?.innerText)?.includes(text);
|
|
5439
5432
|
});
|
|
5440
5433
|
}
|
|
@@ -5452,7 +5445,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
5452
5445
|
let regexp = new RegExp(pattern, flags);
|
|
5453
5446
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5454
5447
|
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5455
|
-
// @ts-ignore
|
|
5456
5448
|
return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
|
|
5457
5449
|
});
|
|
5458
5450
|
}
|
|
@@ -5498,7 +5490,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
5498
5490
|
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
5499
5491
|
let text = textMatch[2];
|
|
5500
5492
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5501
|
-
// @ts-ignore
|
|
5502
5493
|
let content = $el?.textContent || $el?.innerText;
|
|
5503
5494
|
if (typeof content !== "string") {
|
|
5504
5495
|
content = "";
|
|
@@ -5518,7 +5509,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
5518
5509
|
}
|
|
5519
5510
|
let regexp = new RegExp(pattern, flags);
|
|
5520
5511
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5521
|
-
// @ts-ignore
|
|
5522
5512
|
let content = $el?.textContent || $el?.innerText;
|
|
5523
5513
|
if (typeof content !== "string") {
|
|
5524
5514
|
content = "";
|
|
@@ -5549,7 +5539,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
5549
5539
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5550
5540
|
let $closest = $el?.closest(selector);
|
|
5551
5541
|
if ($closest) {
|
|
5552
|
-
// @ts-ignore
|
|
5553
5542
|
let content = $el?.textContent || $el?.innerText;
|
|
5554
5543
|
if (typeof content === "string" && content.includes(text)) {
|
|
5555
5544
|
return $closest;
|
|
@@ -5572,7 +5561,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
5572
5561
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5573
5562
|
let $closest = $el?.closest(selector);
|
|
5574
5563
|
if ($closest) {
|
|
5575
|
-
// @ts-ignore
|
|
5576
5564
|
let content = $el?.textContent || $el?.innerText;
|
|
5577
5565
|
if (typeof content === "string" && content.match(regexp)) {
|
|
5578
5566
|
return $closest;
|
|
@@ -5595,7 +5583,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5595
5583
|
this.windowApi = new WindowApi(option);
|
|
5596
5584
|
}
|
|
5597
5585
|
/** 版本号 */
|
|
5598
|
-
version = "2025.
|
|
5586
|
+
version = "2025.7.29";
|
|
5599
5587
|
addStyle(cssText) {
|
|
5600
5588
|
if (typeof cssText !== "string") {
|
|
5601
5589
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5679,7 +5667,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5679
5667
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
5680
5668
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
5681
5669
|
* + 作者:cxxjackie
|
|
5682
|
-
* + 版本:1.4.
|
|
5670
|
+
* + 版本:1.4.7
|
|
5683
5671
|
* + 旧版本:1.2.4
|
|
5684
5672
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5685
5673
|
* @param useOldVersion 是否使用旧版本,默认false
|
|
@@ -5692,7 +5680,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5692
5680
|
return ajaxHooker();
|
|
5693
5681
|
}
|
|
5694
5682
|
};
|
|
5695
|
-
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view =
|
|
5683
|
+
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = this.windowApi.window) {
|
|
5696
5684
|
if (!(canvasElement instanceof HTMLCanvasElement)) {
|
|
5697
5685
|
throw new Error("Utils.canvasClickByPosition 参数canvasElement必须是canvas元素");
|
|
5698
5686
|
}
|
|
@@ -5703,7 +5691,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
5703
5691
|
cancelable: true,
|
|
5704
5692
|
clientX: clientX,
|
|
5705
5693
|
clientY: clientY,
|
|
5706
|
-
// @ts-ignore
|
|
5707
5694
|
view: view,
|
|
5708
5695
|
detail: 1,
|
|
5709
5696
|
};
|
|
@@ -6210,12 +6197,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
6210
6197
|
}
|
|
6211
6198
|
getElementSelector(element) {
|
|
6212
6199
|
let UtilsContext = this;
|
|
6213
|
-
// @ts-ignore
|
|
6214
6200
|
if (!element)
|
|
6215
|
-
return;
|
|
6216
|
-
// @ts-ignore
|
|
6201
|
+
return void 0;
|
|
6217
6202
|
if (!element.parentElement)
|
|
6218
|
-
return;
|
|
6203
|
+
return void 0;
|
|
6219
6204
|
/* 如果元素有id属性,则直接返回id选择器 */
|
|
6220
6205
|
if (element.id)
|
|
6221
6206
|
return "#" + element.id;
|
|
@@ -6246,8 +6231,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
6246
6231
|
let result = [...args];
|
|
6247
6232
|
let newResult = [];
|
|
6248
6233
|
if (result.length === 0) {
|
|
6249
|
-
|
|
6250
|
-
return;
|
|
6234
|
+
return void 0;
|
|
6251
6235
|
}
|
|
6252
6236
|
if (result.length > 1) {
|
|
6253
6237
|
if (result.length === 2 &&
|
|
@@ -6287,7 +6271,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
6287
6271
|
// 当前页面最大的z-index
|
|
6288
6272
|
let zIndex = 0;
|
|
6289
6273
|
// 当前的最大z-index的元素,调试使用
|
|
6290
|
-
// @ts-ignore
|
|
6291
6274
|
let maxZIndexNode = null;
|
|
6292
6275
|
/**
|
|
6293
6276
|
* 元素是否可见
|
|
@@ -6348,8 +6331,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
6348
6331
|
let result = [...args];
|
|
6349
6332
|
let newResult = [];
|
|
6350
6333
|
if (result.length === 0) {
|
|
6351
|
-
|
|
6352
|
-
return;
|
|
6334
|
+
return void 0;
|
|
6353
6335
|
}
|
|
6354
6336
|
if (result.length > 1) {
|
|
6355
6337
|
if (result.length === 2 &&
|
|
@@ -6823,7 +6805,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
6823
6805
|
}
|
|
6824
6806
|
isJQuery(target) {
|
|
6825
6807
|
let result = false;
|
|
6826
|
-
// @ts-ignore
|
|
6827
6808
|
if (typeof jQuery === "object" && target instanceof jQuery) {
|
|
6828
6809
|
result = true;
|
|
6829
6810
|
}
|
|
@@ -7604,29 +7585,27 @@ System.register('Utils', [], (function (exports) {
|
|
|
7604
7585
|
EventTarget.prototype.addEventListener = function (...args) {
|
|
7605
7586
|
let type = args[0];
|
|
7606
7587
|
let callback = args[1];
|
|
7607
|
-
//
|
|
7608
|
-
args[2];
|
|
7588
|
+
// let options = args[2];
|
|
7609
7589
|
if (filter(type)) {
|
|
7610
7590
|
if (typeof callback === "function") {
|
|
7611
7591
|
args[1] = function (event) {
|
|
7612
7592
|
callback.call(this, trustEvent(event));
|
|
7613
7593
|
};
|
|
7614
7594
|
}
|
|
7615
|
-
else if (typeof callback === "object" &&
|
|
7616
|
-
"handleEvent" in callback) {
|
|
7595
|
+
else if (typeof callback === "object" && "handleEvent" in callback) {
|
|
7617
7596
|
let oldHandleEvent = callback["handleEvent"];
|
|
7618
7597
|
args[1]["handleEvent"] = function (event) {
|
|
7619
7598
|
if (event == null) {
|
|
7620
7599
|
return;
|
|
7621
7600
|
}
|
|
7622
7601
|
try {
|
|
7623
|
-
|
|
7602
|
+
// Proxy对象使用instanceof会报错
|
|
7603
|
+
// 这里故意尝试一下,如果报错,则说明是Proxy对象
|
|
7624
7604
|
event instanceof Proxy;
|
|
7625
7605
|
oldHandleEvent.call(this, trustEvent(event));
|
|
7626
7606
|
}
|
|
7627
7607
|
catch (error) {
|
|
7628
|
-
|
|
7629
|
-
event["isTrusted"] = isTrustValue;
|
|
7608
|
+
Reflect.set(event, "isTrusted", isTrustValue);
|
|
7630
7609
|
}
|
|
7631
7610
|
};
|
|
7632
7611
|
}
|
|
@@ -7699,8 +7678,8 @@ System.register('Utils', [], (function (exports) {
|
|
|
7699
7678
|
}
|
|
7700
7679
|
async init() {
|
|
7701
7680
|
let copyStatus = false;
|
|
7702
|
-
|
|
7703
|
-
|
|
7681
|
+
let requestPermissionStatus = await this.requestClipboardPermission();
|
|
7682
|
+
console.log(requestPermissionStatus);
|
|
7704
7683
|
if (this.hasClipboard() &&
|
|
7705
7684
|
(this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
7706
7685
|
try {
|
|
@@ -7718,11 +7697,8 @@ System.register('Utils', [], (function (exports) {
|
|
|
7718
7697
|
this.destroy();
|
|
7719
7698
|
}
|
|
7720
7699
|
destroy() {
|
|
7721
|
-
// @ts-ignore
|
|
7722
7700
|
this.#resolve = null;
|
|
7723
|
-
// @ts-ignore
|
|
7724
7701
|
this.#copyData = null;
|
|
7725
|
-
// @ts-ignore
|
|
7726
7702
|
this.#copyDataType = null;
|
|
7727
7703
|
}
|
|
7728
7704
|
isText() {
|
|
@@ -7766,7 +7742,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
7766
7742
|
if (navigator.permissions && navigator.permissions.query) {
|
|
7767
7743
|
navigator.permissions
|
|
7768
7744
|
.query({
|
|
7769
|
-
// @ts-ignore
|
|
7770
7745
|
name: "clipboard-write",
|
|
7771
7746
|
})
|
|
7772
7747
|
.then((permissionStatus) => {
|
|
@@ -7862,7 +7837,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
7862
7837
|
dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
|
|
7863
7838
|
let UtilsContext = this;
|
|
7864
7839
|
function initMouseEvent(eventName, offSetX, offSetY) {
|
|
7865
|
-
// @ts-ignore
|
|
7866
7840
|
let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
|
|
7867
7841
|
let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
7868
7842
|
mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
|
|
@@ -8021,7 +7995,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
8021
7995
|
}
|
|
8022
7996
|
stringToRegular(targetString, flags = "ig") {
|
|
8023
7997
|
let reg;
|
|
8024
|
-
// @ts-ignore
|
|
8025
7998
|
flags = flags.toLowerCase();
|
|
8026
7999
|
if (typeof targetString === "string") {
|
|
8027
8000
|
reg = new RegExp(targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"), flags);
|
|
@@ -8114,10 +8087,8 @@ System.register('Utils', [], (function (exports) {
|
|
|
8114
8087
|
*/
|
|
8115
8088
|
searchParamStrToObj(searhParamsStr) {
|
|
8116
8089
|
if (typeof searhParamsStr !== "string") {
|
|
8117
|
-
// @ts-ignore
|
|
8118
8090
|
return {};
|
|
8119
8091
|
}
|
|
8120
|
-
// @ts-ignore
|
|
8121
8092
|
return Object.fromEntries(new URLSearchParams(searhParamsStr));
|
|
8122
8093
|
}
|
|
8123
8094
|
/**
|
|
@@ -8820,7 +8791,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
8820
8791
|
function requestPermissionsWithClipboard() {
|
|
8821
8792
|
navigator.permissions
|
|
8822
8793
|
.query({
|
|
8823
|
-
// @ts-ignore
|
|
8824
8794
|
name: "clipboard-read",
|
|
8825
8795
|
})
|
|
8826
8796
|
.then((permissionStatus) => {
|