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