@whitesev/utils 1.4.2 → 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.
@@ -1163,7 +1163,17 @@ declare class Utils {
1163
1163
  );
1164
1164
  **/
1165
1165
  mutationObserver(target: HTMLElement | Node | NodeList | Document, observer_config: {
1166
+ /**
1167
+ * observer的配置
1168
+ */
1166
1169
  config?: MutationObserverInit;
1170
+ /**
1171
+ * 是否主动触发一次
1172
+ */
1173
+ immediate?: boolean;
1174
+ /**
1175
+ * 触发的回调函数
1176
+ */
1167
1177
  callback: MutationCallback;
1168
1178
  }): MutationObserver;
1169
1179
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "1.4.2",
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.10";
150
+ version = "2024.6.14";
151
151
 
152
152
  /**
153
153
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -2579,14 +2579,34 @@ class Utils {
2579
2579
  mutationObserver(
2580
2580
  target: HTMLElement | Node | NodeList | Document,
2581
2581
  observer_config: {
2582
+ /**
2583
+ * observer的配置
2584
+ */
2582
2585
  config?: MutationObserverInit;
2586
+ /**
2587
+ * 是否主动触发一次
2588
+ */
2589
+ immediate?: boolean;
2590
+ /**
2591
+ * 触发的回调函数
2592
+ */
2583
2593
  callback: MutationCallback;
2584
2594
  }
2585
2595
  ): MutationObserver;
2586
2596
  mutationObserver(
2587
2597
  target: HTMLElement | Node | NodeList | Document,
2588
2598
  observer_config: {
2599
+ /**
2600
+ * observer的配置
2601
+ */
2589
2602
  config?: MutationObserverInit;
2603
+ /**
2604
+ * 是否主动触发一次
2605
+ */
2606
+ immediate?: boolean;
2607
+ /**
2608
+ * 触发的回调函数
2609
+ */
2590
2610
  callback: MutationCallback;
2591
2611
  }
2592
2612
  ): MutationObserver {
@@ -2640,6 +2660,7 @@ class Utils {
2640
2660
  */
2641
2661
  characterDataOldValue: void 0 as any as boolean,
2642
2662
  },
2663
+ immediate: false,
2643
2664
  };
2644
2665
  observer_config = UtilsContext.assign(
2645
2666
  default_obverser_config,
@@ -2672,6 +2693,10 @@ class Utils {
2672
2693
  /* 未知 */
2673
2694
  console.error("Utils.mutationObserver 未知参数", arguments);
2674
2695
  }
2696
+ if (observer_config.immediate) {
2697
+ /* 主动触发一次 */
2698
+ observer_config.callback([], mutationObserver);
2699
+ }
2675
2700
  return mutationObserver;
2676
2701
  }
2677
2702
  /**
@@ -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
  }