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