@whitesev/utils 1.0.0

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 (55) hide show
  1. package/README.md +172 -0
  2. package/dist/index.cjs.js +6017 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.esm.js +6015 -0
  6. package/dist/index.esm.js.map +1 -0
  7. package/dist/index.umd.js +6023 -0
  8. package/dist/index.umd.js.map +1 -0
  9. package/dist/src/ColorConversion.d.ts +45 -0
  10. package/dist/src/Dictionary.d.ts +87 -0
  11. package/dist/src/GBKEncoder.d.ts +17 -0
  12. package/dist/src/Hooks.d.ts +5 -0
  13. package/dist/src/Httpx.d.ts +50 -0
  14. package/dist/src/LockFunction.d.ts +16 -0
  15. package/dist/src/Log.d.ts +66 -0
  16. package/dist/src/Progress.d.ts +6 -0
  17. package/dist/src/Utils.d.ts +1560 -0
  18. package/dist/src/UtilsCore.d.ts +9 -0
  19. package/dist/src/UtilsGMCookie.d.ts +36 -0
  20. package/dist/src/UtilsGMMenu.d.ts +119 -0
  21. package/dist/src/ajaxHooker.d.ts +6 -0
  22. package/dist/src/indexedDB.d.ts +165 -0
  23. package/dist/src/tryCatch.d.ts +31 -0
  24. package/index.ts +3 -0
  25. package/package.json +34 -0
  26. package/rollup.config.js +28 -0
  27. package/src/ColorConversion.ts +124 -0
  28. package/src/Dictionary.ts +158 -0
  29. package/src/GBKEncoder.js +111 -0
  30. package/src/GBKEncoder.ts +116 -0
  31. package/src/Hooks.js +73 -0
  32. package/src/Httpx.js +747 -0
  33. package/src/LockFunction.js +35 -0
  34. package/src/Log.js +256 -0
  35. package/src/Progress.js +98 -0
  36. package/src/Utils.ts +4495 -0
  37. package/src/UtilsCore.ts +39 -0
  38. package/src/UtilsGMCookie.ts +167 -0
  39. package/src/UtilsGMMenu.js +464 -0
  40. package/src/ajaxHooker.js +560 -0
  41. package/src/indexedDB.js +355 -0
  42. package/src/tryCatch.js +100 -0
  43. package/src/types/AjaxHooker.d.ts +153 -0
  44. package/src/types/DOMUtils.d.ts +188 -0
  45. package/src/types/Hook.d.ts +16 -0
  46. package/src/types/Httpx.d.ts +1308 -0
  47. package/src/types/Indexdb.d.ts +128 -0
  48. package/src/types/LockFunction.d.ts +47 -0
  49. package/src/types/Log.d.ts +91 -0
  50. package/src/types/Progress.d.ts +30 -0
  51. package/src/types/TryCatch.d.ts +6 -0
  52. package/src/types/UtilsCore.d.ts +7 -0
  53. package/src/types/UtilsGMMenu.d.ts +224 -0
  54. package/src/types/global.d.ts +58 -0
  55. package/tsconfig.json +32 -0
@@ -0,0 +1,39 @@
1
+ const UtilsCoreDefaultEnv: UtilsCoreOption = {
2
+ document: document,
3
+ window: window,
4
+ globalThis: globalThis,
5
+ self: self,
6
+ top: top as Window,
7
+ };
8
+ const UtilsCoreEnv: UtilsCoreOption = {
9
+ document: document,
10
+ window: window,
11
+ globalThis: globalThis,
12
+ self: self,
13
+ top: top as Window,
14
+ };
15
+ const UtilsCore = {
16
+ init(option?: UtilsCoreOption) {
17
+ if (!option) {
18
+ option = Object.assign({}, UtilsCoreDefaultEnv);
19
+ }
20
+ Object.assign(UtilsCoreEnv, option);
21
+ },
22
+ get document() {
23
+ return UtilsCoreEnv.document;
24
+ },
25
+ get window() {
26
+ return UtilsCoreEnv.window;
27
+ },
28
+ get globalThis() {
29
+ return UtilsCoreEnv.globalThis;
30
+ },
31
+ get self() {
32
+ return UtilsCoreEnv.self;
33
+ },
34
+ get top() {
35
+ return UtilsCoreEnv.top;
36
+ },
37
+ };
38
+
39
+ export { UtilsCore };
@@ -0,0 +1,167 @@
1
+ import { Utils } from "./Utils";
2
+
3
+ declare interface UtilsGMCookieListResult {
4
+ /** 为 window.location.hostname */
5
+ domain: string;
6
+ expirationDate: null;
7
+ hostOnly: true;
8
+ httpOnly: false;
9
+ name: string;
10
+ path: "/";
11
+ sameSite: "unspecified";
12
+ secure: true;
13
+ session: false;
14
+ value: string;
15
+ }
16
+
17
+ declare interface UtilsGMCookieListOptions {
18
+ /** 默认为当前的url */
19
+ url: string;
20
+ /** 默认为当前的域名(window.location.hostname) */
21
+ domain: string;
22
+ /** 需要检索的Cookie的名字 */
23
+ name: string;
24
+ /** 需要检索的Cookie的路径,默认为"/" */
25
+ path: string;
26
+ }
27
+
28
+ declare interface UtilsGMCookieSetOptions {
29
+ /** 默认为当前的url */
30
+ url?: string;
31
+ /** 默认为当前的域名(window.location.hostname) */
32
+ domain?: string;
33
+ /** 需要检索的Cookie的名字 */
34
+ name?: string;
35
+ /** 需要检索的Cookie的路径,默认为"/" */
36
+ path?: string;
37
+ /** 值 */
38
+ value?: string | number;
39
+ /** */
40
+ secure?: boolean;
41
+ /** */
42
+ httpOnly?: boolean;
43
+ /** Cookie过期时间,默认为30天 */
44
+ expirationDate?: number;
45
+ }
46
+
47
+ declare interface UtilsGMCookieDeleteOptions {
48
+ /** 默认为当前的url */
49
+ url: string;
50
+ /** 需要检索的Cookie的名字 */
51
+ name: string;
52
+ }
53
+
54
+ class UtilsGMCookie {
55
+ /**
56
+ * 获取Cookie
57
+ * @param paramDetails
58
+ * @param callback
59
+ * + cookies object[]
60
+ * + error string|undefined
61
+ **/
62
+ list(
63
+ paramDetails: Partial<UtilsGMCookieListResult> = {},
64
+ callback = (resultData: UtilsGMCookieListResult[], error?: Error) => {}
65
+ ) {
66
+ let resultData: UtilsGMCookieListResult[] = [];
67
+ try {
68
+ let details: Partial<UtilsGMCookieListResult> = {
69
+ // @ts-ignore
70
+ url: globalThis.location.href,
71
+ domain: globalThis.location.hostname,
72
+ name: "",
73
+ path: "/",
74
+ };
75
+ details = Utils.assign(details, paramDetails);
76
+ let cookies = document.cookie.split(";");
77
+ cookies.forEach((item) => {
78
+ item = item.trimStart();
79
+ let itemName = item.split("=")[0];
80
+ let itemValue = item.replace(new RegExp("^" + itemName + "="), "");
81
+ let nameRegexp =
82
+ (details.name as any) instanceof RegExp
83
+ ? details.name
84
+ : new RegExp("^" + details.name, "g");
85
+ if (itemName.match(nameRegexp as RegExp)) {
86
+ resultData.push({
87
+ domain: globalThis.location.hostname,
88
+ expirationDate: null,
89
+ hostOnly: true,
90
+ httpOnly: false,
91
+ name: itemName,
92
+ path: "/",
93
+ sameSite: "unspecified",
94
+ secure: true,
95
+ session: false,
96
+ value: itemValue,
97
+ });
98
+ return;
99
+ }
100
+ });
101
+ callback(resultData);
102
+ } catch (error) {
103
+ callback(resultData, error as Error);
104
+ }
105
+ }
106
+ /**
107
+ * 设置Cookie
108
+ * @param paramDetails
109
+ * @param callback
110
+ */
111
+ set(paramDetails = {}, callback = (error?: Error) => {}) {
112
+ try {
113
+ let details: Partial<UtilsGMCookieSetOptions> = {
114
+ url: window.location.href,
115
+ name: "",
116
+ value: "",
117
+ domain: window.location.hostname,
118
+ path: "/",
119
+ secure: true,
120
+ httpOnly: false,
121
+ /**
122
+ * Expires in 30 days
123
+ */
124
+ expirationDate: Math.floor(Date.now()) + 60 * 60 * 24 * 30,
125
+ };
126
+ details = Utils.assign(details, paramDetails);
127
+ let life = details.expirationDate
128
+ ? details.expirationDate
129
+ : Math.floor(Date.now()) + 60 * 60 * 24 * 30;
130
+ let cookieStr =
131
+ details.name +
132
+ "=" +
133
+ decodeURIComponent(details.value as string) +
134
+ ";expires=" +
135
+ (new Date(life) as any).toGMTString() +
136
+ "; path=/";
137
+ document.cookie = cookieStr;
138
+ callback();
139
+ } catch (error) {
140
+ callback(error as Error);
141
+ }
142
+ }
143
+ /**
144
+ * 删除Cookie
145
+ * @param paramDetails
146
+ * @param callback
147
+ */
148
+ delete(paramDetails = {}, callback = (error?: Error) => {}) {
149
+ try {
150
+ let details: Partial<UtilsGMCookieDeleteOptions> = {
151
+ url: window.location.href,
152
+ name: "",
153
+ // @ts-ignore
154
+ firstPartyDomain: "",
155
+ };
156
+ details = Utils.assign(details, paramDetails);
157
+ let cookieStr =
158
+ details.name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
159
+ document.cookie = cookieStr;
160
+ callback();
161
+ } catch (error) {
162
+ callback(error as Error);
163
+ }
164
+ }
165
+ }
166
+
167
+ export { UtilsGMCookie };
@@ -0,0 +1,464 @@
1
+ /**
2
+ *
3
+ * @param {UtilsGMMenuConstructorOptions} details
4
+ */
5
+ const GMMenu = function (details) {
6
+ const GM_Api = {
7
+ /**
8
+ * 获取存储的数据
9
+ * @type {GM_getValue}
10
+ */
11
+ getValue: details.GM_getValue,
12
+ /**
13
+ * 设置数据到存储
14
+ * @type {GM_setValue}
15
+ */
16
+ setValue: details.GM_setValue,
17
+ /**
18
+ * 注册菜单
19
+ * @type {GM_registerMenuCommand}
20
+ */
21
+ registerMenuCommand: details.GM_registerMenuCommand,
22
+ /**
23
+ * 卸载菜单
24
+ * @type {GM_unregisterMenuCommand}
25
+ */
26
+ unregisterMenuCommand: details.GM_unregisterMenuCommand,
27
+ };
28
+ for (const keyName of Object.keys(GM_Api)) {
29
+ if (typeof GM_Api[keyName] !== "function") {
30
+ throw new Error(
31
+ `Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`
32
+ );
33
+ }
34
+ }
35
+ /** 上下文 */
36
+ const context = this;
37
+
38
+ const MenuHandle = {
39
+ $data: {
40
+ /**
41
+ * 菜单数据
42
+ * @type {UtilsGMMenuOptionData[]}
43
+ */
44
+ data: [],
45
+ /**
46
+ * 本地存储的键名
47
+ */
48
+ key: "GM_Menu_Local_Map",
49
+ },
50
+ $default: {
51
+ /** 自动刷新网页,默认为true */
52
+ autoReload:
53
+ typeof details.autoReload === "boolean" ? details.autoReload : true,
54
+ /**
55
+ * 菜单isStoreValue的默认值
56
+ */
57
+ isStoreValue: true,
58
+ },
59
+ $emoji: {
60
+ /**
61
+ * 菜单enable为true的emoji
62
+ */
63
+ success: "✅",
64
+ /**
65
+ * 菜单enable为false的emoji
66
+ */
67
+ error: "❌",
68
+ },
69
+ /**
70
+ * 初始化数据
71
+ */
72
+ init() {
73
+ for (let index = 0; index < this.$data.data.length; index++) {
74
+ let menuOption = this.$data.data[index]["data"];
75
+ menuOption.enable = Boolean(
76
+ this.getLocalMenuData(menuOption.key, menuOption.enable)
77
+ );
78
+ if (typeof menuOption.showText !== "function") {
79
+ menuOption.showText = (menuText, menuEnable) => {
80
+ if (menuEnable) {
81
+ return this.$emoji.success + " " + menuText;
82
+ } else {
83
+ return this.$emoji.error + " " + menuText;
84
+ }
85
+ };
86
+ }
87
+ }
88
+ },
89
+ /**
90
+ * 注册油猴菜单
91
+ * @param { ?UtilsGMMenuOptionData[] } menuOptions 如果存在,使用它
92
+ */
93
+ register(menuOptions) {
94
+ if (menuOptions == null) {
95
+ throw new TypeError("register菜单数据不能为空");
96
+ }
97
+ if (!Array.isArray(menuOptions)) {
98
+ menuOptions = [menuOptions];
99
+ }
100
+ for (let index = 0; index < menuOptions.length; index++) {
101
+ let cloneMenuOptionData = Utils.deepClone(menuOptions[index].data);
102
+ const { showText, clickCallBack } =
103
+ this.handleMenuData(cloneMenuOptionData);
104
+ let menuId = GM_Api.registerMenuCommand(showText, clickCallBack);
105
+ menuOptions[index].id = menuId;
106
+ cloneMenuOptionData.deleteMenu = function () {
107
+ GM_Api.unregisterMenuCommand(menuId);
108
+ };
109
+ Reflect.deleteProperty(menuOptions[index], "handleData");
110
+ menuOptions[index].handleData = cloneMenuOptionData;
111
+ }
112
+ },
113
+ /**
114
+ * 获取本地存储菜单键值
115
+ * @param {string} key 键
116
+ * @returns {boolean}
117
+ */
118
+ getLocalMenuData(key, defaultValue) {
119
+ let localData = GM_Api.getValue(this.$data.key, {});
120
+ if (key in localData) {
121
+ return localData[key];
122
+ } else {
123
+ return defaultValue;
124
+ }
125
+ },
126
+ /**
127
+ * 设置本地存储菜单键值
128
+ * @param {string} key 键
129
+ * @param {boolean} value 值
130
+ */
131
+ setLocalMenuData(key, value) {
132
+ let localData = GM_Api.getValue(this.$data.key, {});
133
+ localData[key] = value;
134
+ GM_Api.setValue(this.$data.key, localData);
135
+ },
136
+ /**
137
+ * 处理初始化配置
138
+ * @param { UtilsGMMenuOption } menuOption
139
+ */
140
+ handleInitDetail(menuOption) {
141
+ menuOption.enable = Boolean(
142
+ this.getLocalMenuData(menuOption.key, menuOption.enable)
143
+ );
144
+ if (typeof menuOption.showText !== "function") {
145
+ menuOption.showText = (menuText, menuEnable) => {
146
+ if (menuEnable) {
147
+ return this.$emoji.success + " " + menuText;
148
+ } else {
149
+ return this.$emoji.error + " " + menuText;
150
+ }
151
+ };
152
+ }
153
+ return menuOption;
154
+ },
155
+ /**
156
+ * 对菜单数据进行处理
157
+ * @param { UtilsGMMenuOption } menuOption
158
+ */
159
+ handleMenuData(menuOption) {
160
+ let menuLocalDataItemKey = menuOption.key;
161
+ /* 菜单默认开启的状态 */
162
+ let defaultEnable = Boolean(
163
+ this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable)
164
+ );
165
+ /** 油猴菜单上显示的文本 */
166
+ let showText = menuOption.showText(menuOption.text, defaultEnable);
167
+ const that = this;
168
+ const GMMenuOptions = {
169
+ /**
170
+ * 菜单的id
171
+ */
172
+ id: menuOption.id,
173
+ /**
174
+ * 点击菜单项后是否应关闭弹出菜单
175
+ */
176
+ autoClose: menuOption.autoClose,
177
+ /**
178
+ * 菜单项的可选访问键
179
+ */
180
+ accessKey: menuOption.accessKey,
181
+ /**
182
+ * 菜单项的鼠标悬浮上的工具提示
183
+ */
184
+ title: menuOption.title,
185
+ };
186
+ /* 点击菜单后触发callback后的网页是否刷新 */
187
+ menuOption.autoReload =
188
+ typeof menuOption.autoReload !== "boolean"
189
+ ? this.$default.autoReload
190
+ : menuOption.autoReload;
191
+ /* 点击菜单后触发callback后的网页是否存储值 */
192
+ menuOption.isStoreValue =
193
+ typeof menuOption.isStoreValue !== "boolean"
194
+ ? this.$default.isStoreValue
195
+ : menuOption.isStoreValue;
196
+ /**
197
+ * 用户点击菜单后的回调函数
198
+ * @param {MouseEvent|PointerEvent} event
199
+ */
200
+ function clickCallBack(event) {
201
+ let localEnable = Boolean(
202
+ that.getLocalMenuData(menuLocalDataItemKey, defaultEnable)
203
+ );
204
+ if (menuOption.isStoreValue) {
205
+ that.setLocalMenuData(menuLocalDataItemKey, !localEnable);
206
+ }
207
+ if (typeof menuOption.callback === "function") {
208
+ menuOption.callback({
209
+ key: menuLocalDataItemKey,
210
+ enable: !localEnable,
211
+ oldEnable: localEnable,
212
+ event: event,
213
+ storeValue(value) {
214
+ that.setLocalMenuData(menuLocalDataItemKey, value);
215
+ },
216
+ });
217
+ }
218
+ /* 不刷新网页就刷新菜单 */
219
+ if (menuOption.autoReload) {
220
+ window.location.reload();
221
+ } else {
222
+ context.update();
223
+ }
224
+ }
225
+
226
+ return {
227
+ showText,
228
+ clickCallBack,
229
+ };
230
+ },
231
+ /**
232
+ * 获取目标菜单配置数据
233
+ * @param {string} menuKey 菜单-键key
234
+ */
235
+ getMenuData(menuKey) {
236
+ return this.$data.data.find((item) => item.data.key === menuKey);
237
+ },
238
+ /**
239
+ * 获取目标菜单配置
240
+ * @param {string} menuKey 菜单-键key
241
+ */
242
+ getMenuOption(menuKey) {
243
+ return this.$data.data.find((item) => item.data.key === menuKey)?.data;
244
+ },
245
+ /**
246
+ * 获取目标菜单处理后的配置
247
+ * @param {string} menuKey 菜单-键key
248
+ */
249
+ getMenuHandledOption(menuKey) {
250
+ return this.$data.data.find((item) => item.handleData.key === menuKey)
251
+ ?.handleData;
252
+ },
253
+ };
254
+
255
+ /**
256
+ * 新增菜单数据
257
+ * @param {UtilsGMMenuOption[]|UtilsGMMenuOption} paramData
258
+ */
259
+ this.add = function (paramData) {
260
+ if (Array.isArray(paramData)) {
261
+ for (const _paramData of paramData) {
262
+ MenuHandle.$data.data.push({
263
+ data: _paramData,
264
+ id: void 0,
265
+ });
266
+ }
267
+ } else {
268
+ MenuHandle.$data.data.push({
269
+ data: paramData,
270
+ id: void 0,
271
+ });
272
+ }
273
+ this.update();
274
+ };
275
+ /**
276
+ * 更新菜单数据
277
+ * @param { ?UtilsGMMenuOption[]|UtilsGMMenuOption } options 数据
278
+ */
279
+ this.update = function (options) {
280
+ /**
281
+ * @type {UtilsGMMenuOption[]}
282
+ */
283
+ let optionsList = [];
284
+ if (Array.isArray(options)) {
285
+ optionsList = [...optionsList, ...options];
286
+ } else if (options != null) {
287
+ optionsList = [...optionsList, options];
288
+ }
289
+ optionsList.forEach((item) => {
290
+ let targetMenu = MenuHandle.getMenuOption(item.key);
291
+ if (targetMenu) {
292
+ Object.assign(targetMenu, item);
293
+ }
294
+ });
295
+ MenuHandle.$data.data.forEach((value) => {
296
+ if (value.handleData) {
297
+ value.handleData.deleteMenu();
298
+ }
299
+ });
300
+ MenuHandle.init();
301
+ MenuHandle.register(MenuHandle.$data.data);
302
+ };
303
+ /**
304
+ * 卸载菜单
305
+ * @param {number} menuId 已注册的菜单id
306
+ */
307
+ this.delete = function (menuId) {
308
+ GM_Api.unregisterMenuCommand(menuId);
309
+ };
310
+ /**
311
+ * 根据键值获取enable值
312
+ * @param {string} menuKey 菜单-键key
313
+ * @returns {boolean}
314
+ */
315
+ this.get = function (menuKey) {
316
+ return this.getEnable(menuKey);
317
+ };
318
+ /**
319
+ * 根据键值获取enable值
320
+ * @param {string} menuKey 菜单-键key
321
+ * @returns {boolean}
322
+ */
323
+ this.getEnable = function (menuKey) {
324
+ return MenuHandle.getMenuHandledOption(menuKey).enable;
325
+ };
326
+ /**
327
+ * 根据键值获取text值
328
+ * @param {string} menuKey 菜单-键key
329
+ * @returns {string}
330
+ */
331
+ this.getText = function (menuKey) {
332
+ return MenuHandle.getMenuHandledOption(menuKey).text;
333
+ };
334
+ /**
335
+ * 根据键值获取showText函数的值
336
+ * @param {string} menuKey 菜单-键key
337
+ * @returns {string}
338
+ */
339
+ this.getShowTextValue = function (menuKey) {
340
+ return MenuHandle.getMenuHandledOption(menuKey).showText(
341
+ this.getText(menuKey),
342
+ this.get(menuKey)
343
+ );
344
+ };
345
+ /**
346
+ * 获取当前已注册菜单的id
347
+ * @param {string} menuKey
348
+ * @returns {?number}
349
+ */
350
+ this.getMenuId = function (menuKey) {
351
+ let result = null;
352
+ for (let index = 0; index < MenuHandle.$data.data.length; index++) {
353
+ const optionData = MenuHandle.$data.data[index];
354
+ if (optionData.handleData.key === menuKey) {
355
+ result = optionData.id;
356
+ break;
357
+ }
358
+ }
359
+ return result;
360
+ };
361
+ /**
362
+ * 根据键值获取accessKey值
363
+ * @param {string} menuKey 菜单-键key
364
+ * @returns {?string}
365
+ */
366
+ this.getAccessKey = function (menuKey) {
367
+ return MenuHandle.getMenuHandledOption(menuKey).accessKey;
368
+ };
369
+ /**
370
+ * 根据键值获取autoClose值
371
+ * @param {string} menuKey 菜单-键key
372
+ * @returns {?boolean}
373
+ */
374
+ this.getAutoClose = function (menuKey) {
375
+ return MenuHandle.getMenuHandledOption(menuKey).autoClose;
376
+ };
377
+ /**
378
+ * 根据键值获取autoReload值
379
+ * @param {string} menuKey 菜单-键key
380
+ * @returns {boolean}
381
+ */
382
+ this.getAutoReload = function (menuKey) {
383
+ return MenuHandle.getMenuHandledOption(menuKey).autoReload;
384
+ };
385
+ /**
386
+ * 根据键值获取callback函数
387
+ * @param {string} menuKey 菜单-键key
388
+ * @returns {?Function}
389
+ */
390
+ this.getCallBack = function (menuKey) {
391
+ return MenuHandle.getMenuHandledOption(menuKey).callback;
392
+ };
393
+ /**
394
+ * 获取当enable为true时默认显示在菜单中前面的emoji图标
395
+ * @returns {string}
396
+ */
397
+ this.getEnableTrueEmoji = function () {
398
+ return MenuHandle.$emoji.success;
399
+ };
400
+ /**
401
+ * 获取当enable为false时默认显示在菜单中前面的emoji图标
402
+ * @returns {string}
403
+ */
404
+ this.getEnableFalseEmoji = function () {
405
+ return MenuHandle.$emoji.error;
406
+ };
407
+ /**
408
+ * 获取本地存储的菜单外部的键名
409
+ * @param {string} keyName
410
+ */
411
+ this.getLocalStorageKeyName = function () {
412
+ return MenuHandle.$data.key;
413
+ };
414
+ /**
415
+ * 设置菜单的值
416
+ * @param {string} menuKey 菜单-键key
417
+ * @param {any} value 需要设置的值
418
+ */
419
+ this.setValue = function (menuKey, value) {
420
+ MenuHandle.setLocalMenuData(menuKey, value);
421
+ };
422
+ /**
423
+ * 设置菜单的值
424
+ * @param {string} menuKey 菜单-键key
425
+ * @param {boolean} value 需要设置的值
426
+ */
427
+ this.setEnable = function (menuKey, value) {
428
+ this.setValue(menuKey, Boolean(value));
429
+ };
430
+ /**
431
+ * 设置当enable为true时默认显示在菜单中前面的emoji图标
432
+ * @param {string} emojiString
433
+ */
434
+ this.setEnableTrueEmoji = function (emojiString) {
435
+ if (typeof emojiString !== "string") {
436
+ throw new Error("参数emojiString必须是string类型");
437
+ }
438
+ MenuHandle.$emoji.success = emojiString;
439
+ };
440
+ /**
441
+ * 设置当enable为false时默认显示在菜单中前面的emoji图标
442
+ * @param {string} emojiString
443
+ */
444
+ this.setEnableFalseEmoji = function (emojiString) {
445
+ if (typeof emojiString !== "string") {
446
+ throw new Error("参数emojiString必须是string类型");
447
+ }
448
+ MenuHandle.$emoji.error = emojiString;
449
+ };
450
+ /**
451
+ * 设置本地存储的菜单外部的键名
452
+ * @param {string} keyName
453
+ */
454
+ this.setLocalStorageKeyName = function (keyName) {
455
+ if (typeof keyName !== "string") {
456
+ throw new Error("参数keyName必须是string类型");
457
+ }
458
+ MenuHandle.$data.key = keyName;
459
+ };
460
+
461
+ this.add(details?.data || []);
462
+ };
463
+
464
+ export { GMMenu };