@whitesev/utils 2.8.0 → 2.8.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.
Files changed (70) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +893 -874
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.cjs.js +893 -874
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.esm.js +893 -874
  7. package/dist/index.esm.js.map +1 -1
  8. package/dist/index.iife.js +893 -874
  9. package/dist/index.iife.js.map +1 -1
  10. package/dist/index.system.js +893 -874
  11. package/dist/index.system.js.map +1 -1
  12. package/dist/index.umd.js +893 -874
  13. package/dist/index.umd.js.map +1 -1
  14. package/dist/types/src/CommonUtil.d.ts +59 -59
  15. package/dist/types/src/DOMUtils.d.ts +1 -1
  16. package/dist/types/src/Dictionary.d.ts +1 -1
  17. package/dist/types/src/Httpx.d.ts +2 -2
  18. package/dist/types/src/Progress.d.ts +0 -4
  19. package/dist/types/src/TryCatch.d.ts +2 -2
  20. package/dist/types/src/Utils.d.ts +365 -365
  21. package/dist/types/src/UtilsGMCookie.d.ts +2 -2
  22. package/dist/types/src/UtilsGMMenu.d.ts +1 -1
  23. package/dist/types/src/indexedDB.d.ts +3 -3
  24. package/dist/types/src/types/Event.d.ts +188 -188
  25. package/dist/types/src/types/Httpx.d.ts +1344 -1343
  26. package/dist/types/src/types/Log.d.ts +19 -19
  27. package/dist/types/src/types/Progress.d.ts +20 -20
  28. package/dist/types/src/types/React.d.ts +119 -119
  29. package/dist/types/src/types/TryCatch.d.ts +9 -9
  30. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  31. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  32. package/dist/types/src/types/Vue2.d.ts +166 -166
  33. package/dist/types/src/types/WindowApi.d.ts +14 -14
  34. package/dist/types/src/types/ajaxHooker.d.ts +151 -151
  35. package/dist/types/src/types/env.d.ts +7 -2
  36. package/dist/types/src/types/global.d.ts +31 -31
  37. package/package.json +16 -7
  38. package/src/ColorConversion.ts +105 -106
  39. package/src/CommonUtil.ts +280 -279
  40. package/src/DOMUtils.ts +251 -272
  41. package/src/Dictionary.ts +153 -154
  42. package/src/GBKEncoder.ts +108 -112
  43. package/src/Hooks.ts +73 -81
  44. package/src/Httpx.ts +1457 -1466
  45. package/src/LockFunction.ts +62 -62
  46. package/src/Log.ts +258 -259
  47. package/src/ModuleRaid.js +1 -0
  48. package/src/Progress.ts +108 -114
  49. package/src/TryCatch.ts +86 -86
  50. package/src/Utils.ts +4772 -4825
  51. package/src/UtilsCommon.ts +14 -14
  52. package/src/UtilsGMCookie.ts +254 -261
  53. package/src/UtilsGMMenu.ts +445 -454
  54. package/src/Vue.ts +233 -229
  55. package/src/WindowApi.ts +59 -59
  56. package/src/ajaxHooker/ajaxHooker.js +1 -0
  57. package/src/indexedDB.ts +497 -502
  58. package/src/types/Event.d.ts +188 -188
  59. package/src/types/Httpx.d.ts +1344 -1343
  60. package/src/types/Log.d.ts +19 -19
  61. package/src/types/Progress.d.ts +20 -20
  62. package/src/types/React.d.ts +119 -119
  63. package/src/types/TryCatch.d.ts +9 -9
  64. package/src/types/UtilsGMCookie.d.ts +93 -93
  65. package/src/types/UtilsGMMenu.d.ts +77 -77
  66. package/src/types/Vue2.d.ts +166 -166
  67. package/src/types/WindowApi.d.ts +14 -14
  68. package/src/types/ajaxHooker.d.ts +151 -151
  69. package/src/types/env.d.ts +7 -2
  70. package/src/types/global.d.ts +31 -31
@@ -1,62 +1,62 @@
1
- export class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
2
- #flag: boolean = false;
3
- #delayTime: number = 0;
4
- #callback: K;
5
- #timeId: number | undefined = void 0;
6
- lock: () => void;
7
- unlock: () => void;
8
- run: (...args: any[]) => Promise<void>;
9
- isLock: () => boolean;
10
- /**
11
- * @param callback 需要执行的函数
12
- * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
13
- */
14
- constructor(callback: K, delayTime?: number);
15
- /**
16
- * @param callback 需要执行的函数
17
- * @param context (可选)函数作用域,默认:this(Utils)
18
- * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
19
- */
20
- constructor(callback: K, context?: any, delayTime?: number);
21
- constructor(callback: K, context?: any, delayTime?: number) {
22
- let that = this;
23
- this.#callback = callback;
24
- if (typeof context === "number") {
25
- this.#delayTime = context;
26
- } else {
27
- this.#delayTime = delayTime as number;
28
- }
29
- /**
30
- * 锁
31
- */
32
- this.lock = function () {
33
- that.#flag = true;
34
- clearTimeout(that.#timeId);
35
- };
36
- /**
37
- * 解锁
38
- */
39
- this.unlock = function () {
40
- that.#timeId = setTimeout(() => {
41
- that.#flag = false;
42
- }, that.#delayTime);
43
- };
44
- /**
45
- * 判断是否被锁
46
- */
47
- this.isLock = function () {
48
- return that.#flag;
49
- };
50
- /**
51
- * 执行
52
- */
53
- this.run = async function (...args: any[]) {
54
- if (that.isLock()) {
55
- return;
56
- }
57
- that.lock();
58
- await that.#callback.apply(this, args);
59
- that.unlock();
60
- };
61
- }
62
- }
1
+ export class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
2
+ #flag: boolean = false;
3
+ #delayTime: number = 0;
4
+ #callback: K;
5
+ #timeId: number | undefined = void 0;
6
+ lock: () => void;
7
+ unlock: () => void;
8
+ run: (...args: any[]) => Promise<void>;
9
+ isLock: () => boolean;
10
+ /**
11
+ * @param callback 需要执行的函数
12
+ * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
13
+ */
14
+ constructor(callback: K, delayTime?: number);
15
+ /**
16
+ * @param callback 需要执行的函数
17
+ * @param context (可选)函数作用域,默认:this(Utils)
18
+ * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
19
+ */
20
+ constructor(callback: K, context?: any, delayTime?: number);
21
+ constructor(callback: K, context?: any, delayTime?: number) {
22
+ const that = this;
23
+ this.#callback = callback;
24
+ if (typeof context === "number") {
25
+ this.#delayTime = context;
26
+ } else {
27
+ this.#delayTime = delayTime as number;
28
+ }
29
+ /**
30
+ * 锁
31
+ */
32
+ this.lock = function () {
33
+ that.#flag = true;
34
+ clearTimeout(that.#timeId);
35
+ };
36
+ /**
37
+ * 解锁
38
+ */
39
+ this.unlock = function () {
40
+ that.#timeId = setTimeout(() => {
41
+ that.#flag = false;
42
+ }, that.#delayTime);
43
+ };
44
+ /**
45
+ * 判断是否被锁
46
+ */
47
+ this.isLock = function () {
48
+ return that.#flag;
49
+ };
50
+ /**
51
+ * 执行
52
+ */
53
+ this.run = async function (...args: any[]) {
54
+ if (that.isLock()) {
55
+ return;
56
+ }
57
+ that.lock();
58
+ await that.#callback.apply(this, args);
59
+ that.unlock();
60
+ };
61
+ }
62
+ }
package/src/Log.ts CHANGED
@@ -1,259 +1,258 @@
1
- import type { UtilsLogOptions } from "./types/Log";
2
-
3
- export class Log {
4
- /** 是否禁用输出的flag */
5
- #disable: boolean = false;
6
- /** 前面的TAG标志 */
7
- tag: string = "Utils.Log";
8
- /* 使用的console函数 */
9
- #console: Console = null as any;
10
- /* 当前输出的数量 */
11
- #logCount = 0;
12
- /* 配置 */
13
- #details: UtilsLogOptions = {
14
- tag: true,
15
- successColor: "#0000FF",
16
- errorColor: "#FF0000",
17
- infoColor: "0",
18
- warnColor: "0",
19
- debug: false,
20
- autoClearConsole: false,
21
- logMaxCount: 999,
22
- };
23
- /**
24
- * 颜色配置
25
- */
26
- #msgColorDetails = [
27
- "font-weight: bold; color: cornflowerblue",
28
- "font-weight: bold; color: cornflowerblue",
29
- "font-weight: bold; color: darkorange",
30
- "font-weight: bold; color: cornflowerblue",
31
- ];
32
- /**
33
- * @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
34
- * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
35
- */
36
- constructor(
37
- __GM_info?:
38
- | {
39
- script: {
40
- name: string;
41
- };
42
- }
43
- | string,
44
- console: Console = window.console
45
- ) {
46
- if (typeof __GM_info === "string") {
47
- this.tag = __GM_info;
48
- } else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
49
- this.tag = __GM_info.script.name;
50
- }
51
- this.#console = console;
52
- }
53
-
54
- /**
55
- * 解析Error的堆栈获取实际调用者的函数名及函数所在的位置
56
- * @param stack
57
- */
58
- private parseErrorStack(stack: string[]) {
59
- let result = {
60
- name: "",
61
- position: "",
62
- };
63
- for (let stackString of stack) {
64
- stackString = stackString.trim();
65
- let stackFunctionNameMatch = stackString.match(/^at[\s]+(.+?)[\s]+/i);
66
- let stackFunctionNamePositionMatch = stackString.match(/^at[\s]+.+[\s]+\((.+?)\)/i);
67
- if (stackFunctionNameMatch == null) {
68
- continue;
69
- }
70
- if (stackFunctionNamePositionMatch == null) {
71
- continue;
72
- }
73
- /* 获取最后一个,因为第一个是包含了at */
74
- let stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
75
- let stackFunctionNamePosition =
76
- stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
77
- if (
78
- stackFunctionName === "" ||
79
- stackFunctionName.match(
80
- /^(Utils\.|)Log(\.|)|.<anonymous>$|^Function.each|^NodeList.forEach|^k.fn.init.each/g
81
- )
82
- ) {
83
- continue;
84
- } else {
85
- result.name = stackFunctionName;
86
- result.position = stackFunctionNamePosition;
87
- break;
88
- }
89
- }
90
- if (result.position === "") {
91
- let lastStackString = stack[stack.length - 1].trim();
92
- if (lastStackString.startsWith("at chrome-extension://")) {
93
- let lastStackMatch = lastStackString.match(/^at[\s]+(.+)/);
94
- if (lastStackMatch) {
95
- result.position = lastStackMatch[lastStackMatch.length - 1];
96
- }
97
- }
98
- }
99
- if (result.position === "") {
100
- result.position = stack[stack.length - 1].trim().replace(/^at[\s]*/g, "");
101
- }
102
- return result;
103
- }
104
- /**
105
- * 检测清理控制台
106
- */
107
- private checkClearConsole() {
108
- this.#logCount++;
109
- if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
110
- this.#console.clear();
111
- this.#logCount = 0;
112
- }
113
- }
114
-
115
- /**
116
- * 输出内容
117
- * @param msg 需要输出的内容
118
- * @param color 颜色
119
- * @param otherStyle 其它CSS
120
- */
121
- private printContent(msg: any[], color: string, otherStyle?: string) {
122
- this.checkClearConsole();
123
- otherStyle = otherStyle || "";
124
- let stackSplit = new Error()!.stack!.split("\n");
125
- stackSplit.splice(0, 2);
126
- let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
127
- let tagName = this.tag;
128
- let that = this;
129
-
130
- /** tag的html输出格式 */
131
- let tagNameHTML = `%c[${tagName}%c`;
132
- /** 调用的函数名的html输出格式 */
133
- let callerNameHTML = `%c${callerName}%c]%c`;
134
- callerName.trim() !== "" && (callerNameHTML = "-" + callerNameHTML);
135
- /**
136
- * 输出消息到控制台
137
- * @param message
138
- */
139
- function consoleMsg(message: any) {
140
- if (typeof message === "string") {
141
- that.#console.log(
142
- `${tagNameHTML}${callerNameHTML} %s`,
143
- ...that.#msgColorDetails,
144
- `color: ${color};${otherStyle}`,
145
- message
146
- );
147
- } else if (typeof message === "number") {
148
- that.#console.log(
149
- `${tagNameHTML}${callerNameHTML} %d`,
150
- ...that.#msgColorDetails,
151
- `color: ${color};${otherStyle}`,
152
- message
153
- );
154
- } else if (typeof message === "object") {
155
- that.#console.log(
156
- `${tagNameHTML}${callerNameHTML} %o`,
157
- ...that.#msgColorDetails,
158
- `color: ${color};${otherStyle}`,
159
- message
160
- );
161
- } else {
162
- that.#console.log(message);
163
- }
164
- }
165
- if (Array.isArray(msg)) {
166
- for (let index = 0; index < msg.length; index++) {
167
- consoleMsg(msg[index]);
168
- }
169
- } else {
170
- consoleMsg(msg);
171
- }
172
- if (this.#details.debug) {
173
- /* 如果开启调试模式,输出堆栈位置 */
174
- this.#console.log(callerPosition);
175
- }
176
- }
177
- /**
178
- * 控制台-普通输出
179
- * @param args 需要输出的内容
180
- * @example
181
- * log.info("输出信息","输出信息2","输出信息3","输出")
182
- */
183
- info(...args: any[]) {
184
- if (this.#disable) return;
185
- this.printContent(args, this.#details.infoColor);
186
- }
187
- /**
188
- * 控制台-警告输出
189
- * @param args 需要输出的内容
190
- * @example
191
- * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
192
- */
193
- warn(...args: any[]) {
194
- if (this.#disable) return;
195
- this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
196
- }
197
- /**
198
- * 控制台-错误输出
199
- * @param args 需要输出的内容
200
- * @example
201
- * log.error("输出错误","输出错误2","输出错误3","输出错误4")
202
- */
203
- error(...args: any[]) {
204
- if (this.#disable) return;
205
- this.printContent(args, this.#details.errorColor);
206
- }
207
- /**
208
- * 控制台-成功输出
209
- * @param args 需要输出的内容
210
- * @example
211
- * log.success("输出成功")
212
- */
213
- success(...args: any[]) {
214
- if (this.#disable) return;
215
- this.printContent(args, this.#details.successColor);
216
- }
217
- /**
218
- * 控制台-输出表格
219
- * @param msg 需要输出的内容
220
- * @example
221
- * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
222
- */
223
- table(msg: any[]) {
224
- if (this.#disable) return;
225
- this.checkClearConsole();
226
- let stack = new Error()!.stack!.split("\n");
227
- stack.splice(0, 1);
228
- let errorStackParse = this.parseErrorStack(stack);
229
- /** 堆栈函数名 */
230
- let stackFunctionName = errorStackParse.name;
231
- /** 堆栈位置 */
232
- let stackFunctionNamePosition = errorStackParse.position;
233
- let callerName = stackFunctionName;
234
- this.#console.log(
235
- `%c[${this.tag}%c-%c${callerName}%c]%c`,
236
- ...this.#msgColorDetails,
237
- `color: ${this.#details.infoColor};`
238
- );
239
- this.#console.table(msg);
240
- if (this.#details.debug) {
241
- this.#console.log(stackFunctionNamePosition);
242
- }
243
- }
244
- /**
245
- * 配置Log对象的颜色
246
- * @param paramDetails 配置信息
247
- */
248
- config(paramDetails: Partial<UtilsLogOptions>) {
249
- this.#details = Object.assign(this.#details, paramDetails);
250
- }
251
- /** 禁用输出 */
252
- disable() {
253
- this.#disable = true;
254
- }
255
- /** 恢复输出 */
256
- recovery() {
257
- this.#disable = false;
258
- }
259
- }
1
+ import type { UtilsLogOptions } from "./types/Log";
2
+
3
+ export class Log {
4
+ /** 是否禁用输出的flag */
5
+ #disable: boolean = false;
6
+ /** 前面的TAG标志 */
7
+ tag: string = "Utils.Log";
8
+ /* 使用的console函数 */
9
+ #console: Console = null as any;
10
+ /* 当前输出的数量 */
11
+ #logCount = 0;
12
+ /* 配置 */
13
+ #details: UtilsLogOptions = {
14
+ tag: true,
15
+ successColor: "#0000FF",
16
+ errorColor: "#FF0000",
17
+ infoColor: "0",
18
+ warnColor: "0",
19
+ debug: false,
20
+ autoClearConsole: false,
21
+ logMaxCount: 999,
22
+ };
23
+ /**
24
+ * 颜色配置
25
+ */
26
+ #msgColorDetails = [
27
+ "font-weight: bold; color: cornflowerblue",
28
+ "font-weight: bold; color: cornflowerblue",
29
+ "font-weight: bold; color: darkorange",
30
+ "font-weight: bold; color: cornflowerblue",
31
+ ];
32
+ /**
33
+ * @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
34
+ * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
35
+ */
36
+ constructor(
37
+ __GM_info?:
38
+ | {
39
+ script: {
40
+ name: string;
41
+ };
42
+ }
43
+ | string,
44
+ console: Console = window.console
45
+ ) {
46
+ if (typeof __GM_info === "string") {
47
+ this.tag = __GM_info;
48
+ } else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
49
+ this.tag = __GM_info.script.name;
50
+ }
51
+ this.#console = console;
52
+ }
53
+
54
+ /**
55
+ * 解析Error的堆栈获取实际调用者的函数名及函数所在的位置
56
+ * @param stack
57
+ */
58
+ private parseErrorStack(stack: string[]) {
59
+ const result = {
60
+ name: "",
61
+ position: "",
62
+ };
63
+ for (let stackString of stack) {
64
+ stackString = stackString.trim();
65
+ const stackFunctionNameMatch = stackString.match(/^at[\s]+(.+?)[\s]+/i);
66
+ const stackFunctionNamePositionMatch = stackString.match(/^at[\s]+.+[\s]+\((.+?)\)/i);
67
+ if (stackFunctionNameMatch == null) {
68
+ continue;
69
+ }
70
+ if (stackFunctionNamePositionMatch == null) {
71
+ continue;
72
+ }
73
+ /* 获取最后一个,因为第一个是包含了at */
74
+ const stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
75
+ const stackFunctionNamePosition = stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
76
+ if (
77
+ stackFunctionName === "" ||
78
+ stackFunctionName.match(/^(Utils\.|)Log(\.|)|.<anonymous>$|^Function.each|^NodeList.forEach|^k.fn.init.each/g)
79
+ ) {
80
+ continue;
81
+ } else {
82
+ result.name = stackFunctionName;
83
+ result.position = stackFunctionNamePosition;
84
+ break;
85
+ }
86
+ }
87
+ if (result.position === "") {
88
+ const lastStackString = stack[stack.length - 1].trim();
89
+ if (lastStackString.startsWith("at chrome-extension://")) {
90
+ const lastStackMatch = lastStackString.match(/^at[\s]+(.+)/);
91
+ if (lastStackMatch) {
92
+ result.position = lastStackMatch[lastStackMatch.length - 1];
93
+ }
94
+ }
95
+ }
96
+ if (result.position === "") {
97
+ result.position = stack[stack.length - 1].trim().replace(/^at[\s]*/g, "");
98
+ }
99
+ return result;
100
+ }
101
+ /**
102
+ * 检测清理控制台
103
+ */
104
+ private checkClearConsole() {
105
+ this.#logCount++;
106
+ if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
107
+ this.#console.clear();
108
+ this.#logCount = 0;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * 输出内容
114
+ * @param msg 需要输出的内容
115
+ * @param color 颜色
116
+ * @param otherStyle 其它CSS
117
+ */
118
+ private printContent(msg: any[], color: string, otherStyle?: string) {
119
+ this.checkClearConsole();
120
+ otherStyle = otherStyle || "";
121
+ const stackSplit = new Error()!.stack!.split("\n");
122
+ stackSplit.splice(0, 2);
123
+ const { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
124
+ const tagName = this.tag;
125
+ const that = this;
126
+
127
+ /** tag的html输出格式 */
128
+ const tagNameHTML = `%c[${tagName}%c`;
129
+ /** 调用的函数名的html输出格式 */
130
+ let callerNameHTML = `%c${callerName}%c]%c`;
131
+ if (callerName.trim() === "") {
132
+ callerNameHTML = `-${callerNameHTML}`;
133
+ }
134
+ /**
135
+ * 输出消息到控制台
136
+ * @param message
137
+ */
138
+ function consoleMsg(message: any) {
139
+ if (typeof message === "string") {
140
+ that.#console.log(
141
+ `${tagNameHTML}${callerNameHTML} %s`,
142
+ ...that.#msgColorDetails,
143
+ `color: ${color};${otherStyle}`,
144
+ message
145
+ );
146
+ } else if (typeof message === "number") {
147
+ that.#console.log(
148
+ `${tagNameHTML}${callerNameHTML} %d`,
149
+ ...that.#msgColorDetails,
150
+ `color: ${color};${otherStyle}`,
151
+ message
152
+ );
153
+ } else if (typeof message === "object") {
154
+ that.#console.log(
155
+ `${tagNameHTML}${callerNameHTML} %o`,
156
+ ...that.#msgColorDetails,
157
+ `color: ${color};${otherStyle}`,
158
+ message
159
+ );
160
+ } else {
161
+ that.#console.log(message);
162
+ }
163
+ }
164
+ if (Array.isArray(msg)) {
165
+ for (let index = 0; index < msg.length; index++) {
166
+ consoleMsg(msg[index]);
167
+ }
168
+ } else {
169
+ consoleMsg(msg);
170
+ }
171
+ if (this.#details.debug) {
172
+ /* 如果开启调试模式,输出堆栈位置 */
173
+ this.#console.log(callerPosition);
174
+ }
175
+ }
176
+ /**
177
+ * 控制台-普通输出
178
+ * @param args 需要输出的内容
179
+ * @example
180
+ * log.info("输出信息","输出信息2","输出信息3","输出")
181
+ */
182
+ info(...args: any[]) {
183
+ if (this.#disable) return;
184
+ this.printContent(args, this.#details.infoColor);
185
+ }
186
+ /**
187
+ * 控制台-警告输出
188
+ * @param args 需要输出的内容
189
+ * @example
190
+ * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
191
+ */
192
+ warn(...args: any[]) {
193
+ if (this.#disable) return;
194
+ this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
195
+ }
196
+ /**
197
+ * 控制台-错误输出
198
+ * @param args 需要输出的内容
199
+ * @example
200
+ * log.error("输出错误","输出错误2","输出错误3","输出错误4")
201
+ */
202
+ error(...args: any[]) {
203
+ if (this.#disable) return;
204
+ this.printContent(args, this.#details.errorColor);
205
+ }
206
+ /**
207
+ * 控制台-成功输出
208
+ * @param args 需要输出的内容
209
+ * @example
210
+ * log.success("输出成功")
211
+ */
212
+ success(...args: any[]) {
213
+ if (this.#disable) return;
214
+ this.printContent(args, this.#details.successColor);
215
+ }
216
+ /**
217
+ * 控制台-输出表格
218
+ * @param msg 需要输出的内容
219
+ * @example
220
+ * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
221
+ */
222
+ table(msg: any[]) {
223
+ if (this.#disable) return;
224
+ this.checkClearConsole();
225
+ const stack = new Error()!.stack!.split("\n");
226
+ stack.splice(0, 1);
227
+ const errorStackParse = this.parseErrorStack(stack);
228
+ /** 堆栈函数名 */
229
+ const stackFunctionName = errorStackParse.name;
230
+ /** 堆栈位置 */
231
+ const stackFunctionNamePosition = errorStackParse.position;
232
+ const callerName = stackFunctionName;
233
+ this.#console.log(
234
+ `%c[${this.tag}%c-%c${callerName}%c]%c`,
235
+ ...this.#msgColorDetails,
236
+ `color: ${this.#details.infoColor};`
237
+ );
238
+ this.#console.table(msg);
239
+ if (this.#details.debug) {
240
+ this.#console.log(stackFunctionNamePosition);
241
+ }
242
+ }
243
+ /**
244
+ * 配置Log对象的颜色
245
+ * @param paramDetails 配置信息
246
+ */
247
+ config(paramDetails: Partial<UtilsLogOptions>) {
248
+ this.#details = Object.assign(this.#details, paramDetails);
249
+ }
250
+ /** 禁用输出 */
251
+ disable() {
252
+ this.#disable = true;
253
+ }
254
+ /** 恢复输出 */
255
+ recovery() {
256
+ this.#disable = false;
257
+ }
258
+ }
package/src/ModuleRaid.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable */
1
2
  // ==UserScript==
2
3
  // @name ModuleRaid.js
3
4
  // @namespace http://tampermonkey.net/