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