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