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