@whitesev/utils 2.7.2 → 2.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.amd.js +197 -350
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +197 -350
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +197 -350
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +197 -350
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +197 -350
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +197 -350
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/WindowApi.d.ts +4 -0
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +4 -21
- package/dist/types/src/types/WindowApi.d.ts +4 -0
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/package.json +1 -1
- package/src/ColorConversion.ts +5 -18
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -22
- package/src/Dictionary.ts +2 -7
- package/src/GBKEncoder.ts +1 -6
- package/src/Hooks.ts +1 -4
- package/src/Httpx.ts +102 -277
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +7 -23
- package/src/Progress.ts +2 -10
- package/src/TryCatch.ts +3 -11
- package/src/Utils.ts +213 -559
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +10 -29
- package/src/Vue.ts +2 -11
- package/src/WindowApi.ts +16 -0
- package/src/ajaxHooker/ajaxHooker.js +78 -142
- package/src/indexedDB.ts +3 -12
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +4 -21
- package/src/types/WindowApi.d.ts +4 -0
- package/src/types/ajaxHooker.d.ts +1 -5
package/dist/index.esm.js
CHANGED
|
@@ -65,11 +65,7 @@ class ColorConversion {
|
|
|
65
65
|
!validPattern.test(greenValue.toString()) ||
|
|
66
66
|
!validPattern.test(blueValue.toString()))
|
|
67
67
|
throw new TypeError("输入错误的rgb颜色值");
|
|
68
|
-
let hexs = [
|
|
69
|
-
redValue.toString(16),
|
|
70
|
-
greenValue.toString(16),
|
|
71
|
-
blueValue.toString(16),
|
|
72
|
-
];
|
|
68
|
+
let hexs = [redValue.toString(16), greenValue.toString(16), blueValue.toString(16)];
|
|
73
69
|
for (let index = 0; index < 3; index++)
|
|
74
70
|
if (hexs[index].length == 1)
|
|
75
71
|
hexs[index] = "0" + hexs[index];
|
|
@@ -117,10 +113,7 @@ class GBKEncoder {
|
|
|
117
113
|
this.#data = dataText.match(/..../g);
|
|
118
114
|
for (let i = 0x81; i <= 0xfe; i++) {
|
|
119
115
|
for (let j = 0x40; j <= 0xfe; j++) {
|
|
120
|
-
this.#U2Ghash[this.#data[index++]] = ("%" +
|
|
121
|
-
i.toString(16) +
|
|
122
|
-
"%" +
|
|
123
|
-
j.toString(16)).toUpperCase();
|
|
116
|
+
this.#U2Ghash[this.#data[index++]] = ("%" + i.toString(16) + "%" + j.toString(16)).toUpperCase();
|
|
124
117
|
}
|
|
125
118
|
}
|
|
126
119
|
for (let key in this.#U2Ghash) {
|
|
@@ -248,9 +241,7 @@ const TryCatch = function (...args) {
|
|
|
248
241
|
callbackFunction = callback;
|
|
249
242
|
context = __context__ || this;
|
|
250
243
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
251
|
-
return result !== void 0
|
|
252
|
-
? result
|
|
253
|
-
: TryCatchCore;
|
|
244
|
+
return result !== void 0 ? result : TryCatchCore;
|
|
254
245
|
},
|
|
255
246
|
};
|
|
256
247
|
/**
|
|
@@ -279,10 +270,7 @@ const TryCatch = function (...args) {
|
|
|
279
270
|
}
|
|
280
271
|
if (handleErrorFunc) {
|
|
281
272
|
if (typeof handleErrorFunc === "string") {
|
|
282
|
-
result = new Function(handleErrorFunc).apply(funcThis, [
|
|
283
|
-
...args,
|
|
284
|
-
error,
|
|
285
|
-
]);
|
|
273
|
+
result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
|
|
286
274
|
}
|
|
287
275
|
else {
|
|
288
276
|
result = handleErrorFunc.apply(funcThis, [...args, error]);
|
|
@@ -370,10 +358,7 @@ class CommonUtil {
|
|
|
370
358
|
itemResult = objItem === 0;
|
|
371
359
|
break;
|
|
372
360
|
case "string":
|
|
373
|
-
itemResult =
|
|
374
|
-
objItem.trim() === "" ||
|
|
375
|
-
objItem === "null" ||
|
|
376
|
-
objItem === "undefined";
|
|
361
|
+
itemResult = objItem.trim() === "" || objItem === "null" || objItem === "undefined";
|
|
377
362
|
break;
|
|
378
363
|
case "boolean":
|
|
379
364
|
itemResult = !objItem;
|
|
@@ -414,8 +399,7 @@ class CommonUtil {
|
|
|
414
399
|
return null;
|
|
415
400
|
let clone = obj instanceof Array ? [] : {};
|
|
416
401
|
for (const [key, value] of Object.entries(obj)) {
|
|
417
|
-
clone[key] =
|
|
418
|
-
typeof value === "object" ? UtilsContext.deepClone(value) : value;
|
|
402
|
+
clone[key] = typeof value === "object" ? UtilsContext.deepClone(value) : value;
|
|
419
403
|
}
|
|
420
404
|
return clone;
|
|
421
405
|
}
|
|
@@ -733,13 +717,13 @@ class UtilsGMCookie {
|
|
|
733
717
|
// ==UserScript==
|
|
734
718
|
// @name ajaxHooker
|
|
735
719
|
// @author cxxjackie
|
|
736
|
-
// @version 1.4.
|
|
720
|
+
// @version 1.4.8
|
|
737
721
|
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
738
722
|
// @license GNU LGPL-3.0
|
|
739
723
|
// ==/UserScript==
|
|
740
724
|
|
|
741
725
|
const ajaxHooker = function () {
|
|
742
|
-
const version = "1.4.
|
|
726
|
+
const version = "1.4.8";
|
|
743
727
|
const hookInst = {
|
|
744
728
|
hookFns: [],
|
|
745
729
|
filters: [],
|
|
@@ -768,11 +752,7 @@ const ajaxHooker = function () {
|
|
|
768
752
|
const emptyFn = () => {};
|
|
769
753
|
const errorFn = (e) => console.error(e);
|
|
770
754
|
function isThenable(obj) {
|
|
771
|
-
return (
|
|
772
|
-
obj &&
|
|
773
|
-
["object", "function"].includes(typeof obj) &&
|
|
774
|
-
typeof obj.then === "function"
|
|
775
|
-
);
|
|
755
|
+
return obj && ["object", "function"].includes(typeof obj) && typeof obj.then === "function";
|
|
776
756
|
}
|
|
777
757
|
function catchError(fn, ...args) {
|
|
778
758
|
try {
|
|
@@ -810,8 +790,7 @@ const ajaxHooker = function () {
|
|
|
810
790
|
const [header, value] = line.split(/(?<=^[^:]+)\s*:\s*/);
|
|
811
791
|
if (!value) continue;
|
|
812
792
|
const lheader = header.toLowerCase();
|
|
813
|
-
headers[lheader] =
|
|
814
|
-
lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
793
|
+
headers[lheader] = lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
815
794
|
}
|
|
816
795
|
break;
|
|
817
796
|
case "[object Headers]":
|
|
@@ -849,11 +828,9 @@ const ajaxHooker = function () {
|
|
|
849
828
|
!filters.find((obj) => {
|
|
850
829
|
switch (true) {
|
|
851
830
|
case obj.type && obj.type !== type:
|
|
852
|
-
case getType(obj.url) === "[object String]" &&
|
|
853
|
-
!url.includes(obj.url):
|
|
831
|
+
case getType(obj.url) === "[object String]" && !url.includes(obj.url):
|
|
854
832
|
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
855
|
-
case obj.method &&
|
|
856
|
-
obj.method.toUpperCase() !== method.toUpperCase():
|
|
833
|
+
case obj.method && obj.method.toUpperCase() !== method.toUpperCase():
|
|
857
834
|
case "async" in obj && obj.async !== async:
|
|
858
835
|
return false;
|
|
859
836
|
}
|
|
@@ -866,8 +843,7 @@ const ajaxHooker = function () {
|
|
|
866
843
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
867
844
|
if (this.shouldFilter(filters)) return;
|
|
868
845
|
hookFns.forEach((fn) => {
|
|
869
|
-
if (getType(fn) === "[object Function]")
|
|
870
|
-
catchError(fn, this.request);
|
|
846
|
+
if (getType(fn) === "[object Function]") catchError(fn, this.request);
|
|
871
847
|
});
|
|
872
848
|
for (const key in this.request) {
|
|
873
849
|
if (isThenable(this.request[key])) this._recoverRequestKey(key);
|
|
@@ -880,93 +856,72 @@ const ajaxHooker = function () {
|
|
|
880
856
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
881
857
|
if (this.shouldFilter(filters)) return;
|
|
882
858
|
promises.push(
|
|
883
|
-
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
(val) => (this.request[key] = val),
|
|
892
|
-
() => this._recoverRequestKey(key)
|
|
893
|
-
)
|
|
859
|
+
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(() => {
|
|
860
|
+
const requestKeys = [];
|
|
861
|
+
for (const key in this.request) !ignoreKeys.has(key) && requestKeys.push(key);
|
|
862
|
+
return Promise.all(
|
|
863
|
+
requestKeys.map((key) =>
|
|
864
|
+
Promise.resolve(this.request[key]).then(
|
|
865
|
+
(val) => (this.request[key] = val),
|
|
866
|
+
() => this._recoverRequestKey(key)
|
|
894
867
|
)
|
|
895
|
-
)
|
|
896
|
-
|
|
897
|
-
)
|
|
868
|
+
)
|
|
869
|
+
);
|
|
870
|
+
})
|
|
898
871
|
);
|
|
899
872
|
});
|
|
900
873
|
return Promise.all(promises);
|
|
901
874
|
}
|
|
902
875
|
waitForResponseKeys(response) {
|
|
903
|
-
const responseKeys =
|
|
904
|
-
this.request.type === "xhr" ? xhrResponses : fetchResponses;
|
|
876
|
+
const responseKeys = this.request.type === "xhr" ? xhrResponses : fetchResponses;
|
|
905
877
|
if (!this.request.async) {
|
|
906
878
|
if (getType(this.request.response) === "[object Function]") {
|
|
907
879
|
catchError(this.request.response, response);
|
|
908
880
|
responseKeys.forEach((key) => {
|
|
909
|
-
if (
|
|
910
|
-
"get" in getDescriptor(response, key) ||
|
|
911
|
-
isThenable(response[key])
|
|
912
|
-
) {
|
|
881
|
+
if ("get" in getDescriptor(response, key) || isThenable(response[key])) {
|
|
913
882
|
delete response[key];
|
|
914
883
|
}
|
|
915
884
|
});
|
|
916
885
|
}
|
|
917
886
|
return new SyncThenable();
|
|
918
887
|
}
|
|
919
|
-
return Promise.resolve(catchError(this.request.response, response)).then(
|
|
920
|
-
(
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
)
|
|
888
|
+
return Promise.resolve(catchError(this.request.response, response)).then(() =>
|
|
889
|
+
Promise.all(
|
|
890
|
+
responseKeys.map((key) => {
|
|
891
|
+
const descriptor = getDescriptor(response, key);
|
|
892
|
+
if (descriptor && "value" in descriptor) {
|
|
893
|
+
return Promise.resolve(descriptor.value).then(
|
|
894
|
+
(val) => (response[key] = val),
|
|
895
|
+
() => delete response[key]
|
|
896
|
+
);
|
|
897
|
+
} else {
|
|
898
|
+
delete response[key];
|
|
899
|
+
}
|
|
900
|
+
})
|
|
901
|
+
)
|
|
934
902
|
);
|
|
935
903
|
}
|
|
936
904
|
}
|
|
937
905
|
const proxyHandler = {
|
|
938
906
|
get(target, prop) {
|
|
939
907
|
const descriptor = getDescriptor(target, prop);
|
|
940
|
-
if (
|
|
941
|
-
descriptor &&
|
|
942
|
-
!descriptor.configurable &&
|
|
943
|
-
!descriptor.writable &&
|
|
944
|
-
!descriptor.get
|
|
945
|
-
)
|
|
908
|
+
if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.get)
|
|
946
909
|
return target[prop];
|
|
947
910
|
const ah = target.__ajaxHooker;
|
|
948
911
|
if (ah && ah.proxyProps) {
|
|
949
912
|
if (prop in ah.proxyProps) {
|
|
950
913
|
const pDescriptor = ah.proxyProps[prop];
|
|
951
914
|
if ("get" in pDescriptor) return pDescriptor.get();
|
|
952
|
-
if (typeof pDescriptor.value === "function")
|
|
953
|
-
return pDescriptor.value.bind(ah);
|
|
915
|
+
if (typeof pDescriptor.value === "function") return pDescriptor.value.bind(ah);
|
|
954
916
|
return pDescriptor.value;
|
|
955
917
|
}
|
|
956
|
-
if (typeof target[prop] === "function")
|
|
957
|
-
return target[prop].bind(target);
|
|
918
|
+
if (typeof target[prop] === "function") return target[prop].bind(target);
|
|
958
919
|
}
|
|
959
920
|
return target[prop];
|
|
960
921
|
},
|
|
961
922
|
set(target, prop, value) {
|
|
962
923
|
const descriptor = getDescriptor(target, prop);
|
|
963
|
-
if (
|
|
964
|
-
descriptor &&
|
|
965
|
-
!descriptor.configurable &&
|
|
966
|
-
!descriptor.writable &&
|
|
967
|
-
!descriptor.set
|
|
968
|
-
)
|
|
969
|
-
return true;
|
|
924
|
+
if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.set) return true;
|
|
970
925
|
const ah = target.__ajaxHooker;
|
|
971
926
|
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
972
927
|
const pDescriptor = ah.proxyProps[prop];
|
|
@@ -988,11 +943,7 @@ const ajaxHooker = function () {
|
|
|
988
943
|
proxyEvents: {},
|
|
989
944
|
});
|
|
990
945
|
xhr.addEventListener("readystatechange", (e) => {
|
|
991
|
-
if (
|
|
992
|
-
ah.proxyXhr.readyState === 4 &&
|
|
993
|
-
ah.request &&
|
|
994
|
-
typeof ah.request.response === "function"
|
|
995
|
-
) {
|
|
946
|
+
if (ah.proxyXhr.readyState === 4 && ah.request && typeof ah.request.response === "function") {
|
|
996
947
|
const response = {
|
|
997
948
|
finalUrl: ah.proxyXhr.responseURL,
|
|
998
949
|
status: ah.proxyXhr.status,
|
|
@@ -1015,18 +966,16 @@ const ajaxHooker = function () {
|
|
|
1015
966
|
}
|
|
1016
967
|
);
|
|
1017
968
|
}
|
|
1018
|
-
ah.resThenable = new AHRequest(ah.request)
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
});
|
|
969
|
+
ah.resThenable = new AHRequest(ah.request).waitForResponseKeys(response).then(() => {
|
|
970
|
+
for (const key of xhrResponses) {
|
|
971
|
+
ah.proxyProps[key] = {
|
|
972
|
+
get: () => {
|
|
973
|
+
if (!(key in response)) response[key] = tempValues[key];
|
|
974
|
+
return response[key];
|
|
975
|
+
},
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
});
|
|
1030
979
|
}
|
|
1031
980
|
ah.dispatchEvent(e);
|
|
1032
981
|
});
|
|
@@ -1039,13 +988,7 @@ const ajaxHooker = function () {
|
|
|
1039
988
|
set: (val) => ah.addEvent(onEvt, val),
|
|
1040
989
|
};
|
|
1041
990
|
}
|
|
1042
|
-
for (const method of [
|
|
1043
|
-
"setRequestHeader",
|
|
1044
|
-
"addEventListener",
|
|
1045
|
-
"removeEventListener",
|
|
1046
|
-
"open",
|
|
1047
|
-
"send",
|
|
1048
|
-
]) {
|
|
991
|
+
for (const method of ["setRequestHeader", "addEventListener", "removeEventListener", "open", "send"]) {
|
|
1049
992
|
ah.proxyProps[method] = { value: ah[method] };
|
|
1050
993
|
}
|
|
1051
994
|
}
|
|
@@ -1054,8 +997,7 @@ const ajaxHooker = function () {
|
|
|
1054
997
|
if (type.startsWith("on")) {
|
|
1055
998
|
this.proxyEvents[type] = typeof event === "function" ? event : null;
|
|
1056
999
|
} else {
|
|
1057
|
-
if (typeof event === "object" && event !== null)
|
|
1058
|
-
event = event.handleEvent;
|
|
1000
|
+
if (typeof event === "object" && event !== null) event = event.handleEvent;
|
|
1059
1001
|
if (typeof event !== "function") return;
|
|
1060
1002
|
this.proxyEvents[type] = this.proxyEvents[type] || new Set();
|
|
1061
1003
|
this.proxyEvents[type].add(event);
|
|
@@ -1065,8 +1007,7 @@ const ajaxHooker = function () {
|
|
|
1065
1007
|
if (type.startsWith("on")) {
|
|
1066
1008
|
this.proxyEvents[type] = null;
|
|
1067
1009
|
} else {
|
|
1068
|
-
if (typeof event === "object" && event !== null)
|
|
1069
|
-
event = event.handleEvent;
|
|
1010
|
+
if (typeof event === "object" && event !== null) event = event.handleEvent;
|
|
1070
1011
|
this.proxyEvents[type] && this.proxyEvents[type].delete(event);
|
|
1071
1012
|
}
|
|
1072
1013
|
}
|
|
@@ -1077,9 +1018,7 @@ const ajaxHooker = function () {
|
|
|
1077
1018
|
defineProp(e, "srcElement", () => this.proxyXhr);
|
|
1078
1019
|
this.proxyEvents[e.type] &&
|
|
1079
1020
|
this.proxyEvents[e.type].forEach((fn) => {
|
|
1080
|
-
this.resThenable.then(
|
|
1081
|
-
() => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e)
|
|
1082
|
-
);
|
|
1021
|
+
this.resThenable.then(() => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e));
|
|
1083
1022
|
});
|
|
1084
1023
|
if (e.ajaxHooker_isStopped) return;
|
|
1085
1024
|
const onEvent = this.proxyEvents["on" + e.type];
|
|
@@ -1089,8 +1028,7 @@ const ajaxHooker = function () {
|
|
|
1089
1028
|
this.originalXhr.setRequestHeader(header, value);
|
|
1090
1029
|
if (!this.request) return;
|
|
1091
1030
|
const headers = this.request.headers;
|
|
1092
|
-
headers[header] =
|
|
1093
|
-
header in headers ? `${headers[header]}, ${value}` : value;
|
|
1031
|
+
headers[header] = header in headers ? `${headers[header]}, ${value}` : value;
|
|
1094
1032
|
}
|
|
1095
1033
|
addEventListener(...args) {
|
|
1096
1034
|
if (xhrAsyncEvents.includes(args[0])) {
|
|
@@ -1119,13 +1057,7 @@ const ajaxHooker = function () {
|
|
|
1119
1057
|
};
|
|
1120
1058
|
this.openArgs = args;
|
|
1121
1059
|
this.resThenable = new SyncThenable();
|
|
1122
|
-
[
|
|
1123
|
-
"responseURL",
|
|
1124
|
-
"readyState",
|
|
1125
|
-
"status",
|
|
1126
|
-
"statusText",
|
|
1127
|
-
...xhrResponses,
|
|
1128
|
-
].forEach((key) => {
|
|
1060
|
+
["responseURL", "readyState", "status", "statusText", ...xhrResponses].forEach((key) => {
|
|
1129
1061
|
delete this.proxyProps[key];
|
|
1130
1062
|
});
|
|
1131
1063
|
return this.originalXhr.open(method, url, async, ...args);
|
|
@@ -1162,15 +1094,12 @@ const ajaxHooker = function () {
|
|
|
1162
1094
|
}
|
|
1163
1095
|
function fakeXHR() {
|
|
1164
1096
|
const xhr = new winAh.realXHR();
|
|
1165
|
-
if ("__ajaxHooker" in xhr)
|
|
1166
|
-
console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
1097
|
+
if ("__ajaxHooker" in xhr) console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
1167
1098
|
xhr.__ajaxHooker = new XhrHooker(xhr);
|
|
1168
1099
|
return xhr.__ajaxHooker.proxyXhr;
|
|
1169
1100
|
}
|
|
1170
1101
|
fakeXHR.prototype = win.XMLHttpRequest.prototype;
|
|
1171
|
-
Object.keys(win.XMLHttpRequest).forEach(
|
|
1172
|
-
(key) => (fakeXHR[key] = win.XMLHttpRequest[key])
|
|
1173
|
-
);
|
|
1102
|
+
Object.keys(win.XMLHttpRequest).forEach((key) => (fakeXHR[key] = win.XMLHttpRequest[key]));
|
|
1174
1103
|
function fakeFetch(url, options = {}) {
|
|
1175
1104
|
if (!url) return winAh.realFetch.call(win, url, options);
|
|
1176
1105
|
return new Promise(async (resolve, reject) => {
|
|
@@ -1236,18 +1165,22 @@ const ajaxHooker = function () {
|
|
|
1236
1165
|
status: res.status,
|
|
1237
1166
|
responseHeaders: parseHeaders(res.headers),
|
|
1238
1167
|
};
|
|
1239
|
-
|
|
1240
|
-
(
|
|
1241
|
-
(
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1168
|
+
if (res.ok) {
|
|
1169
|
+
fetchResponses.forEach(
|
|
1170
|
+
(key) =>
|
|
1171
|
+
(res[key] = function () {
|
|
1172
|
+
if (key in response) return Promise.resolve(response[key]);
|
|
1173
|
+
return resProto[key].call(this).then((val) => {
|
|
1174
|
+
response[key] = val;
|
|
1175
|
+
return req
|
|
1176
|
+
.waitForResponseKeys(response)
|
|
1177
|
+
.then(() => (key in response ? response[key] : val));
|
|
1178
|
+
});
|
|
1179
|
+
})
|
|
1180
|
+
);
|
|
1181
|
+
} else {
|
|
1182
|
+
catchError(request.response, response);
|
|
1183
|
+
}
|
|
1251
1184
|
}
|
|
1252
1185
|
resolve(res);
|
|
1253
1186
|
}, reject);
|
|
@@ -1269,8 +1202,7 @@ const ajaxHooker = function () {
|
|
|
1269
1202
|
realFetchClone: resProto.clone,
|
|
1270
1203
|
hookInsts: new Set(),
|
|
1271
1204
|
};
|
|
1272
|
-
if (winAh.version !== version)
|
|
1273
|
-
console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
1205
|
+
if (winAh.version !== version) console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
1274
1206
|
win.XMLHttpRequest = winAh.fakeXHR;
|
|
1275
1207
|
win.fetch = winAh.fakeFetch;
|
|
1276
1208
|
resProto.clone = winAh.fakeFetchClone;
|
|
@@ -1278,37 +1210,25 @@ const ajaxHooker = function () {
|
|
|
1278
1210
|
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
1279
1211
|
class AHFunction extends Function {
|
|
1280
1212
|
call(thisArg, ...args) {
|
|
1281
|
-
if (
|
|
1282
|
-
thisArg &&
|
|
1283
|
-
thisArg.__ajaxHooker &&
|
|
1284
|
-
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
1285
|
-
) {
|
|
1213
|
+
if (thisArg && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
1286
1214
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
1287
1215
|
}
|
|
1288
1216
|
return Reflect.apply(this, thisArg, args);
|
|
1289
1217
|
}
|
|
1290
1218
|
apply(thisArg, args) {
|
|
1291
|
-
if (
|
|
1292
|
-
thisArg &&
|
|
1293
|
-
thisArg.__ajaxHooker &&
|
|
1294
|
-
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
1295
|
-
) {
|
|
1219
|
+
if (thisArg && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
1296
1220
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
1297
1221
|
}
|
|
1298
1222
|
return Reflect.apply(this, thisArg, args || []);
|
|
1299
1223
|
}
|
|
1300
1224
|
}
|
|
1301
1225
|
function hookSecsdk(csrf) {
|
|
1302
|
-
Object.setPrototypeOf(
|
|
1303
|
-
csrf.nativeXMLHttpRequestSetRequestHeader,
|
|
1304
|
-
AHFunction.prototype
|
|
1305
|
-
);
|
|
1226
|
+
Object.setPrototypeOf(csrf.nativeXMLHttpRequestSetRequestHeader, AHFunction.prototype);
|
|
1306
1227
|
Object.setPrototypeOf(csrf.nativeXMLHttpRequestOpen, AHFunction.prototype);
|
|
1307
1228
|
Object.setPrototypeOf(csrf.nativeXMLHttpRequestSend, AHFunction.prototype);
|
|
1308
1229
|
}
|
|
1309
1230
|
if (win.secsdk) {
|
|
1310
|
-
if (win.secsdk.csrf && win.secsdk.csrf.nativeXMLHttpRequestOpen)
|
|
1311
|
-
hookSecsdk(win.secsdk.csrf);
|
|
1231
|
+
if (win.secsdk.csrf && win.secsdk.csrf.nativeXMLHttpRequestOpen) hookSecsdk(win.secsdk.csrf);
|
|
1312
1232
|
} else {
|
|
1313
1233
|
defineProp(win, "secsdk", emptyFn, (secsdk) => {
|
|
1314
1234
|
delete win.secsdk;
|
|
@@ -1954,14 +1874,10 @@ class GMMenu {
|
|
|
1954
1874
|
// };
|
|
1955
1875
|
/* 点击菜单后触发callback后的网页是否刷新 */
|
|
1956
1876
|
menuOption.autoReload =
|
|
1957
|
-
typeof menuOption.autoReload !== "boolean"
|
|
1958
|
-
? this.$default.autoReload
|
|
1959
|
-
: menuOption.autoReload;
|
|
1877
|
+
typeof menuOption.autoReload !== "boolean" ? this.$default.autoReload : menuOption.autoReload;
|
|
1960
1878
|
/* 点击菜单后触发callback后的网页是否存储值 */
|
|
1961
1879
|
menuOption.isStoreValue =
|
|
1962
|
-
typeof menuOption.isStoreValue !== "boolean"
|
|
1963
|
-
? this.$default.isStoreValue
|
|
1964
|
-
: menuOption.isStoreValue;
|
|
1880
|
+
typeof menuOption.isStoreValue !== "boolean" ? this.$default.isStoreValue : menuOption.isStoreValue;
|
|
1965
1881
|
/**
|
|
1966
1882
|
* 用户点击菜单后的回调函数
|
|
1967
1883
|
* @param event
|
|
@@ -2014,8 +1930,7 @@ class GMMenu {
|
|
|
2014
1930
|
* @param menuKey 菜单-键key
|
|
2015
1931
|
*/
|
|
2016
1932
|
getMenuHandledOption(menuKey) {
|
|
2017
|
-
return this.$data.data.find((item) => item.handleData.key === menuKey)
|
|
2018
|
-
?.handleData;
|
|
1933
|
+
return this.$data.data.find((item) => item.handleData.key === menuKey)?.handleData;
|
|
2019
1934
|
},
|
|
2020
1935
|
};
|
|
2021
1936
|
constructor(details) {
|
|
@@ -2023,8 +1938,7 @@ class GMMenu {
|
|
|
2023
1938
|
this.GM_Api.setValue = details.GM_setValue;
|
|
2024
1939
|
this.GM_Api.registerMenuCommand = details.GM_registerMenuCommand;
|
|
2025
1940
|
this.GM_Api.unregisterMenuCommand = details.GM_unregisterMenuCommand;
|
|
2026
|
-
this.MenuHandle.$default.autoReload =
|
|
2027
|
-
typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
1941
|
+
this.MenuHandle.$default.autoReload = typeof details.autoReload === "boolean" ? details.autoReload : true;
|
|
2028
1942
|
for (const keyName of Object.keys(this.GM_Api)) {
|
|
2029
1943
|
if (typeof this.GM_Api[keyName] !== "function") {
|
|
2030
1944
|
throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
|
|
@@ -2256,8 +2170,7 @@ class Hooks {
|
|
|
2256
2170
|
_context = context || window;
|
|
2257
2171
|
_funcName = getFuncName(this);
|
|
2258
2172
|
_context["realFunc_" + _funcName] = this;
|
|
2259
|
-
if (_context[_funcName].prototype &&
|
|
2260
|
-
_context[_funcName].prototype.isHooked) {
|
|
2173
|
+
if (_context[_funcName].prototype && _context[_funcName].prototype.isHooked) {
|
|
2261
2174
|
console.log("Already has been hooked,unhook first");
|
|
2262
2175
|
return false;
|
|
2263
2176
|
}
|
|
@@ -2435,8 +2348,7 @@ class Httpx {
|
|
|
2435
2348
|
if (details.allowInterceptConfig != null) {
|
|
2436
2349
|
// 配置存在
|
|
2437
2350
|
// 细分处理是否拦截
|
|
2438
|
-
if (typeof details.allowInterceptConfig.afterResponseSuccess ===
|
|
2439
|
-
"boolean" &&
|
|
2351
|
+
if (typeof details.allowInterceptConfig.afterResponseSuccess === "boolean" &&
|
|
2440
2352
|
!details.allowInterceptConfig.afterResponseSuccess) {
|
|
2441
2353
|
// 设置了禁止拦截
|
|
2442
2354
|
return details;
|
|
@@ -2471,8 +2383,7 @@ class Httpx {
|
|
|
2471
2383
|
if (data.details.allowInterceptConfig != null) {
|
|
2472
2384
|
// 配置存在
|
|
2473
2385
|
// 细分处理是否拦截
|
|
2474
|
-
if (typeof data.details.allowInterceptConfig.afterResponseError ===
|
|
2475
|
-
"boolean" &&
|
|
2386
|
+
if (typeof data.details.allowInterceptConfig.afterResponseError === "boolean" &&
|
|
2476
2387
|
!data.details.allowInterceptConfig.afterResponseError) {
|
|
2477
2388
|
// 设置了禁止拦截
|
|
2478
2389
|
return data;
|
|
@@ -2574,44 +2485,31 @@ class Httpx {
|
|
|
2574
2485
|
let requestOption = {
|
|
2575
2486
|
url: url,
|
|
2576
2487
|
method: (method || "GET").toString().toUpperCase().trim(),
|
|
2577
|
-
timeout: userRequestOption.timeout ||
|
|
2578
|
-
|
|
2579
|
-
responseType: userRequestOption.responseType ||
|
|
2580
|
-
this.context.#defaultRequestOption.responseType,
|
|
2488
|
+
timeout: userRequestOption.timeout || this.context.#defaultRequestOption.timeout,
|
|
2489
|
+
responseType: userRequestOption.responseType || this.context.#defaultRequestOption.responseType,
|
|
2581
2490
|
/* 对象使用深拷贝 */
|
|
2582
2491
|
headers: commonUtil.deepClone(this.context.#defaultRequestOption.headers),
|
|
2583
2492
|
data: userRequestOption.data || this.context.#defaultRequestOption.data,
|
|
2584
|
-
redirect: userRequestOption.redirect ||
|
|
2585
|
-
this.context.#defaultRequestOption.redirect,
|
|
2493
|
+
redirect: userRequestOption.redirect || this.context.#defaultRequestOption.redirect,
|
|
2586
2494
|
cookie: userRequestOption.cookie || this.context.#defaultRequestOption.cookie,
|
|
2587
|
-
cookiePartition: userRequestOption.cookiePartition ||
|
|
2588
|
-
this.context.#defaultRequestOption.cookiePartition,
|
|
2495
|
+
cookiePartition: userRequestOption.cookiePartition || this.context.#defaultRequestOption.cookiePartition,
|
|
2589
2496
|
binary: userRequestOption.binary || this.context.#defaultRequestOption.binary,
|
|
2590
|
-
nocache: userRequestOption.nocache ||
|
|
2591
|
-
|
|
2592
|
-
revalidate: userRequestOption.revalidate ||
|
|
2593
|
-
this.context.#defaultRequestOption.revalidate,
|
|
2497
|
+
nocache: userRequestOption.nocache || this.context.#defaultRequestOption.nocache,
|
|
2498
|
+
revalidate: userRequestOption.revalidate || this.context.#defaultRequestOption.revalidate,
|
|
2594
2499
|
/* 对象使用深拷贝 */
|
|
2595
|
-
context: commonUtil.deepClone(userRequestOption.context ||
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
this.context.#defaultRequestOption.overrideMimeType,
|
|
2599
|
-
anonymous: userRequestOption.anonymous ||
|
|
2600
|
-
this.context.#defaultRequestOption.anonymous,
|
|
2500
|
+
context: commonUtil.deepClone(userRequestOption.context || this.context.#defaultRequestOption.context),
|
|
2501
|
+
overrideMimeType: userRequestOption.overrideMimeType || this.context.#defaultRequestOption.overrideMimeType,
|
|
2502
|
+
anonymous: userRequestOption.anonymous || this.context.#defaultRequestOption.anonymous,
|
|
2601
2503
|
fetch: userRequestOption.fetch || this.context.#defaultRequestOption.fetch,
|
|
2602
2504
|
/* 对象使用深拷贝 */
|
|
2603
2505
|
fetchInit: commonUtil.deepClone(this.context.#defaultRequestOption.fetchInit),
|
|
2604
2506
|
allowInterceptConfig: {
|
|
2605
|
-
beforeRequest: this.context.#defaultRequestOption
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
.allowInterceptConfig.afterResponseSuccess,
|
|
2609
|
-
afterResponseError: this.context.#defaultRequestOption
|
|
2610
|
-
.allowInterceptConfig.afterResponseError,
|
|
2507
|
+
beforeRequest: this.context.#defaultRequestOption.allowInterceptConfig.beforeRequest,
|
|
2508
|
+
afterResponseSuccess: this.context.#defaultRequestOption.allowInterceptConfig.afterResponseSuccess,
|
|
2509
|
+
afterResponseError: this.context.#defaultRequestOption.allowInterceptConfig.afterResponseError,
|
|
2611
2510
|
},
|
|
2612
2511
|
user: userRequestOption.user || this.context.#defaultRequestOption.user,
|
|
2613
|
-
password: userRequestOption.password ||
|
|
2614
|
-
this.context.#defaultRequestOption.password,
|
|
2512
|
+
password: userRequestOption.password || this.context.#defaultRequestOption.password,
|
|
2615
2513
|
onabort(...args) {
|
|
2616
2514
|
that.context.HttpxResponseCallBack.onAbort(userRequestOption, resolve, reject, args);
|
|
2617
2515
|
},
|
|
@@ -2659,14 +2557,12 @@ class Httpx {
|
|
|
2659
2557
|
if (typeof requestOption.headers === "object") {
|
|
2660
2558
|
if (typeof userRequestOption.headers === "object") {
|
|
2661
2559
|
Object.keys(userRequestOption.headers).forEach((keyName, index) => {
|
|
2662
|
-
if (keyName in requestOption.headers &&
|
|
2663
|
-
userRequestOption.headers?.[keyName] == null) {
|
|
2560
|
+
if (keyName in requestOption.headers && userRequestOption.headers?.[keyName] == null) {
|
|
2664
2561
|
/* 在默认的header中存在,且设置它新的值为空,那么就是默认的值 */
|
|
2665
2562
|
Reflect.deleteProperty(requestOption.headers, keyName);
|
|
2666
2563
|
}
|
|
2667
2564
|
else {
|
|
2668
|
-
requestOption.headers[keyName] =
|
|
2669
|
-
userRequestOption?.headers?.[keyName];
|
|
2565
|
+
requestOption.headers[keyName] = userRequestOption?.headers?.[keyName];
|
|
2670
2566
|
}
|
|
2671
2567
|
});
|
|
2672
2568
|
}
|
|
@@ -2679,8 +2575,7 @@ class Httpx {
|
|
|
2679
2575
|
/* 使用assign替换且添加 */
|
|
2680
2576
|
if (typeof userRequestOption.fetchInit === "object") {
|
|
2681
2577
|
Object.keys(userRequestOption.fetchInit).forEach((keyName, index) => {
|
|
2682
|
-
if (keyName in requestOption.fetchInit &&
|
|
2683
|
-
userRequestOption.fetchInit[keyName] == null) {
|
|
2578
|
+
if (keyName in requestOption.fetchInit && userRequestOption.fetchInit[keyName] == null) {
|
|
2684
2579
|
/* 在默认的fetchInit中存在,且设置它新的值为空,那么就是默认的值 */
|
|
2685
2580
|
Reflect.deleteProperty(requestOption.fetchInit, keyName);
|
|
2686
2581
|
}
|
|
@@ -2694,8 +2589,7 @@ class Httpx {
|
|
|
2694
2589
|
Reflect.set(requestOption, "fetchInit", userRequestOption.fetchInit);
|
|
2695
2590
|
}
|
|
2696
2591
|
// 处理新的cookiePartition
|
|
2697
|
-
if (typeof requestOption.cookiePartition === "object" &&
|
|
2698
|
-
requestOption.cookiePartition != null) {
|
|
2592
|
+
if (typeof requestOption.cookiePartition === "object" && requestOption.cookiePartition != null) {
|
|
2699
2593
|
if (Reflect.has(requestOption.cookiePartition, "topLevelSite") &&
|
|
2700
2594
|
typeof requestOption.cookiePartition.topLevelSite !== "string") {
|
|
2701
2595
|
// topLevelSite必须是字符串
|
|
@@ -2717,8 +2611,7 @@ class Httpx {
|
|
|
2717
2611
|
}
|
|
2718
2612
|
else {
|
|
2719
2613
|
// 补充origin+/
|
|
2720
|
-
requestOption.url =
|
|
2721
|
-
globalThis.location.origin + "/" + requestOption.url;
|
|
2614
|
+
requestOption.url = globalThis.location.origin + "/" + requestOption.url;
|
|
2722
2615
|
}
|
|
2723
2616
|
}
|
|
2724
2617
|
if (requestOption.fetchInit && !requestOption.fetch) {
|
|
@@ -2842,8 +2735,7 @@ class Httpx {
|
|
|
2842
2735
|
* fetch的请求配置
|
|
2843
2736
|
**/
|
|
2844
2737
|
let fetchRequestOption = {};
|
|
2845
|
-
if ((option.method === "GET" || option.method === "HEAD") &&
|
|
2846
|
-
option.data != null) {
|
|
2738
|
+
if ((option.method === "GET" || option.method === "HEAD") && option.data != null) {
|
|
2847
2739
|
/* GET 或 HEAD 方法的请求不能包含 body 信息 */
|
|
2848
2740
|
Reflect.deleteProperty(option, "data");
|
|
2849
2741
|
}
|
|
@@ -3124,8 +3016,7 @@ class Httpx {
|
|
|
3124
3016
|
if (typeof details?.onreadystatechange === "function") {
|
|
3125
3017
|
details.onreadystatechange.apply(this, argsResult);
|
|
3126
3018
|
}
|
|
3127
|
-
else if (typeof this.context.#defaultRequestOption?.onreadystatechange ===
|
|
3128
|
-
"function") {
|
|
3019
|
+
else if (typeof this.context.#defaultRequestOption?.onreadystatechange === "function") {
|
|
3129
3020
|
this.context.#defaultRequestOption.onreadystatechange.apply(this, argsResult);
|
|
3130
3021
|
}
|
|
3131
3022
|
},
|
|
@@ -3154,8 +3045,7 @@ class Httpx {
|
|
|
3154
3045
|
if (this.context.#defaultInitOption.logDetails) {
|
|
3155
3046
|
console.log("[Httpx-HttpxRequest.request] 请求前的配置👇", details);
|
|
3156
3047
|
}
|
|
3157
|
-
if (typeof this.context.HttpxRequestHook.beforeRequestCallBack ===
|
|
3158
|
-
"function") {
|
|
3048
|
+
if (typeof this.context.HttpxRequestHook.beforeRequestCallBack === "function") {
|
|
3159
3049
|
let hookResult = await this.context.HttpxRequestHook.beforeRequestCallBack(details);
|
|
3160
3050
|
if (hookResult == null) {
|
|
3161
3051
|
return;
|
|
@@ -3211,9 +3101,7 @@ class Httpx {
|
|
|
3211
3101
|
/* 如果需要stream,且获取到的是stream,那直接返回 */
|
|
3212
3102
|
if (option.responseType === "stream" ||
|
|
3213
3103
|
(fetchResponse.headers.has("Content-Type") &&
|
|
3214
|
-
fetchResponse.headers
|
|
3215
|
-
.get("Content-Type")
|
|
3216
|
-
.includes("text/event-stream"))) {
|
|
3104
|
+
fetchResponse.headers.get("Content-Type").includes("text/event-stream"))) {
|
|
3217
3105
|
Reflect.set(httpxResponse, "isStream", true);
|
|
3218
3106
|
Reflect.set(httpxResponse, "response", fetchResponse.body);
|
|
3219
3107
|
Reflect.deleteProperty(httpxResponse, "responseText");
|
|
@@ -3232,9 +3120,7 @@ class Httpx {
|
|
|
3232
3120
|
/** 数据编码 */
|
|
3233
3121
|
let encoding = "utf-8";
|
|
3234
3122
|
if (fetchResponse.headers.has("Content-Type")) {
|
|
3235
|
-
let charsetMatched = fetchResponse.headers
|
|
3236
|
-
.get("Content-Type")
|
|
3237
|
-
?.match(/charset=(.+)/);
|
|
3123
|
+
let charsetMatched = fetchResponse.headers.get("Content-Type")?.match(/charset=(.+)/);
|
|
3238
3124
|
if (charsetMatched) {
|
|
3239
3125
|
encoding = charsetMatched[1];
|
|
3240
3126
|
encoding = encoding.toLowerCase();
|
|
@@ -3256,13 +3142,11 @@ class Httpx {
|
|
|
3256
3142
|
response = new Blob([arrayBuffer]);
|
|
3257
3143
|
}
|
|
3258
3144
|
else if (option.responseType === "json" ||
|
|
3259
|
-
(typeof fetchResponseType === "string" &&
|
|
3260
|
-
fetchResponseType.includes("application/json"))) {
|
|
3145
|
+
(typeof fetchResponseType === "string" && fetchResponseType.includes("application/json"))) {
|
|
3261
3146
|
// response返回格式是JSON格式
|
|
3262
3147
|
response = commonUtil.toJSON(responseText);
|
|
3263
3148
|
}
|
|
3264
|
-
else if (option.responseType === "document" ||
|
|
3265
|
-
option.responseType == null) {
|
|
3149
|
+
else if (option.responseType === "document" || option.responseType == null) {
|
|
3266
3150
|
// response返回格式是文档格式
|
|
3267
3151
|
let parser = new DOMParser();
|
|
3268
3152
|
response = parser.parseFromString(responseText, "text/html");
|
|
@@ -3525,8 +3409,7 @@ class Httpx {
|
|
|
3525
3409
|
}
|
|
3526
3410
|
requestOption = this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
3527
3411
|
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
3528
|
-
if (requestResult != null &&
|
|
3529
|
-
typeof requestResult.abort === "function") {
|
|
3412
|
+
if (requestResult != null && typeof requestResult.abort === "function") {
|
|
3530
3413
|
abortFn = requestResult.abort;
|
|
3531
3414
|
}
|
|
3532
3415
|
});
|
|
@@ -4017,8 +3900,7 @@ class Log {
|
|
|
4017
3900
|
if (typeof __GM_info === "string") {
|
|
4018
3901
|
this.tag = __GM_info;
|
|
4019
3902
|
}
|
|
4020
|
-
else if (typeof __GM_info === "object" &&
|
|
4021
|
-
typeof __GM_info?.script?.name === "string") {
|
|
3903
|
+
else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
|
|
4022
3904
|
this.tag = __GM_info.script.name;
|
|
4023
3905
|
}
|
|
4024
3906
|
this.#console = console;
|
|
@@ -4074,8 +3956,7 @@ class Log {
|
|
|
4074
3956
|
*/
|
|
4075
3957
|
checkClearConsole() {
|
|
4076
3958
|
this.#logCount++;
|
|
4077
|
-
if (this.#details.autoClearConsole &&
|
|
4078
|
-
this.#logCount > this.#details.logMaxCount) {
|
|
3959
|
+
if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
|
|
4079
3960
|
this.#console.clear();
|
|
4080
3961
|
this.#logCount = 0;
|
|
4081
3962
|
}
|
|
@@ -4484,6 +4365,10 @@ class WindowApi {
|
|
|
4484
4365
|
globalThis: globalThis,
|
|
4485
4366
|
self: self,
|
|
4486
4367
|
top: top,
|
|
4368
|
+
setTimeout: globalThis.setTimeout,
|
|
4369
|
+
setInterval: globalThis.setInterval,
|
|
4370
|
+
clearTimeout: globalThis.clearTimeout,
|
|
4371
|
+
clearInterval: globalThis.clearInterval,
|
|
4487
4372
|
};
|
|
4488
4373
|
/** 使用的配置 */
|
|
4489
4374
|
api;
|
|
@@ -4516,6 +4401,18 @@ class WindowApi {
|
|
|
4516
4401
|
get top() {
|
|
4517
4402
|
return this.api.top;
|
|
4518
4403
|
}
|
|
4404
|
+
get setTimeout() {
|
|
4405
|
+
return this.api.setTimeout;
|
|
4406
|
+
}
|
|
4407
|
+
get setInterval() {
|
|
4408
|
+
return this.api.setInterval;
|
|
4409
|
+
}
|
|
4410
|
+
get clearTimeout() {
|
|
4411
|
+
return this.api.clearTimeout;
|
|
4412
|
+
}
|
|
4413
|
+
get clearInterval() {
|
|
4414
|
+
return this.api.clearInterval;
|
|
4415
|
+
}
|
|
4519
4416
|
}
|
|
4520
4417
|
|
|
4521
4418
|
const VueUtils = {
|
|
@@ -4991,7 +4888,7 @@ const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
|
4991
4888
|
};
|
|
4992
4889
|
|
|
4993
4890
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
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,(
|
|
4891
|
+
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
|
|
4995
4892
|
|
|
4996
4893
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
4997
4894
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -5578,7 +5475,7 @@ class Utils {
|
|
|
5578
5475
|
this.windowApi = new WindowApi(option);
|
|
5579
5476
|
}
|
|
5580
5477
|
/** 版本号 */
|
|
5581
|
-
version = "2025.
|
|
5478
|
+
version = "2025.8.21";
|
|
5582
5479
|
addStyle(cssText) {
|
|
5583
5480
|
if (typeof cssText !== "string") {
|
|
5584
5481
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5701,13 +5598,9 @@ class Utils {
|
|
|
5701
5598
|
let touchEvent = UtilsContext.windowApi.window.event;
|
|
5702
5599
|
let $click = clickEvent?.composedPath()?.[0];
|
|
5703
5600
|
// 点击的x坐标
|
|
5704
|
-
let clickPosX = clickEvent?.clientX != null
|
|
5705
|
-
? clickEvent.clientX
|
|
5706
|
-
: touchEvent.touches[0].clientX;
|
|
5601
|
+
let clickPosX = clickEvent?.clientX != null ? clickEvent.clientX : touchEvent.touches[0].clientX;
|
|
5707
5602
|
// 点击的y坐标
|
|
5708
|
-
let clickPosY = clickEvent?.clientY != null
|
|
5709
|
-
? clickEvent.clientY
|
|
5710
|
-
: touchEvent.touches[0].clientY;
|
|
5603
|
+
let clickPosY = clickEvent?.clientY != null ? clickEvent.clientY : touchEvent.touches[0].clientY;
|
|
5711
5604
|
let {
|
|
5712
5605
|
/* 要检测的元素的相对屏幕的横坐标最左边 */
|
|
5713
5606
|
left: elementPosXLeft,
|
|
@@ -5870,9 +5763,7 @@ class Utils {
|
|
|
5870
5763
|
/* CODE FOR BROWSERS THAT SUPPORT window.find */
|
|
5871
5764
|
let windowFind = this.windowApi.self.find;
|
|
5872
5765
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
5873
|
-
if (strFound &&
|
|
5874
|
-
this.windowApi.self.getSelection &&
|
|
5875
|
-
!this.windowApi.self.getSelection().anchorNode) {
|
|
5766
|
+
if (strFound && this.windowApi.self.getSelection && !this.windowApi.self.getSelection().anchorNode) {
|
|
5876
5767
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
5877
5768
|
}
|
|
5878
5769
|
if (!strFound) {
|
|
@@ -5975,9 +5866,7 @@ class Utils {
|
|
|
5975
5866
|
}
|
|
5976
5867
|
}
|
|
5977
5868
|
result = result.toFixed(2);
|
|
5978
|
-
result = addType
|
|
5979
|
-
? result + resultType.toString()
|
|
5980
|
-
: parseFloat(result.toString());
|
|
5869
|
+
result = addType ? result + resultType.toString() : parseFloat(result.toString());
|
|
5981
5870
|
return result;
|
|
5982
5871
|
}
|
|
5983
5872
|
getNodeListValue(...args) {
|
|
@@ -6056,14 +5945,7 @@ class Utils {
|
|
|
6056
5945
|
if (text.length === 8) {
|
|
6057
5946
|
/* 该字符串只有时分秒 */
|
|
6058
5947
|
let today = new Date();
|
|
6059
|
-
text =
|
|
6060
|
-
today.getFullYear() +
|
|
6061
|
-
"-" +
|
|
6062
|
-
(today.getMonth() + 1) +
|
|
6063
|
-
"-" +
|
|
6064
|
-
today.getDate() +
|
|
6065
|
-
" " +
|
|
6066
|
-
text;
|
|
5948
|
+
text = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + " " + text;
|
|
6067
5949
|
}
|
|
6068
5950
|
text = text.substring(0, 19);
|
|
6069
5951
|
text = text.replace(/-/g, "/");
|
|
@@ -6084,25 +5966,13 @@ class Utils {
|
|
|
6084
5966
|
* 获取 transitionend 的在各个浏览器的兼容名
|
|
6085
5967
|
*/
|
|
6086
5968
|
getTransitionEndNameList() {
|
|
6087
|
-
return [
|
|
6088
|
-
"webkitTransitionEnd",
|
|
6089
|
-
"mozTransitionEnd",
|
|
6090
|
-
"MSTransitionEnd",
|
|
6091
|
-
"otransitionend",
|
|
6092
|
-
"transitionend",
|
|
6093
|
-
];
|
|
5969
|
+
return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
|
|
6094
5970
|
}
|
|
6095
5971
|
/**
|
|
6096
5972
|
* 获取 animationend 的在各个浏览器的兼容名
|
|
6097
5973
|
*/
|
|
6098
5974
|
getAnimationEndNameList() {
|
|
6099
|
-
return [
|
|
6100
|
-
"webkitAnimationEnd",
|
|
6101
|
-
"mozAnimationEnd",
|
|
6102
|
-
"MSAnimationEnd",
|
|
6103
|
-
"oanimationend",
|
|
6104
|
-
"animationend",
|
|
6105
|
-
];
|
|
5975
|
+
return ["webkitAnimationEnd", "mozAnimationEnd", "MSAnimationEnd", "oanimationend", "animationend"];
|
|
6106
5976
|
}
|
|
6107
5977
|
getArrayLastValue(targetObj) {
|
|
6108
5978
|
return targetObj[targetObj.length - 1];
|
|
@@ -6206,10 +6076,8 @@ class Utils {
|
|
|
6206
6076
|
}
|
|
6207
6077
|
/* 如果有多个相同类型的兄弟元素,则需要添加索引 */
|
|
6208
6078
|
if (element.parentElement.querySelectorAll(element.tagName).length > 1) {
|
|
6209
|
-
let index = Array.prototype.indexOf.call(element.parentElement.children, element) +
|
|
6210
|
-
|
|
6211
|
-
selector +=
|
|
6212
|
-
" > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
|
|
6079
|
+
let index = Array.prototype.indexOf.call(element.parentElement.children, element) + 1;
|
|
6080
|
+
selector += " > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
|
|
6213
6081
|
}
|
|
6214
6082
|
else {
|
|
6215
6083
|
selector += " > " + element.tagName.toLowerCase();
|
|
@@ -6229,9 +6097,7 @@ class Utils {
|
|
|
6229
6097
|
return void 0;
|
|
6230
6098
|
}
|
|
6231
6099
|
if (result.length > 1) {
|
|
6232
|
-
if (result.length === 2 &&
|
|
6233
|
-
typeof result[0] === "object" &&
|
|
6234
|
-
typeof result[1] === "function") {
|
|
6100
|
+
if (result.length === 2 && typeof result[0] === "object" && typeof result[1] === "function") {
|
|
6235
6101
|
let data = result[0];
|
|
6236
6102
|
let handleDataFunc = result[1];
|
|
6237
6103
|
Object.keys(data).forEach((keyName) => {
|
|
@@ -6329,9 +6195,7 @@ class Utils {
|
|
|
6329
6195
|
return void 0;
|
|
6330
6196
|
}
|
|
6331
6197
|
if (result.length > 1) {
|
|
6332
|
-
if (result.length === 2 &&
|
|
6333
|
-
typeof result[0] === "object" &&
|
|
6334
|
-
typeof result[1] === "function") {
|
|
6198
|
+
if (result.length === 2 && typeof result[0] === "object" && typeof result[1] === "function") {
|
|
6335
6199
|
let data = result[0];
|
|
6336
6200
|
let handleDataFunc = result[1];
|
|
6337
6201
|
Object.keys(data).forEach((keyName) => {
|
|
@@ -6421,12 +6285,10 @@ class Utils {
|
|
|
6421
6285
|
getRandomValue(...args) {
|
|
6422
6286
|
let result = [...args];
|
|
6423
6287
|
if (result.length > 1) {
|
|
6424
|
-
if (result.length === 2 &&
|
|
6425
|
-
typeof result[0] === "number" &&
|
|
6426
|
-
typeof result[1] === "number") {
|
|
6288
|
+
if (result.length === 2 && typeof result[0] === "number" && typeof result[1] === "number") {
|
|
6427
6289
|
let leftNumber = result[0] > result[1] ? result[1] : result[0];
|
|
6428
6290
|
let rightNumber = result[0] > result[1] ? result[0] : result[1];
|
|
6429
|
-
return
|
|
6291
|
+
return Math.round(Math.random() * (rightNumber - leftNumber)) + leftNumber;
|
|
6430
6292
|
}
|
|
6431
6293
|
else {
|
|
6432
6294
|
return result[Math.floor(Math.random() * result.length)];
|
|
@@ -6437,8 +6299,7 @@ class Utils {
|
|
|
6437
6299
|
if (Array.isArray(paramData)) {
|
|
6438
6300
|
return paramData[Math.floor(Math.random() * paramData.length)];
|
|
6439
6301
|
}
|
|
6440
|
-
else if (typeof paramData === "object" &&
|
|
6441
|
-
Object.keys(paramData).length > 0) {
|
|
6302
|
+
else if (typeof paramData === "object" && Object.keys(paramData).length > 0) {
|
|
6442
6303
|
let paramObjDataKey = Object.keys(paramData)[Math.floor(Math.random() * Object.keys(paramData).length)];
|
|
6443
6304
|
return paramData[paramObjDataKey];
|
|
6444
6305
|
}
|
|
@@ -6745,11 +6606,9 @@ class Utils {
|
|
|
6745
6606
|
let nearBottomHeight = 50;
|
|
6746
6607
|
let checkWindow = () => {
|
|
6747
6608
|
// 已滚动的距离
|
|
6748
|
-
let scrollTop = this.windowApi.window.pageYOffset ||
|
|
6749
|
-
this.windowApi.document.documentElement.scrollTop;
|
|
6609
|
+
let scrollTop = this.windowApi.window.pageYOffset || this.windowApi.document.documentElement.scrollTop;
|
|
6750
6610
|
// 视窗高度
|
|
6751
|
-
let viewportHeight = this.windowApi.window.innerHeight ||
|
|
6752
|
-
this.windowApi.document.documentElement.clientHeight;
|
|
6611
|
+
let viewportHeight = this.windowApi.window.innerHeight || this.windowApi.document.documentElement.clientHeight;
|
|
6753
6612
|
// 最大滚动距离
|
|
6754
6613
|
let maxScrollHeight = this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
|
|
6755
6614
|
return scrollTop + viewportHeight >= maxScrollHeight;
|
|
@@ -7038,8 +6897,7 @@ class Utils {
|
|
|
7038
6897
|
**/
|
|
7039
6898
|
isNull = commonUtil.isNull.bind(commonUtil);
|
|
7040
6899
|
isThemeDark() {
|
|
7041
|
-
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
7042
|
-
.matches;
|
|
6900
|
+
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
7043
6901
|
}
|
|
7044
6902
|
/**
|
|
7045
6903
|
* 判断元素是否在页面中可见
|
|
@@ -7072,10 +6930,8 @@ class Utils {
|
|
|
7072
6930
|
else {
|
|
7073
6931
|
let domClientRect = domItem.getBoundingClientRect();
|
|
7074
6932
|
if (inView) {
|
|
7075
|
-
let viewportWidth = this.windowApi.window.innerWidth ||
|
|
7076
|
-
|
|
7077
|
-
let viewportHeight = this.windowApi.window.innerHeight ||
|
|
7078
|
-
this.windowApi.document.documentElement.clientHeight;
|
|
6933
|
+
let viewportWidth = this.windowApi.window.innerWidth || this.windowApi.document.documentElement.clientWidth;
|
|
6934
|
+
let viewportHeight = this.windowApi.window.innerHeight || this.windowApi.document.documentElement.clientHeight;
|
|
7079
6935
|
result = !(domClientRect.right < 0 ||
|
|
7080
6936
|
domClientRect.left > viewportWidth ||
|
|
7081
6937
|
domClientRect.bottom < 0 ||
|
|
@@ -7099,8 +6955,7 @@ class Utils {
|
|
|
7099
6955
|
for (const key in Object.values(this.windowApi.top.window.via)) {
|
|
7100
6956
|
if (Reflect.has(this.windowApi.top.window.via, key)) {
|
|
7101
6957
|
let objValueFunc = this.windowApi.top.window.via[key];
|
|
7102
|
-
if (typeof objValueFunc === "function" &&
|
|
7103
|
-
UtilsContext.isNativeFunc(objValueFunc)) {
|
|
6958
|
+
if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
|
|
7104
6959
|
result = true;
|
|
7105
6960
|
}
|
|
7106
6961
|
else {
|
|
@@ -7122,8 +6977,7 @@ class Utils {
|
|
|
7122
6977
|
for (const key in Object.values(this.windowApi.top.window.mbrowser)) {
|
|
7123
6978
|
if (Reflect.has(this.windowApi.top.window.mbrowser, key)) {
|
|
7124
6979
|
let objValueFunc = this.windowApi.top.window.mbrowser[key];
|
|
7125
|
-
if (typeof objValueFunc === "function" &&
|
|
7126
|
-
UtilsContext.isNativeFunc(objValueFunc)) {
|
|
6980
|
+
if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
|
|
7127
6981
|
result = true;
|
|
7128
6982
|
}
|
|
7129
6983
|
else {
|
|
@@ -7360,13 +7214,11 @@ class Utils {
|
|
|
7360
7214
|
* 释放所有
|
|
7361
7215
|
*/
|
|
7362
7216
|
function releaseAll() {
|
|
7363
|
-
if (typeof UtilsContext.windowApi.window[needReleaseKey] !==
|
|
7364
|
-
"undefined") {
|
|
7217
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] !== "undefined") {
|
|
7365
7218
|
/* 已存在 */
|
|
7366
7219
|
return;
|
|
7367
7220
|
}
|
|
7368
|
-
UtilsContext.windowApi.window[needReleaseKey] =
|
|
7369
|
-
UtilsContext.deepClone(needReleaseObject);
|
|
7221
|
+
UtilsContext.windowApi.window[needReleaseKey] = UtilsContext.deepClone(needReleaseObject);
|
|
7370
7222
|
Object.values(needReleaseObject).forEach((value) => {
|
|
7371
7223
|
if (typeof value === "function") {
|
|
7372
7224
|
needReleaseObject[value.name] = () => { };
|
|
@@ -7380,8 +7232,7 @@ class Utils {
|
|
|
7380
7232
|
Array.from(functionNameList).forEach((item) => {
|
|
7381
7233
|
Object.values(needReleaseObject).forEach((value) => {
|
|
7382
7234
|
if (typeof value === "function") {
|
|
7383
|
-
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
7384
|
-
"undefined") {
|
|
7235
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
|
|
7385
7236
|
UtilsContext.windowApi.window[needReleaseKey] = {};
|
|
7386
7237
|
}
|
|
7387
7238
|
if (item === value.name) {
|
|
@@ -7396,8 +7247,7 @@ class Utils {
|
|
|
7396
7247
|
* 恢复所有
|
|
7397
7248
|
*/
|
|
7398
7249
|
function recoveryAll() {
|
|
7399
|
-
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
7400
|
-
"undefined") {
|
|
7250
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
|
|
7401
7251
|
/* 未存在 */
|
|
7402
7252
|
return;
|
|
7403
7253
|
}
|
|
@@ -7408,8 +7258,7 @@ class Utils {
|
|
|
7408
7258
|
* 恢复单个
|
|
7409
7259
|
*/
|
|
7410
7260
|
function recoveryOne() {
|
|
7411
|
-
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
7412
|
-
"undefined") {
|
|
7261
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
|
|
7413
7262
|
/* 未存在 */
|
|
7414
7263
|
return;
|
|
7415
7264
|
}
|
|
@@ -7417,8 +7266,7 @@ class Utils {
|
|
|
7417
7266
|
if (UtilsContext.windowApi.window[needReleaseKey][item]) {
|
|
7418
7267
|
needReleaseObject[item] = UtilsContext.windowApi.window[needReleaseKey][item];
|
|
7419
7268
|
Reflect.deleteProperty(UtilsContext.windowApi.window[needReleaseKey], item);
|
|
7420
|
-
if (Object.keys(UtilsContext.windowApi.window[needReleaseKey])
|
|
7421
|
-
.length === 0) {
|
|
7269
|
+
if (Object.keys(UtilsContext.windowApi.window[needReleaseKey]).length === 0) {
|
|
7422
7270
|
Reflect.deleteProperty(window, needReleaseKey);
|
|
7423
7271
|
}
|
|
7424
7272
|
}
|
|
@@ -7675,8 +7523,7 @@ class Utils {
|
|
|
7675
7523
|
let copyStatus = false;
|
|
7676
7524
|
let requestPermissionStatus = await this.requestClipboardPermission();
|
|
7677
7525
|
console.log(requestPermissionStatus);
|
|
7678
|
-
if (this.hasClipboard() &&
|
|
7679
|
-
(this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
7526
|
+
if (this.hasClipboard() && (this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
7680
7527
|
try {
|
|
7681
7528
|
copyStatus = await this.copyDataByClipboard();
|
|
7682
7529
|
}
|
|
@@ -7837,11 +7684,8 @@ class Utils {
|
|
|
7837
7684
|
mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
|
|
7838
7685
|
return mouseEvent;
|
|
7839
7686
|
}
|
|
7840
|
-
let sliderElement = typeof selector === "string"
|
|
7841
|
-
|
|
7842
|
-
: selector;
|
|
7843
|
-
if (!(sliderElement instanceof Node) ||
|
|
7844
|
-
!(sliderElement instanceof Element)) {
|
|
7687
|
+
let sliderElement = typeof selector === "string" ? domUtils.selector(selector) : selector;
|
|
7688
|
+
if (!(sliderElement instanceof Node) || !(sliderElement instanceof Element)) {
|
|
7845
7689
|
throw new Error("Utils.dragSlider 参数selector 必须为Node/Element类型");
|
|
7846
7690
|
}
|
|
7847
7691
|
let rect = sliderElement.getBoundingClientRect(), x0 = rect.x || rect.left, y0 = rect.y || rect.top, x1 = x0 + offsetX, y1 = y0;
|
|
@@ -7893,17 +7737,14 @@ class Utils {
|
|
|
7893
7737
|
}
|
|
7894
7738
|
sortListByProperty(data, getPropertyValueFunc, sortByDesc = true) {
|
|
7895
7739
|
let UtilsContext = this;
|
|
7896
|
-
if (typeof getPropertyValueFunc !== "function" &&
|
|
7897
|
-
typeof getPropertyValueFunc !== "string") {
|
|
7740
|
+
if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
|
|
7898
7741
|
throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
|
|
7899
7742
|
}
|
|
7900
7743
|
if (typeof sortByDesc !== "boolean") {
|
|
7901
7744
|
throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
|
|
7902
7745
|
}
|
|
7903
7746
|
let getObjValue = function (obj) {
|
|
7904
|
-
return typeof getPropertyValueFunc === "string"
|
|
7905
|
-
? obj[getPropertyValueFunc]
|
|
7906
|
-
: getPropertyValueFunc(obj);
|
|
7747
|
+
return typeof getPropertyValueFunc === "string" ? obj[getPropertyValueFunc] : getPropertyValueFunc(obj);
|
|
7907
7748
|
};
|
|
7908
7749
|
/**
|
|
7909
7750
|
* 排序方法
|
|
@@ -7978,8 +7819,7 @@ class Utils {
|
|
|
7978
7819
|
if (Array.isArray(data)) {
|
|
7979
7820
|
data.sort(sortFunc);
|
|
7980
7821
|
}
|
|
7981
|
-
else if (data instanceof NodeList ||
|
|
7982
|
-
UtilsContext.isJQuery(data)) {
|
|
7822
|
+
else if (data instanceof NodeList || UtilsContext.isJQuery(data)) {
|
|
7983
7823
|
sortNodeFunc(data, getDataFunc);
|
|
7984
7824
|
result = getDataFunc();
|
|
7985
7825
|
}
|
|
@@ -8172,9 +8012,7 @@ class Utils {
|
|
|
8172
8012
|
let parent = UtilsContext.windowApi.document;
|
|
8173
8013
|
// 超时时间
|
|
8174
8014
|
let timeout = 0;
|
|
8175
|
-
if (typeof args[0] !== "string" &&
|
|
8176
|
-
!Array.isArray(args[0]) &&
|
|
8177
|
-
typeof args[0] !== "function") {
|
|
8015
|
+
if (typeof args[0] !== "string" && !Array.isArray(args[0]) && typeof args[0] !== "function") {
|
|
8178
8016
|
throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
|
|
8179
8017
|
}
|
|
8180
8018
|
if (args.length === 1) ;
|
|
@@ -8184,8 +8022,7 @@ class Utils {
|
|
|
8184
8022
|
// "div",10000
|
|
8185
8023
|
timeout = secondParam;
|
|
8186
8024
|
}
|
|
8187
|
-
else if (typeof secondParam === "object" &&
|
|
8188
|
-
secondParam instanceof Node) {
|
|
8025
|
+
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8189
8026
|
// "div",document
|
|
8190
8027
|
parent = secondParam;
|
|
8191
8028
|
}
|
|
@@ -8271,8 +8108,7 @@ class Utils {
|
|
|
8271
8108
|
// "div",10000
|
|
8272
8109
|
timeout = secondParam;
|
|
8273
8110
|
}
|
|
8274
|
-
else if (typeof secondParam === "object" &&
|
|
8275
|
-
secondParam instanceof Node) {
|
|
8111
|
+
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8276
8112
|
// "div",document
|
|
8277
8113
|
parent = secondParam;
|
|
8278
8114
|
}
|
|
@@ -8327,8 +8163,7 @@ class Utils {
|
|
|
8327
8163
|
// "div",10000
|
|
8328
8164
|
timeout = secondParam;
|
|
8329
8165
|
}
|
|
8330
|
-
else if (typeof secondParam === "object" &&
|
|
8331
|
-
secondParam instanceof Node) {
|
|
8166
|
+
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8332
8167
|
// "div",document
|
|
8333
8168
|
parent = secondParam;
|
|
8334
8169
|
}
|
|
@@ -8414,8 +8249,7 @@ class Utils {
|
|
|
8414
8249
|
// "div",10000
|
|
8415
8250
|
timeout = secondParam;
|
|
8416
8251
|
}
|
|
8417
|
-
else if (typeof secondParam === "object" &&
|
|
8418
|
-
secondParam instanceof Node) {
|
|
8252
|
+
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8419
8253
|
// "div",document
|
|
8420
8254
|
parent = secondParam;
|
|
8421
8255
|
}
|
|
@@ -8548,8 +8382,7 @@ class Utils {
|
|
|
8548
8382
|
return flag;
|
|
8549
8383
|
}
|
|
8550
8384
|
watchObject(target, propertyName, getCallBack, setCallBack) {
|
|
8551
|
-
if (typeof getCallBack !== "function" &&
|
|
8552
|
-
typeof setCallBack !== "function") {
|
|
8385
|
+
if (typeof getCallBack !== "function" && typeof setCallBack !== "function") {
|
|
8553
8386
|
return;
|
|
8554
8387
|
}
|
|
8555
8388
|
if (typeof getCallBack === "function") {
|
|
@@ -8601,13 +8434,27 @@ class Utils {
|
|
|
8601
8434
|
return;
|
|
8602
8435
|
}
|
|
8603
8436
|
let handleResult = handler(target);
|
|
8604
|
-
if (handleResult &&
|
|
8605
|
-
typeof handleResult.isFind === "boolean" &&
|
|
8606
|
-
handleResult.isFind) {
|
|
8437
|
+
if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) {
|
|
8607
8438
|
return handleResult.data;
|
|
8608
8439
|
}
|
|
8609
8440
|
return this.queryProperty(handleResult.data, handler);
|
|
8610
8441
|
}
|
|
8442
|
+
/**
|
|
8443
|
+
* 异步-深度获取对象属性
|
|
8444
|
+
* @param target 待获取的对象
|
|
8445
|
+
* @param handler 获取属性的回调
|
|
8446
|
+
*/
|
|
8447
|
+
async asyncQueryProperty(target, handler) {
|
|
8448
|
+
if (target == null) {
|
|
8449
|
+
// @ts-ignore
|
|
8450
|
+
return;
|
|
8451
|
+
}
|
|
8452
|
+
let handleResult = await handler(target);
|
|
8453
|
+
if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) {
|
|
8454
|
+
return handleResult.data;
|
|
8455
|
+
}
|
|
8456
|
+
return await this.asyncQueryProperty(handleResult.data, handler);
|
|
8457
|
+
}
|
|
8611
8458
|
/**
|
|
8612
8459
|
* 创建一个新的Utils实例
|
|
8613
8460
|
* @param option
|
|
@@ -8712,7 +8559,7 @@ class Utils {
|
|
|
8712
8559
|
return setTimeout$1(callback, timeout);
|
|
8713
8560
|
}
|
|
8714
8561
|
catch (error) {
|
|
8715
|
-
return
|
|
8562
|
+
return this.windowApi.setTimeout(callback, timeout);
|
|
8716
8563
|
}
|
|
8717
8564
|
}
|
|
8718
8565
|
/**
|
|
@@ -8728,7 +8575,7 @@ class Utils {
|
|
|
8728
8575
|
catch (error) {
|
|
8729
8576
|
}
|
|
8730
8577
|
finally {
|
|
8731
|
-
|
|
8578
|
+
this.windowApi.clearTimeout(timeId);
|
|
8732
8579
|
}
|
|
8733
8580
|
}
|
|
8734
8581
|
/**
|
|
@@ -8741,7 +8588,7 @@ class Utils {
|
|
|
8741
8588
|
return setInterval(callback, timeout);
|
|
8742
8589
|
}
|
|
8743
8590
|
catch (error) {
|
|
8744
|
-
return
|
|
8591
|
+
return this.windowApi.setInterval(callback, timeout);
|
|
8745
8592
|
}
|
|
8746
8593
|
}
|
|
8747
8594
|
/**
|
|
@@ -8757,7 +8604,7 @@ class Utils {
|
|
|
8757
8604
|
catch (error) {
|
|
8758
8605
|
}
|
|
8759
8606
|
finally {
|
|
8760
|
-
|
|
8607
|
+
this.windowApi.clearInterval(timeId);
|
|
8761
8608
|
}
|
|
8762
8609
|
}
|
|
8763
8610
|
/**
|