@whitesev/utils 2.7.2 → 2.7.3
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 +98 -203
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +98 -203
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +98 -203
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +98 -203
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +98 -203
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +98 -203
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +4 -21
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/package.json +1 -1
- package/src/ColorConversion.ts +5 -18
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -22
- package/src/Dictionary.ts +2 -7
- package/src/GBKEncoder.ts +1 -6
- package/src/Hooks.ts +1 -4
- package/src/Httpx.ts +102 -277
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +7 -23
- package/src/Progress.ts +2 -10
- package/src/TryCatch.ts +3 -11
- package/src/Utils.ts +209 -555
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +10 -29
- package/src/Vue.ts +2 -11
- package/src/indexedDB.ts +3 -12
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +4 -21
- package/src/types/ajaxHooker.d.ts +1 -5
package/src/LockFunction.ts
CHANGED
package/src/Log.ts
CHANGED
|
@@ -45,10 +45,7 @@ export class Log {
|
|
|
45
45
|
) {
|
|
46
46
|
if (typeof __GM_info === "string") {
|
|
47
47
|
this.tag = __GM_info;
|
|
48
|
-
} else if (
|
|
49
|
-
typeof __GM_info === "object" &&
|
|
50
|
-
typeof __GM_info?.script?.name === "string"
|
|
51
|
-
) {
|
|
48
|
+
} else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
|
|
52
49
|
this.tag = __GM_info.script.name;
|
|
53
50
|
}
|
|
54
51
|
this.#console = console;
|
|
@@ -66,9 +63,7 @@ export class Log {
|
|
|
66
63
|
for (let stackString of stack) {
|
|
67
64
|
stackString = stackString.trim();
|
|
68
65
|
let stackFunctionNameMatch = stackString.match(/^at[\s]+(.+?)[\s]+/i);
|
|
69
|
-
let stackFunctionNamePositionMatch = stackString.match(
|
|
70
|
-
/^at[\s]+.+[\s]+\((.+?)\)/i
|
|
71
|
-
);
|
|
66
|
+
let stackFunctionNamePositionMatch = stackString.match(/^at[\s]+.+[\s]+\((.+?)\)/i);
|
|
72
67
|
if (stackFunctionNameMatch == null) {
|
|
73
68
|
continue;
|
|
74
69
|
}
|
|
@@ -76,12 +71,9 @@ export class Log {
|
|
|
76
71
|
continue;
|
|
77
72
|
}
|
|
78
73
|
/* 获取最后一个,因为第一个是包含了at */
|
|
79
|
-
let stackFunctionName =
|
|
80
|
-
stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
|
|
74
|
+
let stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
|
|
81
75
|
let stackFunctionNamePosition =
|
|
82
|
-
stackFunctionNamePositionMatch[
|
|
83
|
-
stackFunctionNamePositionMatch.length - 1
|
|
84
|
-
];
|
|
76
|
+
stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
|
|
85
77
|
if (
|
|
86
78
|
stackFunctionName === "" ||
|
|
87
79
|
stackFunctionName.match(
|
|
@@ -114,10 +106,7 @@ export class Log {
|
|
|
114
106
|
*/
|
|
115
107
|
private checkClearConsole() {
|
|
116
108
|
this.#logCount++;
|
|
117
|
-
if (
|
|
118
|
-
this.#details.autoClearConsole &&
|
|
119
|
-
this.#logCount > this.#details.logMaxCount
|
|
120
|
-
) {
|
|
109
|
+
if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
|
|
121
110
|
this.#console.clear();
|
|
122
111
|
this.#logCount = 0;
|
|
123
112
|
}
|
|
@@ -134,8 +123,7 @@ export class Log {
|
|
|
134
123
|
otherStyle = otherStyle || "";
|
|
135
124
|
let stackSplit = new Error()!.stack!.split("\n");
|
|
136
125
|
stackSplit.splice(0, 2);
|
|
137
|
-
let { name: callerName, position: callerPosition } =
|
|
138
|
-
this.parseErrorStack(stackSplit);
|
|
126
|
+
let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
|
|
139
127
|
let tagName = this.tag;
|
|
140
128
|
let that = this;
|
|
141
129
|
|
|
@@ -204,11 +192,7 @@ export class Log {
|
|
|
204
192
|
*/
|
|
205
193
|
warn(...args: any[]) {
|
|
206
194
|
if (this.#disable) return;
|
|
207
|
-
this.printContent(
|
|
208
|
-
args,
|
|
209
|
-
this.#details.warnColor,
|
|
210
|
-
"background: #FEF6D5;padding: 4px 6px 4px 0px;"
|
|
211
|
-
);
|
|
195
|
+
this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
|
|
212
196
|
}
|
|
213
197
|
/**
|
|
214
198
|
* 控制台-错误输出
|
package/src/Progress.ts
CHANGED
|
@@ -50,9 +50,7 @@ export class Progress {
|
|
|
50
50
|
constructor(paramConfig: ProgressParamConfig) {
|
|
51
51
|
this.#config = CommonUtil.assign(this.#config, paramConfig);
|
|
52
52
|
if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
"Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement"
|
|
55
|
-
);
|
|
53
|
+
throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
|
|
56
54
|
}
|
|
57
55
|
this.init();
|
|
58
56
|
}
|
|
@@ -90,13 +88,7 @@ export class Progress {
|
|
|
90
88
|
this.#ctx.clearRect(0, 0, this.#width, this.#height);
|
|
91
89
|
/* 开始绘制底圆 */
|
|
92
90
|
this.#ctx.beginPath();
|
|
93
|
-
this.#ctx.arc(
|
|
94
|
-
this.#width / 2,
|
|
95
|
-
this.#height / 2,
|
|
96
|
-
this.#config.circleRadius,
|
|
97
|
-
1,
|
|
98
|
-
8
|
|
99
|
-
);
|
|
91
|
+
this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, 1, 8);
|
|
100
92
|
this.#ctx.strokeStyle = this.#config.lineBgColor;
|
|
101
93
|
this.#ctx.stroke();
|
|
102
94
|
/* 开始绘制动态圆 */
|
package/src/TryCatch.ts
CHANGED
|
@@ -41,9 +41,7 @@ export const TryCatch = function (...args: any) {
|
|
|
41
41
|
callbackFunction = callback;
|
|
42
42
|
context = __context__ || this;
|
|
43
43
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
44
|
-
return result !== void 0
|
|
45
|
-
? result
|
|
46
|
-
: (TryCatchCore as any as UtilsTryCatchType);
|
|
44
|
+
return result !== void 0 ? result : (TryCatchCore as any as UtilsTryCatchType);
|
|
47
45
|
},
|
|
48
46
|
};
|
|
49
47
|
|
|
@@ -69,19 +67,13 @@ export const TryCatch = function (...args: any) {
|
|
|
69
67
|
} catch (error) {
|
|
70
68
|
if (defaultDetails.log) {
|
|
71
69
|
callback = callback as Function;
|
|
72
|
-
console.log(
|
|
73
|
-
`%c ${callback?.name ? callback?.name : callback + "出现错误"} `,
|
|
74
|
-
"color: #f20000"
|
|
75
|
-
);
|
|
70
|
+
console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
|
|
76
71
|
console.log(`%c 错误原因:${error}`, "color: #f20000");
|
|
77
72
|
console.trace(callback);
|
|
78
73
|
}
|
|
79
74
|
if (handleErrorFunc) {
|
|
80
75
|
if (typeof handleErrorFunc === "string") {
|
|
81
|
-
result = new Function(handleErrorFunc).apply(funcThis, [
|
|
82
|
-
...args,
|
|
83
|
-
error,
|
|
84
|
-
]);
|
|
76
|
+
result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
|
|
85
77
|
} else {
|
|
86
78
|
result = handleErrorFunc.apply(funcThis, [...args, error]);
|
|
87
79
|
}
|