@whitesev/utils 2.7.0 → 2.7.1
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 +37 -23
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +37 -23
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +37 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +37 -23
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +37 -23
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +37 -23
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/Utils.ts +2 -2
- package/src/ajaxHooker/ajaxHooker.js +35 -21
package/dist/index.system.js
CHANGED
|
@@ -751,13 +751,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
751
751
|
// ==UserScript==
|
|
752
752
|
// @name ajaxHooker
|
|
753
753
|
// @author cxxjackie
|
|
754
|
-
// @version 1.4.
|
|
754
|
+
// @version 1.4.7
|
|
755
755
|
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
756
756
|
// @license GNU LGPL-3.0
|
|
757
757
|
// ==/UserScript==
|
|
758
758
|
|
|
759
759
|
const ajaxHooker = function () {
|
|
760
|
-
const version = "1.4.
|
|
760
|
+
const version = "1.4.7";
|
|
761
761
|
const hookInst = {
|
|
762
762
|
hookFns: [],
|
|
763
763
|
filters: [],
|
|
@@ -767,20 +767,18 @@ System.register('Utils', [], (function (exports) {
|
|
|
767
767
|
const resProto = win.Response.prototype;
|
|
768
768
|
const xhrResponses = ["response", "responseText", "responseXML"];
|
|
769
769
|
const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
"headers",
|
|
773
|
-
"body",
|
|
774
|
-
"mode",
|
|
775
|
-
"credentials",
|
|
770
|
+
const xhrExtraProps = ["responseType", "timeout", "withCredentials"];
|
|
771
|
+
const fetchExtraProps = [
|
|
776
772
|
"cache",
|
|
773
|
+
"credentials",
|
|
774
|
+
"integrity",
|
|
775
|
+
"keepalive",
|
|
776
|
+
"mode",
|
|
777
|
+
"priority",
|
|
777
778
|
"redirect",
|
|
778
779
|
"referrer",
|
|
779
780
|
"referrerPolicy",
|
|
780
|
-
"integrity",
|
|
781
|
-
"keepalive",
|
|
782
781
|
"signal",
|
|
783
|
-
"priority",
|
|
784
782
|
];
|
|
785
783
|
const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
|
|
786
784
|
const getType = {}.toString.call.bind({}.toString);
|
|
@@ -858,6 +856,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
858
856
|
this.request = request;
|
|
859
857
|
this.requestClone = { ...this.request };
|
|
860
858
|
}
|
|
859
|
+
_recoverRequestKey(key) {
|
|
860
|
+
if (key in this.requestClone) this.request[key] = this.requestClone[key];
|
|
861
|
+
else delete this.request[key];
|
|
862
|
+
}
|
|
861
863
|
shouldFilter(filters) {
|
|
862
864
|
const { type, url, method, async } = this.request;
|
|
863
865
|
return (
|
|
@@ -878,7 +880,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
878
880
|
);
|
|
879
881
|
}
|
|
880
882
|
waitForRequestKeys() {
|
|
881
|
-
const requestKeys = ["url", "method", "abort", "headers", "data"];
|
|
882
883
|
if (!this.request.async) {
|
|
883
884
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
884
885
|
if (this.shouldFilter(filters)) return;
|
|
@@ -886,27 +887,31 @@ System.register('Utils', [], (function (exports) {
|
|
|
886
887
|
if (getType(fn) === "[object Function]")
|
|
887
888
|
catchError(fn, this.request);
|
|
888
889
|
});
|
|
889
|
-
|
|
890
|
-
if (isThenable(this.request[key]))
|
|
891
|
-
|
|
892
|
-
});
|
|
890
|
+
for (const key in this.request) {
|
|
891
|
+
if (isThenable(this.request[key])) this._recoverRequestKey(key);
|
|
892
|
+
}
|
|
893
893
|
});
|
|
894
894
|
return new SyncThenable();
|
|
895
895
|
}
|
|
896
896
|
const promises = [];
|
|
897
|
+
const ignoreKeys = new Set(["type", "async", "response"]);
|
|
897
898
|
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
898
899
|
if (this.shouldFilter(filters)) return;
|
|
899
900
|
promises.push(
|
|
900
901
|
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
901
|
-
() =>
|
|
902
|
-
|
|
902
|
+
() => {
|
|
903
|
+
const requestKeys = [];
|
|
904
|
+
for (const key in this.request)
|
|
905
|
+
!ignoreKeys.has(key) && requestKeys.push(key);
|
|
906
|
+
return Promise.all(
|
|
903
907
|
requestKeys.map((key) =>
|
|
904
908
|
Promise.resolve(this.request[key]).then(
|
|
905
909
|
(val) => (this.request[key] = val),
|
|
906
|
-
() =>
|
|
910
|
+
() => this._recoverRequestKey(key)
|
|
907
911
|
)
|
|
908
912
|
)
|
|
909
|
-
)
|
|
913
|
+
);
|
|
914
|
+
}
|
|
910
915
|
)
|
|
911
916
|
);
|
|
912
917
|
});
|
|
@@ -1087,6 +1092,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1087
1092
|
e.stopImmediatePropagation = stopImmediatePropagation;
|
|
1088
1093
|
defineProp(e, "target", () => this.proxyXhr);
|
|
1089
1094
|
defineProp(e, "currentTarget", () => this.proxyXhr);
|
|
1095
|
+
defineProp(e, "srcElement", () => this.proxyXhr);
|
|
1090
1096
|
this.proxyEvents[e.type] &&
|
|
1091
1097
|
this.proxyEvents[e.type].forEach((fn) => {
|
|
1092
1098
|
this.resThenable.then(
|
|
@@ -1164,6 +1170,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
1164
1170
|
for (const header in request.headers) {
|
|
1165
1171
|
xhr.setRequestHeader(header, request.headers[header]);
|
|
1166
1172
|
}
|
|
1173
|
+
for (const prop of xhrExtraProps) {
|
|
1174
|
+
if (prop in request) xhr[prop] = request[prop];
|
|
1175
|
+
}
|
|
1167
1176
|
xhr.send(request.data);
|
|
1168
1177
|
}
|
|
1169
1178
|
});
|
|
@@ -1185,8 +1194,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
1185
1194
|
return new Promise(async (resolve, reject) => {
|
|
1186
1195
|
const init = {};
|
|
1187
1196
|
if (getType(url) === "[object Request]") {
|
|
1188
|
-
|
|
1197
|
+
init.method = url.method;
|
|
1198
|
+
init.headers = url.headers;
|
|
1189
1199
|
if (url.body) init.body = await url.arrayBuffer();
|
|
1200
|
+
for (const prop of fetchExtraProps) init[prop] = url[prop];
|
|
1190
1201
|
url = url.url;
|
|
1191
1202
|
}
|
|
1192
1203
|
url = url.toString();
|
|
@@ -1233,6 +1244,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
1233
1244
|
init.method = request.method;
|
|
1234
1245
|
init.headers = request.headers;
|
|
1235
1246
|
init.body = request.data;
|
|
1247
|
+
for (const prop of fetchExtraProps) {
|
|
1248
|
+
if (prop in request) init[prop] = request[prop];
|
|
1249
|
+
}
|
|
1236
1250
|
winAh.realFetch.call(win, request.url, init).then((res) => {
|
|
1237
1251
|
if (typeof request.response === "function") {
|
|
1238
1252
|
const response = {
|
|
@@ -5595,7 +5609,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5595
5609
|
this.windowApi = new WindowApi(option);
|
|
5596
5610
|
}
|
|
5597
5611
|
/** 版本号 */
|
|
5598
|
-
version = "2025.
|
|
5612
|
+
version = "2025.7.29";
|
|
5599
5613
|
addStyle(cssText) {
|
|
5600
5614
|
if (typeof cssText !== "string") {
|
|
5601
5615
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5679,7 +5693,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5679
5693
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
5680
5694
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
5681
5695
|
* + 作者:cxxjackie
|
|
5682
|
-
* + 版本:1.4.
|
|
5696
|
+
* + 版本:1.4.7
|
|
5683
5697
|
* + 旧版本:1.2.4
|
|
5684
5698
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5685
5699
|
* @param useOldVersion 是否使用旧版本,默认false
|