@whitesev/utils 1.0.9 → 1.1.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.
@@ -2476,6 +2476,10 @@ System.register('Utils', [], (function (exports) {
2476
2476
  #delayTime = 0;
2477
2477
  #callback;
2478
2478
  #context;
2479
+ lock;
2480
+ unlock;
2481
+ run;
2482
+ isLock;
2479
2483
  constructor(callback, context, delayTime) {
2480
2484
  this.#callback = callback;
2481
2485
  if (typeof context === "number") {
@@ -2486,46 +2490,50 @@ System.register('Utils', [], (function (exports) {
2486
2490
  this.#delayTime = delayTime;
2487
2491
  this.#context = context;
2488
2492
  }
2489
- }
2490
- /**
2491
- * 判断是否被锁
2492
- */
2493
- isLock() {
2494
- return this.#flag;
2495
- }
2496
- /**
2497
- * 锁
2498
- */
2499
- lock() {
2500
- this.#flag = true;
2501
- }
2502
- /**
2503
- * 解锁
2504
- */
2505
- unlock() {
2506
- setTimeout(() => {
2507
- this.#flag = false;
2508
- }, this.#delayTime);
2509
- }
2510
- /**
2511
- * 执行
2512
- */
2513
- async run(...args) {
2514
- if (this.isLock()) {
2515
- return;
2516
- }
2517
- this.lock();
2518
- await this.#callback.apply(this.#context, args);
2519
- this.unlock();
2493
+ /**
2494
+ * 锁
2495
+ */
2496
+ this.lock = function () {
2497
+ this.#flag = true;
2498
+ };
2499
+ /**
2500
+ * 解锁
2501
+ */
2502
+ this.unlock = function () {
2503
+ setTimeout(() => {
2504
+ this.#flag = false;
2505
+ }, this.#delayTime);
2506
+ };
2507
+ /**
2508
+ * 判断是否被锁
2509
+ */
2510
+ this.isLock = function () {
2511
+ return this.#flag;
2512
+ };
2513
+ /**
2514
+ * 执行
2515
+ */
2516
+ this.run = async function (...args) {
2517
+ if (this.isLock()) {
2518
+ return;
2519
+ }
2520
+ this.lock();
2521
+ await this.#callback.apply(this.#context, args);
2522
+ this.unlock();
2523
+ };
2520
2524
  }
2521
2525
  }
2522
2526
 
2523
2527
  class Log {
2524
- /** 前面的TAG标志 */
2528
+ /** 是否禁用输出的flag */
2525
2529
  #disable = false;
2526
- tag = "";
2530
+ /** 前面的TAG标志 */
2531
+ tag = "Utils.Log";
2532
+ /* 使用的console函数 */
2527
2533
  #console = null;
2534
+ /* 当前输出的数量 */
2528
2535
  #logCount = 0;
2536
+ /* 配置 */
2529
2537
  #details = {
2530
2538
  tag: true,
2531
2539
  successColor: "#0000FF",
@@ -2536,10 +2544,6 @@ System.register('Utils', [], (function (exports) {
2536
2544
  autoClearConsole: false,
2537
2545
  logMaxCount: 999,
2538
2546
  };
2539
- /**
2540
- * 待恢复的函数或对象
2541
- */
2542
- #recoveryList = [];
2543
2547
  #msgColorDetails = [
2544
2548
  "font-weight: bold; color: cornflowerblue",
2545
2549
  "font-weight: bold; color: cornflowerblue",
@@ -2547,15 +2551,17 @@ System.register('Utils', [], (function (exports) {
2547
2551
  "font-weight: bold; color: cornflowerblue",
2548
2552
  ];
2549
2553
  /**
2550
- * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}}
2554
+ * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
2551
2555
  * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
2552
2556
  */
2553
- constructor(_GM_info_ = {
2554
- script: {
2555
- name: "Utils.Log",
2556
- },
2557
- }, console = global.console) {
2558
- this.tag = _GM_info_.script.name;
2557
+ constructor(_GM_info_, console = globalThis.console) {
2558
+ if (typeof _GM_info_ === "string") {
2559
+ this.tag = _GM_info_;
2560
+ }
2561
+ else if (typeof _GM_info_ === "object" &&
2562
+ typeof _GM_info_?.script?.name === "string") {
2563
+ this.tag = _GM_info_.script.name;
2564
+ }
2559
2565
  this.#console = console;
2560
2566
  }
2561
2567
  /**
@@ -2577,10 +2583,11 @@ System.register('Utils', [], (function (exports) {
2577
2583
  if (stackFunctionNamePositionMatch == null) {
2578
2584
  continue;
2579
2585
  }
2586
+ /* 获取最后一个,因为第一个是包含了at */
2580
2587
  let stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
2581
2588
  let stackFunctionNamePosition = stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
2582
2589
  if (stackFunctionName === "" ||
2583
- stackFunctionName.match(new RegExp("(^Utils.Log.|.<anonymous>$|^Function.each|^NodeList.forEach|^k.fn.init.each)", "g"))) {
2590
+ stackFunctionName.match(/^(Utils\.|)Log(\.|)|.<anonymous>$|^Function.each|^NodeList.forEach|^k.fn.init.each/g)) {
2584
2591
  continue;
2585
2592
  }
2586
2593
  else {
@@ -2621,7 +2628,7 @@ System.register('Utils', [], (function (exports) {
2621
2628
  * @param otherStyle 其它CSS
2622
2629
  */
2623
2630
  printContent(msg, color, otherStyle) {
2624
- this.checkClearConsole.apply(this);
2631
+ this.checkClearConsole();
2625
2632
  otherStyle = otherStyle || "";
2626
2633
  let stackSplit = new Error().stack.split("\n");
2627
2634
  stackSplit.splice(0, 2);
@@ -2710,7 +2717,7 @@ System.register('Utils', [], (function (exports) {
2710
2717
  table(msg, color = this.#details.infoColor, otherStyle = "") {
2711
2718
  if (this.#disable)
2712
2719
  return;
2713
- this.checkClearConsole.apply(this);
2720
+ this.checkClearConsole();
2714
2721
  let stack = new Error().stack.split("\n");
2715
2722
  stack.splice(0, 1);
2716
2723
  let errorStackParse = this.parseErrorStack(stack);
@@ -3079,7 +3086,7 @@ System.register('Utils', [], (function (exports) {
3079
3086
  /// <reference path="./ajaxHooker/index.d.ts" />
3080
3087
  class Utils {
3081
3088
  /** 版本号 */
3082
- version = "2024.5.25";
3089
+ version = "2024.5.28";
3083
3090
  addStyle(cssText) {
3084
3091
  if (typeof cssText !== "string") {
3085
3092
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4646,42 +4653,35 @@ System.register('Utils', [], (function (exports) {
4646
4653
  callback: () => { },
4647
4654
  config: {
4648
4655
  /**
4649
- * @type {boolean|undefined}
4650
4656
  * + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
4651
4657
  * + false (默认) 不生效
4652
4658
  */
4653
4659
  subtree: void 0,
4654
4660
  /**
4655
- * @type {boolean|undefined}
4656
4661
  * + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
4657
4662
  * + false (默认) 不生效
4658
4663
  */
4659
4664
  childList: void 0,
4660
4665
  /**
4661
- * @type {boolean|undefined}
4662
4666
  * + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
4663
4667
  * + false (默认) 不生效
4664
4668
  */
4665
4669
  attributes: void 0,
4666
4670
  /**
4667
4671
  * 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
4668
- * @type {[...string]|undefined}
4669
4672
  */
4670
4673
  attributeFilter: void 0,
4671
4674
  /**
4672
- * @type {boolean|undefined}
4673
4675
  * + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
4674
4676
  * + false (默认) 不生效
4675
4677
  */
4676
4678
  attributeOldValue: void 0,
4677
4679
  /**
4678
- * @type {boolean|undefined}
4679
4680
  * + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
4680
4681
  * + false (默认) 不生效
4681
4682
  */
4682
4683
  characterData: void 0,
4683
4684
  /**
4684
- * @type {boolean|undefined}
4685
4685
  * + true 记录前一个被监听的节点中发生的文本变化
4686
4686
  * + false (默认) 不生效
4687
4687
  */
@@ -4689,11 +4689,10 @@ System.register('Utils', [], (function (exports) {
4689
4689
  },
4690
4690
  };
4691
4691
  observer_config = UtilsContext.assign(default_obverser_config, observer_config);
4692
- let MutationObserver = UtilsCore.window.MutationObserver ||
4692
+ let windowMutationObserver = window.MutationObserver ||
4693
4693
  UtilsCore.window.webkitMutationObserver ||
4694
4694
  UtilsCore.window.MozMutationObserver;
4695
- /** @type {MutationObserver} */
4696
- let mutationObserver = new MutationObserver(function (mutations, observer) {
4695
+ let mutationObserver = new windowMutationObserver(function (mutations, observer) {
4697
4696
  observer_config?.callback(mutations, observer);
4698
4697
  });
4699
4698
  if (target instanceof Node) {