@whitesev/utils 2.6.9 → 2.7.0
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 +584 -602
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +584 -602
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +584 -602
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +584 -602
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +584 -602
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +584 -602
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +1 -1
- package/dist/types/src/ajaxHooker/ajaxHooker.d.ts +1 -1
- package/package.json +11 -9
- package/src/Utils.ts +4 -4
- package/src/ajaxHooker/ajaxHooker.js +536 -554
package/dist/index.esm.js
CHANGED
|
@@ -263,7 +263,7 @@ const TryCatch = function (...args) {
|
|
|
263
263
|
context = __context__ || this;
|
|
264
264
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
265
265
|
// @ts-ignore
|
|
266
|
-
return result !==
|
|
266
|
+
return result !== void 0 ? result : TryCatchCore;
|
|
267
267
|
},
|
|
268
268
|
};
|
|
269
269
|
/**
|
|
@@ -274,7 +274,7 @@ const TryCatch = function (...args) {
|
|
|
274
274
|
* @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
|
|
275
275
|
*/
|
|
276
276
|
function executeTryCatch(callback, handleErrorFunc, funcThis) {
|
|
277
|
-
let result =
|
|
277
|
+
let result = void 0;
|
|
278
278
|
try {
|
|
279
279
|
if (typeof callback === "string") {
|
|
280
280
|
result = new Function(callback).apply(funcThis, args);
|
|
@@ -421,8 +421,8 @@ class CommonUtil {
|
|
|
421
421
|
}
|
|
422
422
|
deepClone(obj) {
|
|
423
423
|
let UtilsContext = this;
|
|
424
|
-
if (obj ===
|
|
425
|
-
return
|
|
424
|
+
if (obj === void 0)
|
|
425
|
+
return void 0;
|
|
426
426
|
if (obj === null)
|
|
427
427
|
return null;
|
|
428
428
|
let clone = obj instanceof Array ? [] : {};
|
|
@@ -519,7 +519,7 @@ class UtilsGMCookie {
|
|
|
519
519
|
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
520
520
|
}
|
|
521
521
|
let cookies = this.getCookiesList();
|
|
522
|
-
let findValue =
|
|
522
|
+
let findValue = void 0;
|
|
523
523
|
for (const cookieItem of cookies) {
|
|
524
524
|
let item = cookieItem.trim();
|
|
525
525
|
let itemSplit = item.split("=");
|
|
@@ -743,189 +743,189 @@ class UtilsGMCookie {
|
|
|
743
743
|
}
|
|
744
744
|
}
|
|
745
745
|
|
|
746
|
+
// ==UserScript==
|
|
746
747
|
// @name ajaxHooker
|
|
747
748
|
// @author cxxjackie
|
|
748
|
-
// @version 1.4.
|
|
749
|
-
// @updateLog 修复头条、抖音部分站点下this引用错误的问题。
|
|
749
|
+
// @version 1.4.6
|
|
750
750
|
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
751
|
+
// @license GNU LGPL-3.0
|
|
752
|
+
// ==/UserScript==
|
|
751
753
|
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
console.error(err);
|
|
798
|
-
}
|
|
754
|
+
const ajaxHooker = function () {
|
|
755
|
+
const version = "1.4.6";
|
|
756
|
+
const hookInst = {
|
|
757
|
+
hookFns: [],
|
|
758
|
+
filters: [],
|
|
759
|
+
};
|
|
760
|
+
const win = window.unsafeWindow || document.defaultView || window;
|
|
761
|
+
let winAh = win.__ajaxHooker;
|
|
762
|
+
const resProto = win.Response.prototype;
|
|
763
|
+
const xhrResponses = ["response", "responseText", "responseXML"];
|
|
764
|
+
const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
|
|
765
|
+
const fetchInitProps = [
|
|
766
|
+
"method",
|
|
767
|
+
"headers",
|
|
768
|
+
"body",
|
|
769
|
+
"mode",
|
|
770
|
+
"credentials",
|
|
771
|
+
"cache",
|
|
772
|
+
"redirect",
|
|
773
|
+
"referrer",
|
|
774
|
+
"referrerPolicy",
|
|
775
|
+
"integrity",
|
|
776
|
+
"keepalive",
|
|
777
|
+
"signal",
|
|
778
|
+
"priority",
|
|
779
|
+
];
|
|
780
|
+
const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
|
|
781
|
+
const getType = {}.toString.call.bind({}.toString);
|
|
782
|
+
const getDescriptor = Object.getOwnPropertyDescriptor.bind(Object);
|
|
783
|
+
const emptyFn = () => {};
|
|
784
|
+
const errorFn = (e) => console.error(e);
|
|
785
|
+
function isThenable(obj) {
|
|
786
|
+
return (
|
|
787
|
+
obj &&
|
|
788
|
+
["object", "function"].includes(typeof obj) &&
|
|
789
|
+
typeof obj.then === "function"
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
function catchError(fn, ...args) {
|
|
793
|
+
try {
|
|
794
|
+
const result = fn(...args);
|
|
795
|
+
if (isThenable(result)) return result.then(null, errorFn);
|
|
796
|
+
return result;
|
|
797
|
+
} catch (err) {
|
|
798
|
+
console.error(err);
|
|
799
799
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
800
|
+
}
|
|
801
|
+
function defineProp(obj, prop, getter, setter) {
|
|
802
|
+
Object.defineProperty(obj, prop, {
|
|
803
|
+
configurable: true,
|
|
804
|
+
enumerable: true,
|
|
805
|
+
get: getter,
|
|
806
|
+
set: setter,
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function readonly(obj, prop, value = obj[prop]) {
|
|
810
|
+
defineProp(obj, prop, () => value, emptyFn);
|
|
811
|
+
}
|
|
812
|
+
function writable(obj, prop, value = obj[prop]) {
|
|
813
|
+
Object.defineProperty(obj, prop, {
|
|
814
|
+
configurable: true,
|
|
815
|
+
enumerable: true,
|
|
816
|
+
writable: true,
|
|
817
|
+
value: value,
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
function parseHeaders(obj) {
|
|
821
|
+
const headers = {};
|
|
822
|
+
switch (getType(obj)) {
|
|
823
|
+
case "[object String]":
|
|
824
|
+
for (const line of obj.trim().split(/[\r\n]+/)) {
|
|
825
|
+
const [header, value] = line.split(/(?<=^[^:]+)\s*:\s*/);
|
|
826
|
+
if (!value) continue;
|
|
827
|
+
const lheader = header.toLowerCase();
|
|
828
|
+
headers[lheader] =
|
|
829
|
+
lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
830
|
+
}
|
|
831
|
+
break;
|
|
832
|
+
case "[object Headers]":
|
|
833
|
+
for (const [key, val] of obj) {
|
|
834
|
+
headers[key] = val;
|
|
835
|
+
}
|
|
836
|
+
break;
|
|
837
|
+
case "[object Object]":
|
|
838
|
+
return { ...obj };
|
|
807
839
|
}
|
|
808
|
-
|
|
809
|
-
|
|
840
|
+
return headers;
|
|
841
|
+
}
|
|
842
|
+
function stopImmediatePropagation() {
|
|
843
|
+
this.ajaxHooker_isStopped = true;
|
|
844
|
+
}
|
|
845
|
+
class SyncThenable {
|
|
846
|
+
then(fn) {
|
|
847
|
+
fn && fn();
|
|
848
|
+
return new SyncThenable();
|
|
810
849
|
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
value: value,
|
|
817
|
-
});
|
|
850
|
+
}
|
|
851
|
+
class AHRequest {
|
|
852
|
+
constructor(request) {
|
|
853
|
+
this.request = request;
|
|
854
|
+
this.requestClone = { ...this.request };
|
|
818
855
|
}
|
|
819
|
-
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
headers[key] = val;
|
|
856
|
+
shouldFilter(filters) {
|
|
857
|
+
const { type, url, method, async } = this.request;
|
|
858
|
+
return (
|
|
859
|
+
filters.length &&
|
|
860
|
+
!filters.find((obj) => {
|
|
861
|
+
switch (true) {
|
|
862
|
+
case obj.type && obj.type !== type:
|
|
863
|
+
case getType(obj.url) === "[object String]" &&
|
|
864
|
+
!url.includes(obj.url):
|
|
865
|
+
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
866
|
+
case obj.method &&
|
|
867
|
+
obj.method.toUpperCase() !== method.toUpperCase():
|
|
868
|
+
case "async" in obj && obj.async !== async:
|
|
869
|
+
return false;
|
|
834
870
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
return headers;
|
|
840
|
-
}
|
|
841
|
-
function stopImmediatePropagation() {
|
|
842
|
-
this.ajaxHooker_isStopped = true;
|
|
871
|
+
return true;
|
|
872
|
+
})
|
|
873
|
+
);
|
|
843
874
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
875
|
+
waitForRequestKeys() {
|
|
876
|
+
const requestKeys = ["url", "method", "abort", "headers", "data"];
|
|
877
|
+
if (!this.request.async) {
|
|
878
|
+
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
879
|
+
if (this.shouldFilter(filters)) return;
|
|
880
|
+
hookFns.forEach((fn) => {
|
|
881
|
+
if (getType(fn) === "[object Function]")
|
|
882
|
+
catchError(fn, this.request);
|
|
883
|
+
});
|
|
884
|
+
requestKeys.forEach((key) => {
|
|
885
|
+
if (isThenable(this.request[key]))
|
|
886
|
+
this.request[key] = this.requestClone[key];
|
|
887
|
+
});
|
|
888
|
+
});
|
|
847
889
|
return new SyncThenable();
|
|
848
890
|
}
|
|
891
|
+
const promises = [];
|
|
892
|
+
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
893
|
+
if (this.shouldFilter(filters)) return;
|
|
894
|
+
promises.push(
|
|
895
|
+
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
896
|
+
() =>
|
|
897
|
+
Promise.all(
|
|
898
|
+
requestKeys.map((key) =>
|
|
899
|
+
Promise.resolve(this.request[key]).then(
|
|
900
|
+
(val) => (this.request[key] = val),
|
|
901
|
+
() => (this.request[key] = this.requestClone[key])
|
|
902
|
+
)
|
|
903
|
+
)
|
|
904
|
+
)
|
|
905
|
+
)
|
|
906
|
+
);
|
|
907
|
+
});
|
|
908
|
+
return Promise.all(promises);
|
|
849
909
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
this.request
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
case getType(obj.url) === "[object String]" &&
|
|
863
|
-
!url.includes(obj.url):
|
|
864
|
-
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
865
|
-
case obj.method &&
|
|
866
|
-
obj.method.toUpperCase() !== method.toUpperCase():
|
|
867
|
-
case "async" in obj && obj.async !== async:
|
|
868
|
-
return false;
|
|
910
|
+
waitForResponseKeys(response) {
|
|
911
|
+
const responseKeys =
|
|
912
|
+
this.request.type === "xhr" ? xhrResponses : fetchResponses;
|
|
913
|
+
if (!this.request.async) {
|
|
914
|
+
if (getType(this.request.response) === "[object Function]") {
|
|
915
|
+
catchError(this.request.response, response);
|
|
916
|
+
responseKeys.forEach((key) => {
|
|
917
|
+
if (
|
|
918
|
+
"get" in getDescriptor(response, key) ||
|
|
919
|
+
isThenable(response[key])
|
|
920
|
+
) {
|
|
921
|
+
delete response[key];
|
|
869
922
|
}
|
|
870
|
-
return true;
|
|
871
|
-
})
|
|
872
|
-
);
|
|
873
|
-
}
|
|
874
|
-
waitForRequestKeys() {
|
|
875
|
-
const requestKeys = ["url", "method", "abort", "headers", "data"];
|
|
876
|
-
if (!this.request.async) {
|
|
877
|
-
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
878
|
-
if (this.shouldFilter(filters)) return;
|
|
879
|
-
hookFns.forEach((fn) => {
|
|
880
|
-
if (getType(fn) === "[object Function]")
|
|
881
|
-
catchError(fn, this.request);
|
|
882
|
-
});
|
|
883
|
-
requestKeys.forEach((key) => {
|
|
884
|
-
if (isThenable(this.request[key]))
|
|
885
|
-
this.request[key] = this.requestClone[key];
|
|
886
|
-
});
|
|
887
923
|
});
|
|
888
|
-
return new SyncThenable();
|
|
889
924
|
}
|
|
890
|
-
|
|
891
|
-
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
892
|
-
if (this.shouldFilter(filters)) return;
|
|
893
|
-
promises.push(
|
|
894
|
-
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
895
|
-
() =>
|
|
896
|
-
Promise.all(
|
|
897
|
-
requestKeys.map((key) =>
|
|
898
|
-
Promise.resolve(this.request[key]).then(
|
|
899
|
-
(val) => (this.request[key] = val),
|
|
900
|
-
() => (this.request[key] = this.requestClone[key])
|
|
901
|
-
)
|
|
902
|
-
)
|
|
903
|
-
)
|
|
904
|
-
)
|
|
905
|
-
);
|
|
906
|
-
});
|
|
907
|
-
return Promise.all(promises);
|
|
925
|
+
return new SyncThenable();
|
|
908
926
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
this.request.type === "xhr" ? xhrResponses : fetchResponses;
|
|
912
|
-
if (!this.request.async) {
|
|
913
|
-
if (getType(this.request.response) === "[object Function]") {
|
|
914
|
-
catchError(this.request.response, response);
|
|
915
|
-
responseKeys.forEach((key) => {
|
|
916
|
-
if (
|
|
917
|
-
"get" in getDescriptor(response, key) ||
|
|
918
|
-
isThenable(response[key])
|
|
919
|
-
) {
|
|
920
|
-
delete response[key];
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
return new SyncThenable();
|
|
925
|
-
}
|
|
926
|
-
return Promise.resolve(
|
|
927
|
-
catchError(this.request.response, response)
|
|
928
|
-
).then(() =>
|
|
927
|
+
return Promise.resolve(catchError(this.request.response, response)).then(
|
|
928
|
+
() =>
|
|
929
929
|
Promise.all(
|
|
930
930
|
responseKeys.map((key) => {
|
|
931
931
|
const descriptor = getDescriptor(response, key);
|
|
@@ -939,424 +939,406 @@ const AjaxHooker = function () {
|
|
|
939
939
|
}
|
|
940
940
|
})
|
|
941
941
|
)
|
|
942
|
-
|
|
943
|
-
}
|
|
942
|
+
);
|
|
944
943
|
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
const ah = target.__ajaxHooker;
|
|
956
|
-
if (ah && ah.proxyProps) {
|
|
957
|
-
if (prop in ah.proxyProps) {
|
|
958
|
-
const pDescriptor = ah.proxyProps[prop];
|
|
959
|
-
if ("get" in pDescriptor) return pDescriptor.get();
|
|
960
|
-
if (typeof pDescriptor.value === "function")
|
|
961
|
-
return pDescriptor.value.bind(ah);
|
|
962
|
-
return pDescriptor.value;
|
|
963
|
-
}
|
|
964
|
-
if (typeof target[prop] === "function")
|
|
965
|
-
return target[prop].bind(target);
|
|
966
|
-
}
|
|
944
|
+
}
|
|
945
|
+
const proxyHandler = {
|
|
946
|
+
get(target, prop) {
|
|
947
|
+
const descriptor = getDescriptor(target, prop);
|
|
948
|
+
if (
|
|
949
|
+
descriptor &&
|
|
950
|
+
!descriptor.configurable &&
|
|
951
|
+
!descriptor.writable &&
|
|
952
|
+
!descriptor.get
|
|
953
|
+
)
|
|
967
954
|
return target[prop];
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (
|
|
972
|
-
descriptor &&
|
|
973
|
-
!descriptor.configurable &&
|
|
974
|
-
!descriptor.writable &&
|
|
975
|
-
!descriptor.set
|
|
976
|
-
)
|
|
977
|
-
return true;
|
|
978
|
-
const ah = target.__ajaxHooker;
|
|
979
|
-
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
955
|
+
const ah = target.__ajaxHooker;
|
|
956
|
+
if (ah && ah.proxyProps) {
|
|
957
|
+
if (prop in ah.proxyProps) {
|
|
980
958
|
const pDescriptor = ah.proxyProps[prop];
|
|
981
|
-
pDescriptor.
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
target[prop] = value;
|
|
986
|
-
}
|
|
987
|
-
return true;
|
|
988
|
-
},
|
|
989
|
-
};
|
|
990
|
-
class XhrHooker {
|
|
991
|
-
constructor(xhr) {
|
|
992
|
-
const ah = this;
|
|
993
|
-
Object.assign(ah, {
|
|
994
|
-
originalXhr: xhr,
|
|
995
|
-
proxyXhr: new Proxy(xhr, proxyHandler),
|
|
996
|
-
resThenable: new SyncThenable(),
|
|
997
|
-
proxyProps: {},
|
|
998
|
-
proxyEvents: {},
|
|
999
|
-
});
|
|
1000
|
-
xhr.addEventListener("readystatechange", (e) => {
|
|
1001
|
-
if (
|
|
1002
|
-
ah.proxyXhr.readyState === 4 &&
|
|
1003
|
-
ah.request &&
|
|
1004
|
-
typeof ah.request.response === "function"
|
|
1005
|
-
) {
|
|
1006
|
-
const response = {
|
|
1007
|
-
finalUrl: ah.proxyXhr.responseURL,
|
|
1008
|
-
status: ah.proxyXhr.status,
|
|
1009
|
-
responseHeaders: parseHeaders(
|
|
1010
|
-
ah.proxyXhr.getAllResponseHeaders()
|
|
1011
|
-
),
|
|
1012
|
-
};
|
|
1013
|
-
const tempValues = {};
|
|
1014
|
-
for (const key of xhrResponses) {
|
|
1015
|
-
try {
|
|
1016
|
-
tempValues[key] = ah.originalXhr[key];
|
|
1017
|
-
} catch (err) {}
|
|
1018
|
-
defineProp(
|
|
1019
|
-
response,
|
|
1020
|
-
key,
|
|
1021
|
-
() => {
|
|
1022
|
-
return (response[key] = tempValues[key]);
|
|
1023
|
-
},
|
|
1024
|
-
(val) => {
|
|
1025
|
-
delete response[key];
|
|
1026
|
-
response[key] = val;
|
|
1027
|
-
}
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
ah.resThenable = new AHRequest(ah.request)
|
|
1031
|
-
.waitForResponseKeys(response)
|
|
1032
|
-
.then(() => {
|
|
1033
|
-
for (const key of xhrResponses) {
|
|
1034
|
-
ah.proxyProps[key] = {
|
|
1035
|
-
get: () => {
|
|
1036
|
-
if (!(key in response)) response[key] = tempValues[key];
|
|
1037
|
-
return response[key];
|
|
1038
|
-
},
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
ah.dispatchEvent(e);
|
|
1044
|
-
});
|
|
1045
|
-
xhr.addEventListener("load", (e) => ah.dispatchEvent(e));
|
|
1046
|
-
xhr.addEventListener("loadend", (e) => ah.dispatchEvent(e));
|
|
1047
|
-
for (const evt of xhrAsyncEvents) {
|
|
1048
|
-
const onEvt = "on" + evt;
|
|
1049
|
-
ah.proxyProps[onEvt] = {
|
|
1050
|
-
get: () => ah.proxyEvents[onEvt] || null,
|
|
1051
|
-
set: (val) => ah.addEvent(onEvt, val),
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
for (const method of [
|
|
1055
|
-
"setRequestHeader",
|
|
1056
|
-
"addEventListener",
|
|
1057
|
-
"removeEventListener",
|
|
1058
|
-
"open",
|
|
1059
|
-
"send",
|
|
1060
|
-
]) {
|
|
1061
|
-
ah.proxyProps[method] = { value: ah[method] };
|
|
959
|
+
if ("get" in pDescriptor) return pDescriptor.get();
|
|
960
|
+
if (typeof pDescriptor.value === "function")
|
|
961
|
+
return pDescriptor.value.bind(ah);
|
|
962
|
+
return pDescriptor.value;
|
|
1062
963
|
}
|
|
964
|
+
if (typeof target[prop] === "function")
|
|
965
|
+
return target[prop].bind(target);
|
|
1063
966
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
event = event.handleEvent;
|
|
1082
|
-
this.proxyEvents[type] && this.proxyEvents[type].delete(event);
|
|
1083
|
-
}
|
|
967
|
+
return target[prop];
|
|
968
|
+
},
|
|
969
|
+
set(target, prop, value) {
|
|
970
|
+
const descriptor = getDescriptor(target, prop);
|
|
971
|
+
if (
|
|
972
|
+
descriptor &&
|
|
973
|
+
!descriptor.configurable &&
|
|
974
|
+
!descriptor.writable &&
|
|
975
|
+
!descriptor.set
|
|
976
|
+
)
|
|
977
|
+
return true;
|
|
978
|
+
const ah = target.__ajaxHooker;
|
|
979
|
+
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
980
|
+
const pDescriptor = ah.proxyProps[prop];
|
|
981
|
+
pDescriptor.set ? pDescriptor.set(value) : (pDescriptor.value = value);
|
|
982
|
+
} else {
|
|
983
|
+
target[prop] = value;
|
|
1084
984
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
985
|
+
return true;
|
|
986
|
+
},
|
|
987
|
+
};
|
|
988
|
+
class XhrHooker {
|
|
989
|
+
constructor(xhr) {
|
|
990
|
+
const ah = this;
|
|
991
|
+
Object.assign(ah, {
|
|
992
|
+
originalXhr: xhr,
|
|
993
|
+
proxyXhr: new Proxy(xhr, proxyHandler),
|
|
994
|
+
resThenable: new SyncThenable(),
|
|
995
|
+
proxyProps: {},
|
|
996
|
+
proxyEvents: {},
|
|
997
|
+
});
|
|
998
|
+
xhr.addEventListener("readystatechange", (e) => {
|
|
999
|
+
if (
|
|
1000
|
+
ah.proxyXhr.readyState === 4 &&
|
|
1001
|
+
ah.request &&
|
|
1002
|
+
typeof ah.request.response === "function"
|
|
1003
|
+
) {
|
|
1004
|
+
const response = {
|
|
1005
|
+
finalUrl: ah.proxyXhr.responseURL,
|
|
1006
|
+
status: ah.proxyXhr.status,
|
|
1007
|
+
responseHeaders: parseHeaders(ah.proxyXhr.getAllResponseHeaders()),
|
|
1008
|
+
};
|
|
1009
|
+
const tempValues = {};
|
|
1010
|
+
for (const key of xhrResponses) {
|
|
1011
|
+
try {
|
|
1012
|
+
tempValues[key] = ah.originalXhr[key];
|
|
1013
|
+
} catch (err) {}
|
|
1014
|
+
defineProp(
|
|
1015
|
+
response,
|
|
1016
|
+
key,
|
|
1017
|
+
() => {
|
|
1018
|
+
return (response[key] = tempValues[key]);
|
|
1019
|
+
},
|
|
1020
|
+
(val) => {
|
|
1021
|
+
delete response[key];
|
|
1022
|
+
response[key] = val;
|
|
1023
|
+
}
|
|
1093
1024
|
);
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1025
|
+
}
|
|
1026
|
+
ah.resThenable = new AHRequest(ah.request)
|
|
1027
|
+
.waitForResponseKeys(response)
|
|
1028
|
+
.then(() => {
|
|
1029
|
+
for (const key of xhrResponses) {
|
|
1030
|
+
ah.proxyProps[key] = {
|
|
1031
|
+
get: () => {
|
|
1032
|
+
if (!(key in response)) response[key] = tempValues[key];
|
|
1033
|
+
return response[key];
|
|
1034
|
+
},
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
ah.dispatchEvent(e);
|
|
1040
|
+
});
|
|
1041
|
+
xhr.addEventListener("load", (e) => ah.dispatchEvent(e));
|
|
1042
|
+
xhr.addEventListener("loadend", (e) => ah.dispatchEvent(e));
|
|
1043
|
+
for (const evt of xhrAsyncEvents) {
|
|
1044
|
+
const onEvt = "on" + evt;
|
|
1045
|
+
ah.proxyProps[onEvt] = {
|
|
1046
|
+
get: () => ah.proxyEvents[onEvt] || null,
|
|
1047
|
+
set: (val) => ah.addEvent(onEvt, val),
|
|
1048
|
+
};
|
|
1098
1049
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1050
|
+
for (const method of [
|
|
1051
|
+
"setRequestHeader",
|
|
1052
|
+
"addEventListener",
|
|
1053
|
+
"removeEventListener",
|
|
1054
|
+
"open",
|
|
1055
|
+
"send",
|
|
1056
|
+
]) {
|
|
1057
|
+
ah.proxyProps[method] = { value: ah[method] };
|
|
1105
1058
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1059
|
+
}
|
|
1060
|
+
toJSON() {} // Converting circular structure to JSON
|
|
1061
|
+
addEvent(type, event) {
|
|
1062
|
+
if (type.startsWith("on")) {
|
|
1063
|
+
this.proxyEvents[type] = typeof event === "function" ? event : null;
|
|
1064
|
+
} else {
|
|
1065
|
+
if (typeof event === "object" && event !== null)
|
|
1066
|
+
event = event.handleEvent;
|
|
1067
|
+
if (typeof event !== "function") return;
|
|
1068
|
+
this.proxyEvents[type] = this.proxyEvents[type] || new Set();
|
|
1069
|
+
this.proxyEvents[type].add(event);
|
|
1112
1070
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1071
|
+
}
|
|
1072
|
+
removeEvent(type, event) {
|
|
1073
|
+
if (type.startsWith("on")) {
|
|
1074
|
+
this.proxyEvents[type] = null;
|
|
1075
|
+
} else {
|
|
1076
|
+
if (typeof event === "object" && event !== null)
|
|
1077
|
+
event = event.handleEvent;
|
|
1078
|
+
this.proxyEvents[type] && this.proxyEvents[type].delete(event);
|
|
1119
1079
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
};
|
|
1131
|
-
this.openArgs = args;
|
|
1132
|
-
this.resThenable = new SyncThenable();
|
|
1133
|
-
[
|
|
1134
|
-
"responseURL",
|
|
1135
|
-
"readyState",
|
|
1136
|
-
"status",
|
|
1137
|
-
"statusText",
|
|
1138
|
-
...xhrResponses,
|
|
1139
|
-
].forEach((key) => {
|
|
1140
|
-
delete this.proxyProps[key];
|
|
1080
|
+
}
|
|
1081
|
+
dispatchEvent(e) {
|
|
1082
|
+
e.stopImmediatePropagation = stopImmediatePropagation;
|
|
1083
|
+
defineProp(e, "target", () => this.proxyXhr);
|
|
1084
|
+
defineProp(e, "currentTarget", () => this.proxyXhr);
|
|
1085
|
+
this.proxyEvents[e.type] &&
|
|
1086
|
+
this.proxyEvents[e.type].forEach((fn) => {
|
|
1087
|
+
this.resThenable.then(
|
|
1088
|
+
() => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e)
|
|
1089
|
+
);
|
|
1141
1090
|
});
|
|
1142
|
-
|
|
1091
|
+
if (e.ajaxHooker_isStopped) return;
|
|
1092
|
+
const onEvent = this.proxyEvents["on" + e.type];
|
|
1093
|
+
onEvent && this.resThenable.then(onEvent.bind(this.proxyXhr, e));
|
|
1094
|
+
}
|
|
1095
|
+
setRequestHeader(header, value) {
|
|
1096
|
+
this.originalXhr.setRequestHeader(header, value);
|
|
1097
|
+
if (!this.request) return;
|
|
1098
|
+
const headers = this.request.headers;
|
|
1099
|
+
headers[header] =
|
|
1100
|
+
header in headers ? `${headers[header]}, ${value}` : value;
|
|
1101
|
+
}
|
|
1102
|
+
addEventListener(...args) {
|
|
1103
|
+
if (xhrAsyncEvents.includes(args[0])) {
|
|
1104
|
+
this.addEvent(args[0], args[1]);
|
|
1105
|
+
} else {
|
|
1106
|
+
this.originalXhr.addEventListener(...args);
|
|
1143
1107
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
new AHRequest(request).waitForRequestKeys().then(() => {
|
|
1151
|
-
if (request.abort) {
|
|
1152
|
-
if (typeof request.response === "function") {
|
|
1153
|
-
Object.assign(ah.proxyProps, {
|
|
1154
|
-
responseURL: { value: request.url },
|
|
1155
|
-
readyState: { value: 4 },
|
|
1156
|
-
status: { value: 200 },
|
|
1157
|
-
statusText: { value: "OK" },
|
|
1158
|
-
});
|
|
1159
|
-
xhrAsyncEvents.forEach((evt) =>
|
|
1160
|
-
xhr.dispatchEvent(new Event(evt))
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
} else {
|
|
1164
|
-
xhr.open(
|
|
1165
|
-
request.method,
|
|
1166
|
-
request.url,
|
|
1167
|
-
request.async,
|
|
1168
|
-
...ah.openArgs
|
|
1169
|
-
);
|
|
1170
|
-
for (const header in request.headers) {
|
|
1171
|
-
xhr.setRequestHeader(header, request.headers[header]);
|
|
1172
|
-
}
|
|
1173
|
-
xhr.send(request.data);
|
|
1174
|
-
}
|
|
1175
|
-
});
|
|
1108
|
+
}
|
|
1109
|
+
removeEventListener(...args) {
|
|
1110
|
+
if (xhrAsyncEvents.includes(args[0])) {
|
|
1111
|
+
this.removeEvent(args[0], args[1]);
|
|
1112
|
+
} else {
|
|
1113
|
+
this.originalXhr.removeEventListener(...args);
|
|
1176
1114
|
}
|
|
1177
1115
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1116
|
+
open(method, url, async = true, ...args) {
|
|
1117
|
+
this.request = {
|
|
1118
|
+
type: "xhr",
|
|
1119
|
+
url: url.toString(),
|
|
1120
|
+
method: method.toUpperCase(),
|
|
1121
|
+
abort: false,
|
|
1122
|
+
headers: {},
|
|
1123
|
+
data: null,
|
|
1124
|
+
response: null,
|
|
1125
|
+
async: !!async,
|
|
1126
|
+
};
|
|
1127
|
+
this.openArgs = args;
|
|
1128
|
+
this.resThenable = new SyncThenable();
|
|
1129
|
+
[
|
|
1130
|
+
"responseURL",
|
|
1131
|
+
"readyState",
|
|
1132
|
+
"status",
|
|
1133
|
+
"statusText",
|
|
1134
|
+
...xhrResponses,
|
|
1135
|
+
].forEach((key) => {
|
|
1136
|
+
delete this.proxyProps[key];
|
|
1137
|
+
});
|
|
1138
|
+
return this.originalXhr.open(method, url, async, ...args);
|
|
1184
1139
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
const init = {};
|
|
1193
|
-
if (getType(url) === "[object Request]") {
|
|
1194
|
-
for (const prop of fetchInitProps) init[prop] = url[prop];
|
|
1195
|
-
if (url.body) init.body = await url.arrayBuffer();
|
|
1196
|
-
url = url.url;
|
|
1197
|
-
}
|
|
1198
|
-
url = url.toString();
|
|
1199
|
-
Object.assign(init, options);
|
|
1200
|
-
init.method = init.method || "GET";
|
|
1201
|
-
init.headers = init.headers || {};
|
|
1202
|
-
const request = {
|
|
1203
|
-
type: "fetch",
|
|
1204
|
-
url: url,
|
|
1205
|
-
method: init.method.toUpperCase(),
|
|
1206
|
-
abort: false,
|
|
1207
|
-
headers: parseHeaders(init.headers),
|
|
1208
|
-
data: init.body,
|
|
1209
|
-
response: null,
|
|
1210
|
-
async: true,
|
|
1211
|
-
};
|
|
1212
|
-
const req = new AHRequest(request);
|
|
1213
|
-
await req.waitForRequestKeys();
|
|
1140
|
+
send(data) {
|
|
1141
|
+
const ah = this;
|
|
1142
|
+
const xhr = ah.originalXhr;
|
|
1143
|
+
const request = ah.request;
|
|
1144
|
+
if (!request) return xhr.send(data);
|
|
1145
|
+
request.data = data;
|
|
1146
|
+
new AHRequest(request).waitForRequestKeys().then(() => {
|
|
1214
1147
|
if (request.abort) {
|
|
1215
1148
|
if (typeof request.response === "function") {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
await req.waitForResponseKeys(response);
|
|
1222
|
-
const key = fetchResponses.find((k) => k in response);
|
|
1223
|
-
let val = response[key];
|
|
1224
|
-
if (key === "json" && typeof val === "object") {
|
|
1225
|
-
val = catchError(JSON.stringify.bind(JSON), val);
|
|
1226
|
-
}
|
|
1227
|
-
const res = new Response(val, {
|
|
1228
|
-
status: 200,
|
|
1229
|
-
statusText: "OK",
|
|
1149
|
+
Object.assign(ah.proxyProps, {
|
|
1150
|
+
responseURL: { value: request.url },
|
|
1151
|
+
readyState: { value: 4 },
|
|
1152
|
+
status: { value: 200 },
|
|
1153
|
+
statusText: { value: "OK" },
|
|
1230
1154
|
});
|
|
1231
|
-
|
|
1232
|
-
defineProp(res, "url", () => request.url);
|
|
1233
|
-
resolve(res);
|
|
1234
|
-
} else {
|
|
1235
|
-
reject(new DOMException("aborted", "AbortError"));
|
|
1155
|
+
xhrAsyncEvents.forEach((evt) => xhr.dispatchEvent(new Event(evt)));
|
|
1236
1156
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
init.body = request.data;
|
|
1242
|
-
winAh.realFetch.call(win, request.url, init).then((res) => {
|
|
1243
|
-
if (typeof request.response === "function") {
|
|
1244
|
-
const response = {
|
|
1245
|
-
finalUrl: res.url,
|
|
1246
|
-
status: res.status,
|
|
1247
|
-
responseHeaders: parseHeaders(res.headers),
|
|
1248
|
-
};
|
|
1249
|
-
fetchResponses.forEach(
|
|
1250
|
-
(key) =>
|
|
1251
|
-
(res[key] = function () {
|
|
1252
|
-
if (key in response) return Promise.resolve(response[key]);
|
|
1253
|
-
return resProto[key].call(this).then((val) => {
|
|
1254
|
-
response[key] = val;
|
|
1255
|
-
return req
|
|
1256
|
-
.waitForResponseKeys(response)
|
|
1257
|
-
.then(() => (key in response ? response[key] : val));
|
|
1258
|
-
});
|
|
1259
|
-
})
|
|
1260
|
-
);
|
|
1157
|
+
} else {
|
|
1158
|
+
xhr.open(request.method, request.url, request.async, ...ah.openArgs);
|
|
1159
|
+
for (const header in request.headers) {
|
|
1160
|
+
xhr.setRequestHeader(header, request.headers[header]);
|
|
1261
1161
|
}
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1162
|
+
xhr.send(request.data);
|
|
1163
|
+
}
|
|
1264
1164
|
});
|
|
1265
1165
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
return res;
|
|
1271
|
-
}
|
|
1272
|
-
winAh = win.__ajaxHooker = winAh || {
|
|
1273
|
-
version,
|
|
1274
|
-
fakeXHR,
|
|
1275
|
-
fakeFetch,
|
|
1276
|
-
fakeFetchClone,
|
|
1277
|
-
realXHR: win.XMLHttpRequest,
|
|
1278
|
-
realFetch: win.fetch,
|
|
1279
|
-
realFetchClone: resProto.clone,
|
|
1280
|
-
hookInsts: new Set(),
|
|
1281
|
-
};
|
|
1282
|
-
if (winAh.version !== version)
|
|
1166
|
+
}
|
|
1167
|
+
function fakeXHR() {
|
|
1168
|
+
const xhr = new winAh.realXHR();
|
|
1169
|
+
if ("__ajaxHooker" in xhr)
|
|
1283
1170
|
console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1171
|
+
xhr.__ajaxHooker = new XhrHooker(xhr);
|
|
1172
|
+
return xhr.__ajaxHooker.proxyXhr;
|
|
1173
|
+
}
|
|
1174
|
+
fakeXHR.prototype = win.XMLHttpRequest.prototype;
|
|
1175
|
+
Object.keys(win.XMLHttpRequest).forEach(
|
|
1176
|
+
(key) => (fakeXHR[key] = win.XMLHttpRequest[key])
|
|
1177
|
+
);
|
|
1178
|
+
function fakeFetch(url, options = {}) {
|
|
1179
|
+
if (!url) return winAh.realFetch.call(win, url, options);
|
|
1180
|
+
return new Promise(async (resolve, reject) => {
|
|
1181
|
+
const init = {};
|
|
1182
|
+
if (getType(url) === "[object Request]") {
|
|
1183
|
+
for (const prop of fetchInitProps) init[prop] = url[prop];
|
|
1184
|
+
if (url.body) init.body = await url.arrayBuffer();
|
|
1185
|
+
url = url.url;
|
|
1186
|
+
}
|
|
1187
|
+
url = url.toString();
|
|
1188
|
+
Object.assign(init, options);
|
|
1189
|
+
init.method = init.method || "GET";
|
|
1190
|
+
init.headers = init.headers || {};
|
|
1191
|
+
const request = {
|
|
1192
|
+
type: "fetch",
|
|
1193
|
+
url: url,
|
|
1194
|
+
method: init.method.toUpperCase(),
|
|
1195
|
+
abort: false,
|
|
1196
|
+
headers: parseHeaders(init.headers),
|
|
1197
|
+
data: init.body,
|
|
1198
|
+
response: null,
|
|
1199
|
+
async: true,
|
|
1200
|
+
};
|
|
1201
|
+
const req = new AHRequest(request);
|
|
1202
|
+
await req.waitForRequestKeys();
|
|
1203
|
+
if (request.abort) {
|
|
1204
|
+
if (typeof request.response === "function") {
|
|
1205
|
+
const response = {
|
|
1206
|
+
finalUrl: request.url,
|
|
1207
|
+
status: 200,
|
|
1208
|
+
responseHeaders: {},
|
|
1209
|
+
};
|
|
1210
|
+
await req.waitForResponseKeys(response);
|
|
1211
|
+
const key = fetchResponses.find((k) => k in response);
|
|
1212
|
+
let val = response[key];
|
|
1213
|
+
if (key === "json" && typeof val === "object") {
|
|
1214
|
+
val = catchError(JSON.stringify.bind(JSON), val);
|
|
1215
|
+
}
|
|
1216
|
+
const res = new Response(val, {
|
|
1217
|
+
status: 200,
|
|
1218
|
+
statusText: "OK",
|
|
1219
|
+
});
|
|
1220
|
+
defineProp(res, "type", () => "basic");
|
|
1221
|
+
defineProp(res, "url", () => request.url);
|
|
1222
|
+
resolve(res);
|
|
1223
|
+
} else {
|
|
1224
|
+
reject(new DOMException("aborted", "AbortError"));
|
|
1297
1225
|
}
|
|
1298
|
-
return
|
|
1226
|
+
return;
|
|
1299
1227
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1228
|
+
init.method = request.method;
|
|
1229
|
+
init.headers = request.headers;
|
|
1230
|
+
init.body = request.data;
|
|
1231
|
+
winAh.realFetch.call(win, request.url, init).then((res) => {
|
|
1232
|
+
if (typeof request.response === "function") {
|
|
1233
|
+
const response = {
|
|
1234
|
+
finalUrl: res.url,
|
|
1235
|
+
status: res.status,
|
|
1236
|
+
responseHeaders: parseHeaders(res.headers),
|
|
1237
|
+
};
|
|
1238
|
+
fetchResponses.forEach(
|
|
1239
|
+
(key) =>
|
|
1240
|
+
(res[key] = function () {
|
|
1241
|
+
if (key in response) return Promise.resolve(response[key]);
|
|
1242
|
+
return resProto[key].call(this).then((val) => {
|
|
1243
|
+
response[key] = val;
|
|
1244
|
+
return req
|
|
1245
|
+
.waitForResponseKeys(response)
|
|
1246
|
+
.then(() => (key in response ? response[key] : val));
|
|
1247
|
+
});
|
|
1248
|
+
})
|
|
1249
|
+
);
|
|
1307
1250
|
}
|
|
1308
|
-
|
|
1251
|
+
resolve(res);
|
|
1252
|
+
}, reject);
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
function fakeFetchClone() {
|
|
1256
|
+
const descriptors = Object.getOwnPropertyDescriptors(this);
|
|
1257
|
+
const res = winAh.realFetchClone.call(this);
|
|
1258
|
+
Object.defineProperties(res, descriptors);
|
|
1259
|
+
return res;
|
|
1260
|
+
}
|
|
1261
|
+
winAh = win.__ajaxHooker = winAh || {
|
|
1262
|
+
version,
|
|
1263
|
+
fakeXHR,
|
|
1264
|
+
fakeFetch,
|
|
1265
|
+
fakeFetchClone,
|
|
1266
|
+
realXHR: win.XMLHttpRequest,
|
|
1267
|
+
realFetch: win.fetch,
|
|
1268
|
+
realFetchClone: resProto.clone,
|
|
1269
|
+
hookInsts: new Set(),
|
|
1270
|
+
};
|
|
1271
|
+
if (winAh.version !== version)
|
|
1272
|
+
console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
1273
|
+
win.XMLHttpRequest = winAh.fakeXHR;
|
|
1274
|
+
win.fetch = winAh.fakeFetch;
|
|
1275
|
+
resProto.clone = winAh.fakeFetchClone;
|
|
1276
|
+
winAh.hookInsts.add(hookInst);
|
|
1277
|
+
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
1278
|
+
class AHFunction extends Function {
|
|
1279
|
+
call(thisArg, ...args) {
|
|
1280
|
+
if (
|
|
1281
|
+
thisArg &&
|
|
1282
|
+
thisArg.__ajaxHooker &&
|
|
1283
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
1284
|
+
) {
|
|
1285
|
+
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
1309
1286
|
}
|
|
1287
|
+
return Reflect.apply(this, thisArg, args);
|
|
1310
1288
|
}
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
);
|
|
1320
|
-
Object.setPrototypeOf(
|
|
1321
|
-
csrf.nativeXMLHttpRequestSend,
|
|
1322
|
-
AHFunction.prototype
|
|
1323
|
-
);
|
|
1289
|
+
apply(thisArg, args) {
|
|
1290
|
+
if (
|
|
1291
|
+
thisArg &&
|
|
1292
|
+
thisArg.__ajaxHooker &&
|
|
1293
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
1294
|
+
) {
|
|
1295
|
+
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
1296
|
+
}
|
|
1297
|
+
return Reflect.apply(this, thisArg, args || []);
|
|
1324
1298
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1299
|
+
}
|
|
1300
|
+
function hookSecsdk(csrf) {
|
|
1301
|
+
Object.setPrototypeOf(
|
|
1302
|
+
csrf.nativeXMLHttpRequestSetRequestHeader,
|
|
1303
|
+
AHFunction.prototype
|
|
1304
|
+
);
|
|
1305
|
+
Object.setPrototypeOf(csrf.nativeXMLHttpRequestOpen, AHFunction.prototype);
|
|
1306
|
+
Object.setPrototypeOf(csrf.nativeXMLHttpRequestSend, AHFunction.prototype);
|
|
1307
|
+
}
|
|
1308
|
+
if (win.secsdk) {
|
|
1309
|
+
if (win.secsdk.csrf && win.secsdk.csrf.nativeXMLHttpRequestOpen)
|
|
1310
|
+
hookSecsdk(win.secsdk.csrf);
|
|
1311
|
+
} else {
|
|
1312
|
+
defineProp(win, "secsdk", emptyFn, (secsdk) => {
|
|
1313
|
+
delete win.secsdk;
|
|
1314
|
+
win.secsdk = secsdk;
|
|
1315
|
+
defineProp(secsdk, "csrf", emptyFn, (csrf) => {
|
|
1316
|
+
delete secsdk.csrf;
|
|
1317
|
+
secsdk.csrf = csrf;
|
|
1318
|
+
if (csrf.nativeXMLHttpRequestOpen) hookSecsdk(csrf);
|
|
1337
1319
|
});
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
return {
|
|
1323
|
+
hook: (fn) => hookInst.hookFns.push(fn),
|
|
1324
|
+
filter: (arr) => {
|
|
1325
|
+
if (Array.isArray(arr)) hookInst.filters = arr;
|
|
1326
|
+
},
|
|
1327
|
+
protect: () => {
|
|
1328
|
+
readonly(win, "XMLHttpRequest", winAh.fakeXHR);
|
|
1329
|
+
readonly(win, "fetch", winAh.fakeFetch);
|
|
1330
|
+
readonly(resProto, "clone", winAh.fakeFetchClone);
|
|
1331
|
+
},
|
|
1332
|
+
unhook: () => {
|
|
1333
|
+
winAh.hookInsts.delete(hookInst);
|
|
1334
|
+
if (!winAh.hookInsts.size) {
|
|
1335
|
+
writable(win, "XMLHttpRequest", winAh.realXHR);
|
|
1336
|
+
writable(win, "fetch", winAh.realFetch);
|
|
1337
|
+
writable(resProto, "clone", winAh.realFetchClone);
|
|
1338
|
+
delete win.__ajaxHooker;
|
|
1339
|
+
}
|
|
1340
|
+
},
|
|
1341
|
+
};
|
|
1360
1342
|
};
|
|
1361
1343
|
|
|
1362
1344
|
// ==UserScript==
|
|
@@ -2060,14 +2042,14 @@ class GMMenu {
|
|
|
2060
2042
|
const option = menuOption[index];
|
|
2061
2043
|
this.MenuHandle.$data.data.push({
|
|
2062
2044
|
data: option,
|
|
2063
|
-
id:
|
|
2045
|
+
id: void 0,
|
|
2064
2046
|
});
|
|
2065
2047
|
}
|
|
2066
2048
|
}
|
|
2067
2049
|
else {
|
|
2068
2050
|
this.MenuHandle.$data.data.push({
|
|
2069
2051
|
data: menuOption,
|
|
2070
|
-
id:
|
|
2052
|
+
id: void 0,
|
|
2071
2053
|
});
|
|
2072
2054
|
}
|
|
2073
2055
|
}
|
|
@@ -3210,13 +3192,13 @@ class Httpx {
|
|
|
3210
3192
|
status: fetchResponse.status,
|
|
3211
3193
|
statusText: fetchResponse.statusText,
|
|
3212
3194
|
// @ts-ignore
|
|
3213
|
-
response:
|
|
3195
|
+
response: void 0,
|
|
3214
3196
|
responseFetchHeaders: fetchResponse.headers,
|
|
3215
3197
|
responseHeaders: "",
|
|
3216
3198
|
// @ts-ignore
|
|
3217
|
-
responseText:
|
|
3199
|
+
responseText: void 0,
|
|
3218
3200
|
responseType: option.responseType,
|
|
3219
|
-
responseXML:
|
|
3201
|
+
responseXML: void 0,
|
|
3220
3202
|
};
|
|
3221
3203
|
Object.assign(httpxResponse, option.context || {});
|
|
3222
3204
|
// 把headers转为字符串
|
|
@@ -3328,30 +3310,30 @@ class Httpx {
|
|
|
3328
3310
|
* 默认配置
|
|
3329
3311
|
*/
|
|
3330
3312
|
#defaultRequestOption = {
|
|
3331
|
-
url:
|
|
3313
|
+
url: void 0,
|
|
3332
3314
|
timeout: 5000,
|
|
3333
3315
|
async: false,
|
|
3334
|
-
responseType:
|
|
3335
|
-
headers:
|
|
3336
|
-
data:
|
|
3337
|
-
redirect:
|
|
3338
|
-
cookie:
|
|
3339
|
-
cookiePartition:
|
|
3340
|
-
binary:
|
|
3341
|
-
nocache:
|
|
3342
|
-
revalidate:
|
|
3343
|
-
context:
|
|
3344
|
-
overrideMimeType:
|
|
3345
|
-
anonymous:
|
|
3346
|
-
fetch:
|
|
3347
|
-
fetchInit:
|
|
3316
|
+
responseType: void 0,
|
|
3317
|
+
headers: void 0,
|
|
3318
|
+
data: void 0,
|
|
3319
|
+
redirect: void 0,
|
|
3320
|
+
cookie: void 0,
|
|
3321
|
+
cookiePartition: void 0,
|
|
3322
|
+
binary: void 0,
|
|
3323
|
+
nocache: void 0,
|
|
3324
|
+
revalidate: void 0,
|
|
3325
|
+
context: void 0,
|
|
3326
|
+
overrideMimeType: void 0,
|
|
3327
|
+
anonymous: void 0,
|
|
3328
|
+
fetch: void 0,
|
|
3329
|
+
fetchInit: void 0,
|
|
3348
3330
|
allowInterceptConfig: {
|
|
3349
3331
|
beforeRequest: true,
|
|
3350
3332
|
afterResponseSuccess: true,
|
|
3351
3333
|
afterResponseError: true,
|
|
3352
3334
|
},
|
|
3353
|
-
user:
|
|
3354
|
-
password:
|
|
3335
|
+
user: void 0,
|
|
3336
|
+
password: void 0,
|
|
3355
3337
|
onabort() { },
|
|
3356
3338
|
onerror() { },
|
|
3357
3339
|
ontimeout() { },
|
|
@@ -3363,7 +3345,7 @@ class Httpx {
|
|
|
3363
3345
|
/**
|
|
3364
3346
|
* `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL。
|
|
3365
3347
|
*/
|
|
3366
|
-
baseURL:
|
|
3348
|
+
baseURL: void 0,
|
|
3367
3349
|
/**
|
|
3368
3350
|
* 当前使用请求时,输出请求的配置,一般用于DEBUG|DEV
|
|
3369
3351
|
*/
|
|
@@ -3768,7 +3750,7 @@ class indexedDB {
|
|
|
3768
3750
|
success: false,
|
|
3769
3751
|
code: that.#statusCode.getFailed.code,
|
|
3770
3752
|
msg: that.#statusCode.getFailed.msg,
|
|
3771
|
-
data:
|
|
3753
|
+
data: void 0,
|
|
3772
3754
|
});
|
|
3773
3755
|
}
|
|
3774
3756
|
else {
|
|
@@ -3778,7 +3760,7 @@ class indexedDB {
|
|
|
3778
3760
|
let result = target.result;
|
|
3779
3761
|
/* result 返回的是 {key: string, value: any} */
|
|
3780
3762
|
/* 键值对存储 */
|
|
3781
|
-
let data = result ? result.value :
|
|
3763
|
+
let data = result ? result.value : void 0;
|
|
3782
3764
|
if (data == null) {
|
|
3783
3765
|
resolve({
|
|
3784
3766
|
success: true,
|
|
@@ -3805,7 +3787,7 @@ class indexedDB {
|
|
|
3805
3787
|
success: false,
|
|
3806
3788
|
code: that.#statusCode.getFailed.code,
|
|
3807
3789
|
msg: that.#statusCode.getFailed.msg,
|
|
3808
|
-
data:
|
|
3790
|
+
data: void 0,
|
|
3809
3791
|
event: event,
|
|
3810
3792
|
});
|
|
3811
3793
|
};
|
|
@@ -3955,7 +3937,7 @@ class LockFunction {
|
|
|
3955
3937
|
#flag = false;
|
|
3956
3938
|
#delayTime = 0;
|
|
3957
3939
|
#callback;
|
|
3958
|
-
#timeId =
|
|
3940
|
+
#timeId = void 0;
|
|
3959
3941
|
lock;
|
|
3960
3942
|
unlock;
|
|
3961
3943
|
run;
|
|
@@ -4378,7 +4360,7 @@ class UtilsDictionary {
|
|
|
4378
4360
|
*/
|
|
4379
4361
|
getStartsWith(key) {
|
|
4380
4362
|
let allKeys = this.keys();
|
|
4381
|
-
let result =
|
|
4363
|
+
let result = void 0;
|
|
4382
4364
|
for (const keyName of allKeys) {
|
|
4383
4365
|
if (String(keyName).startsWith(String(key))) {
|
|
4384
4366
|
result = this.get(keyName);
|
|
@@ -4393,7 +4375,7 @@ class UtilsDictionary {
|
|
|
4393
4375
|
* @param val 值,默认为""
|
|
4394
4376
|
*/
|
|
4395
4377
|
set(key, val) {
|
|
4396
|
-
if (key ===
|
|
4378
|
+
if (key === void 0) {
|
|
4397
4379
|
throw new Error("Utils.Dictionary().set 参数 key 不能为空");
|
|
4398
4380
|
}
|
|
4399
4381
|
Reflect.set(this.items, key, val);
|
|
@@ -5608,7 +5590,7 @@ class Utils {
|
|
|
5608
5590
|
this.windowApi = new WindowApi(option);
|
|
5609
5591
|
}
|
|
5610
5592
|
/** 版本号 */
|
|
5611
|
-
version = "2025.6.
|
|
5593
|
+
version = "2025.6.26";
|
|
5612
5594
|
addStyle(cssText) {
|
|
5613
5595
|
if (typeof cssText !== "string") {
|
|
5614
5596
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5692,7 +5674,7 @@ class Utils {
|
|
|
5692
5674
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
5693
5675
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
5694
5676
|
* + 作者:cxxjackie
|
|
5695
|
-
* + 版本:1.4.
|
|
5677
|
+
* + 版本:1.4.6
|
|
5696
5678
|
* + 旧版本:1.2.4
|
|
5697
5679
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5698
5680
|
* @param useOldVersion 是否使用旧版本,默认false
|
|
@@ -5702,7 +5684,7 @@ class Utils {
|
|
|
5702
5684
|
return AjaxHooker1_2_4();
|
|
5703
5685
|
}
|
|
5704
5686
|
else {
|
|
5705
|
-
return
|
|
5687
|
+
return ajaxHooker();
|
|
5706
5688
|
}
|
|
5707
5689
|
};
|
|
5708
5690
|
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = globalThis) {
|
|
@@ -7263,36 +7245,36 @@ class Utils {
|
|
|
7263
7245
|
* + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
|
|
7264
7246
|
* + false (默认) 不生效
|
|
7265
7247
|
*/
|
|
7266
|
-
subtree:
|
|
7248
|
+
subtree: void 0,
|
|
7267
7249
|
/**
|
|
7268
7250
|
* + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
|
|
7269
7251
|
* + false (默认) 不生效
|
|
7270
7252
|
*/
|
|
7271
|
-
childList:
|
|
7253
|
+
childList: void 0,
|
|
7272
7254
|
/**
|
|
7273
7255
|
* + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
|
|
7274
7256
|
* + false (默认) 不生效
|
|
7275
7257
|
*/
|
|
7276
|
-
attributes:
|
|
7258
|
+
attributes: void 0,
|
|
7277
7259
|
/**
|
|
7278
7260
|
* 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
|
|
7279
7261
|
*/
|
|
7280
|
-
attributeFilter:
|
|
7262
|
+
attributeFilter: void 0,
|
|
7281
7263
|
/**
|
|
7282
7264
|
* + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
|
|
7283
7265
|
* + false (默认) 不生效
|
|
7284
7266
|
*/
|
|
7285
|
-
attributeOldValue:
|
|
7267
|
+
attributeOldValue: void 0,
|
|
7286
7268
|
/**
|
|
7287
7269
|
* + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
|
|
7288
7270
|
* + false (默认) 不生效
|
|
7289
7271
|
*/
|
|
7290
|
-
characterData:
|
|
7272
|
+
characterData: void 0,
|
|
7291
7273
|
/**
|
|
7292
7274
|
* + true 记录前一个被监听的节点中发生的文本变化
|
|
7293
7275
|
* + false (默认) 不生效
|
|
7294
7276
|
*/
|
|
7295
|
-
characterDataOldValue:
|
|
7277
|
+
characterDataOldValue: void 0,
|
|
7296
7278
|
},
|
|
7297
7279
|
immediate: false,
|
|
7298
7280
|
};
|
|
@@ -7868,7 +7850,7 @@ class Utils {
|
|
|
7868
7850
|
}
|
|
7869
7851
|
return new Promise((resolve) => {
|
|
7870
7852
|
UtilsContext.workerSetTimeout(() => {
|
|
7871
|
-
resolve(
|
|
7853
|
+
resolve(void 0);
|
|
7872
7854
|
}, delayTime);
|
|
7873
7855
|
});
|
|
7874
7856
|
}
|
|
@@ -8211,7 +8193,7 @@ class Utils {
|
|
|
8211
8193
|
}
|
|
8212
8194
|
waitNode(...args) {
|
|
8213
8195
|
// 过滤掉undefined
|
|
8214
|
-
args = args.filter((arg) => arg !==
|
|
8196
|
+
args = args.filter((arg) => arg !== void 0);
|
|
8215
8197
|
let UtilsContext = this;
|
|
8216
8198
|
// 选择器
|
|
8217
8199
|
let selector = args[0];
|
|
@@ -8300,7 +8282,7 @@ class Utils {
|
|
|
8300
8282
|
}
|
|
8301
8283
|
waitAnyNode(...args) {
|
|
8302
8284
|
// 过滤掉undefined
|
|
8303
|
-
args = args.filter((arg) => arg !==
|
|
8285
|
+
args = args.filter((arg) => arg !== void 0);
|
|
8304
8286
|
let UtilsContext = this;
|
|
8305
8287
|
// 选择器
|
|
8306
8288
|
let selectorList = args[0];
|
|
@@ -8356,7 +8338,7 @@ class Utils {
|
|
|
8356
8338
|
}
|
|
8357
8339
|
waitNodeList(...args) {
|
|
8358
8340
|
// 过滤掉undefined
|
|
8359
|
-
args = args.filter((arg) => arg !==
|
|
8341
|
+
args = args.filter((arg) => arg !== void 0);
|
|
8360
8342
|
let UtilsContext = this;
|
|
8361
8343
|
// 选择器数组
|
|
8362
8344
|
let selector = args[0];
|
|
@@ -8443,7 +8425,7 @@ class Utils {
|
|
|
8443
8425
|
}
|
|
8444
8426
|
waitAnyNodeList(...args) {
|
|
8445
8427
|
// 过滤掉undefined
|
|
8446
|
-
args = args.filter((arg) => arg !==
|
|
8428
|
+
args = args.filter((arg) => arg !== void 0);
|
|
8447
8429
|
let UtilsContext = this;
|
|
8448
8430
|
// 选择器数组
|
|
8449
8431
|
let selectorList = args[0];
|