@whitesev/utils 1.4.3 → 1.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/node/index.esm.js",
package/src/Utils.ts CHANGED
@@ -147,7 +147,7 @@ class Utils {
147
147
  UtilsCore.init(option);
148
148
  }
149
149
  /** 版本号 */
150
- version = "2024.6.11";
150
+ version = "2024.6.14";
151
151
 
152
152
  /**
153
153
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -1,14 +1,15 @@
1
1
  /// <reference path="./index.d.ts" />
2
2
  // @name ajaxHooker
3
3
  // @author cxxjackie
4
- // @version 1.4.2
5
- // @updateLog 修复了fetch请求的参数为Request类型时body类型不正确的bug。
4
+ // @version 1.4.3
5
+ // @updateLog 修复特殊情况下有部分请求头丢失的问题。
6
+ // @updateLog xhr事件增加currentTarget劫持。
6
7
  // @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
7
8
 
8
9
  const AjaxHooker = function () {
9
10
  return function() {
10
11
  'use strict';
11
- const version = '1.4.2';
12
+ const version = '1.4.3';
12
13
  const hookInst = {
13
14
  hookFns: [],
14
15
  filters: []
@@ -263,6 +264,7 @@ const AjaxHooker = function () {
263
264
  dispatchEvent(e) {
264
265
  e.stopImmediatePropagation = stopImmediatePropagation;
265
266
  defineProp(e, 'target', () => this.proxyXhr);
267
+ defineProp(e, 'currentTarget', () => this.proxyXhr);
266
268
  this.proxyEvents[e.type] && this.proxyEvents[e.type].forEach(fn => {
267
269
  this.resThenable.then(() => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e));
268
270
  });
@@ -272,7 +274,7 @@ const AjaxHooker = function () {
272
274
  }
273
275
  setRequestHeader(header, value) {
274
276
  this.originalXhr.setRequestHeader(header, value);
275
- if (this.originalXhr.readyState !== 1) return;
277
+ if (!this.request) return;
276
278
  const headers = this.request.headers;
277
279
  headers[header] = header in headers ? `${headers[header]}, ${value}` : value;
278
280
  }