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