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