@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.iife.js
CHANGED
|
@@ -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
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
this.#flag
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
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
|
-
/**
|
|
2526
|
+
/** 是否禁用输出的flag */
|
|
2523
2527
|
#disable = false;
|
|
2524
|
-
|
|
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
|
-
|
|
2553
|
-
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
|
|
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(
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
4690
|
+
let windowMutationObserver = window.MutationObserver ||
|
|
4691
4691
|
UtilsCore.window.webkitMutationObserver ||
|
|
4692
4692
|
UtilsCore.window.MozMutationObserver;
|
|
4693
|
-
|
|
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) {
|