@whitesev/utils 2.6.0 → 2.6.2

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.esm.js CHANGED
@@ -460,14 +460,13 @@ class UtilsGMCookie {
460
460
 
461
461
  // @name ajaxHooker
462
462
  // @author cxxjackie
463
- // @version 1.4.3
464
- // @updateLog 修复特殊情况下有部分请求头丢失的问题。
465
- // @updateLog xhr事件增加currentTarget劫持。
463
+ // @version 1.4.4
464
+ // @updateLog 修复头条、抖音部分站点下this引用错误的问题。
466
465
  // @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
467
466
 
468
467
  const AjaxHooker = function () {
469
468
  return (function () {
470
- const version = "1.4.3";
469
+ const version = "1.4.4";
471
470
  const hookInst = {
472
471
  hookFns: [],
473
472
  filters: [],
@@ -1001,6 +1000,57 @@ const AjaxHooker = function () {
1001
1000
  win.fetch = winAh.fakeFetch;
1002
1001
  resProto.clone = winAh.fakeFetchClone;
1003
1002
  winAh.hookInsts.add(hookInst);
1003
+ // 针对头条、抖音 secsdk.umd.js 的兼容性处理
1004
+ class AHFunction {
1005
+ call(thisArg, ...args) {
1006
+ if (
1007
+ thisArg &&
1008
+ thisArg.__ajaxHooker &&
1009
+ thisArg.__ajaxHooker.proxyXhr === thisArg
1010
+ ) {
1011
+ thisArg = thisArg.__ajaxHooker.originalXhr;
1012
+ }
1013
+ return Reflect.apply(this, thisArg, args);
1014
+ }
1015
+ apply(thisArg, args) {
1016
+ if (
1017
+ thisArg &&
1018
+ thisArg.__ajaxHooker &&
1019
+ thisArg.__ajaxHooker.proxyXhr === thisArg
1020
+ ) {
1021
+ thisArg = thisArg.__ajaxHooker.originalXhr;
1022
+ }
1023
+ return Reflect.apply(this, thisArg, args || []);
1024
+ }
1025
+ }
1026
+ function hookSecsdk(csrf) {
1027
+ Object.setPrototypeOf(
1028
+ csrf.nativeXMLHttpRequestSetRequestHeader,
1029
+ AHFunction.prototype
1030
+ );
1031
+ Object.setPrototypeOf(
1032
+ csrf.nativeXMLHttpRequestOpen,
1033
+ AHFunction.prototype
1034
+ );
1035
+ Object.setPrototypeOf(
1036
+ csrf.nativeXMLHttpRequestSend,
1037
+ AHFunction.prototype
1038
+ );
1039
+ }
1040
+ if (win.secsdk) {
1041
+ if (win.secsdk.csrf && win.secsdk.csrf.nativeXMLHttpRequestOpen)
1042
+ hookSecsdk(win.secsdk.csrf);
1043
+ } else {
1044
+ defineProp(win, "secsdk", emptyFn, (secsdk) => {
1045
+ delete win.secsdk;
1046
+ win.secsdk = secsdk;
1047
+ defineProp(secsdk, "csrf", emptyFn, (csrf) => {
1048
+ delete secsdk.csrf;
1049
+ secsdk.csrf = csrf;
1050
+ if (csrf.nativeXMLHttpRequestOpen) hookSecsdk(csrf);
1051
+ });
1052
+ });
1053
+ }
1004
1054
  return {
1005
1055
  hook: (fn) => hookInst.hookFns.push(fn),
1006
1056
  filter: (arr) => {
@@ -4985,7 +5035,7 @@ class Utils {
4985
5035
  this.windowApi = new WindowApi(option);
4986
5036
  }
4987
5037
  /** 版本号 */
4988
- version = "2025.1.11";
5038
+ version = "2025.3.24";
4989
5039
  addStyle(cssText) {
4990
5040
  if (typeof cssText !== "string") {
4991
5041
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -5105,7 +5155,7 @@ class Utils {
5105
5155
  * ajax劫持库,支持xhr和fetch劫持。
5106
5156
  * + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
5107
5157
  * + 作者:cxxjackie
5108
- * + 版本:1.4.3
5158
+ * + 版本:1.4.4
5109
5159
  * + 旧版本:1.2.4
5110
5160
  * + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
5111
5161
  * @param useOldVersion 是否使用旧版本,默认false