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