@whitesev/utils 2.9.10 → 2.9.11
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 +46 -27
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +46 -27
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +46 -27
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +46 -27
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +46 -27
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +46 -27
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/UtilsGMMenu.d.ts +9 -7
- package/package.json +2 -2
- package/src/UtilsGMMenu.ts +47 -28
package/dist/index.esm.js
CHANGED
|
@@ -237,7 +237,7 @@ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
|
237
237
|
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
238
238
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
239
239
|
|
|
240
|
-
const version = "2.9.
|
|
240
|
+
const version = "2.9.11";
|
|
241
241
|
|
|
242
242
|
/* eslint-disable */
|
|
243
243
|
// ==UserScript==
|
|
@@ -5038,29 +5038,30 @@ class GMMenu {
|
|
|
5038
5038
|
},
|
|
5039
5039
|
};
|
|
5040
5040
|
/**
|
|
5041
|
-
* @param
|
|
5041
|
+
* @param constructOptions 菜单配置
|
|
5042
5042
|
*/
|
|
5043
|
-
constructor(
|
|
5044
|
-
this.GM_Api.getValue =
|
|
5045
|
-
this.GM_Api.setValue =
|
|
5046
|
-
this.GM_Api.registerMenuCommand =
|
|
5047
|
-
this.GM_Api.unregisterMenuCommand =
|
|
5048
|
-
this.MenuHandle.$default.autoReload =
|
|
5043
|
+
constructor(constructOptions) {
|
|
5044
|
+
this.GM_Api.getValue = constructOptions.GM_getValue;
|
|
5045
|
+
this.GM_Api.setValue = constructOptions.GM_setValue;
|
|
5046
|
+
this.GM_Api.registerMenuCommand = constructOptions.GM_registerMenuCommand;
|
|
5047
|
+
this.GM_Api.unregisterMenuCommand = constructOptions.GM_unregisterMenuCommand;
|
|
5048
|
+
this.MenuHandle.$default.autoReload =
|
|
5049
|
+
typeof constructOptions.autoReload === "boolean" ? constructOptions.autoReload : true;
|
|
5049
5050
|
for (const keyName of Object.keys(this.GM_Api)) {
|
|
5050
5051
|
if (typeof this.GM_Api[keyName] !== "function") {
|
|
5051
5052
|
throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
|
|
5052
5053
|
}
|
|
5053
5054
|
}
|
|
5054
|
-
this.add(
|
|
5055
|
+
this.add(constructOptions?.data || []);
|
|
5055
5056
|
}
|
|
5056
5057
|
/**
|
|
5057
5058
|
* 新增菜单数据
|
|
5058
|
-
* @param
|
|
5059
|
+
* @param options
|
|
5059
5060
|
*/
|
|
5060
|
-
__add(
|
|
5061
|
-
if (Array.isArray(
|
|
5062
|
-
for (let index = 0; index <
|
|
5063
|
-
const option =
|
|
5061
|
+
__add(options) {
|
|
5062
|
+
if (Array.isArray(options)) {
|
|
5063
|
+
for (let index = 0; index < options.length; index++) {
|
|
5064
|
+
const option = options[index];
|
|
5064
5065
|
this.MenuHandle.$data.data.push({
|
|
5065
5066
|
data: option,
|
|
5066
5067
|
id: void 0,
|
|
@@ -5069,7 +5070,7 @@ class GMMenu {
|
|
|
5069
5070
|
}
|
|
5070
5071
|
else {
|
|
5071
5072
|
this.MenuHandle.$data.data.push({
|
|
5072
|
-
data:
|
|
5073
|
+
data: options,
|
|
5073
5074
|
id: void 0,
|
|
5074
5075
|
});
|
|
5075
5076
|
}
|
|
@@ -5078,11 +5079,21 @@ class GMMenu {
|
|
|
5078
5079
|
* 新增菜单数据
|
|
5079
5080
|
*
|
|
5080
5081
|
* 自动调用.update()
|
|
5081
|
-
* @param
|
|
5082
|
+
* @param options
|
|
5082
5083
|
*/
|
|
5083
|
-
add(
|
|
5084
|
-
this.__add(
|
|
5084
|
+
add(options) {
|
|
5085
|
+
this.__add(options);
|
|
5085
5086
|
this.update();
|
|
5087
|
+
return {
|
|
5088
|
+
destory: () => {
|
|
5089
|
+
if (!Array.isArray(options)) {
|
|
5090
|
+
options = [options];
|
|
5091
|
+
}
|
|
5092
|
+
options.forEach((option) => {
|
|
5093
|
+
this.delete(option.key);
|
|
5094
|
+
});
|
|
5095
|
+
},
|
|
5096
|
+
};
|
|
5086
5097
|
}
|
|
5087
5098
|
/**
|
|
5088
5099
|
* 更新菜单数据
|
|
@@ -5102,14 +5113,14 @@ class GMMenu {
|
|
|
5102
5113
|
else if (options != null) {
|
|
5103
5114
|
menuOptionList = [...menuOptionList, options];
|
|
5104
5115
|
}
|
|
5105
|
-
menuOptionList.forEach((
|
|
5106
|
-
const oldMenuOption = this.MenuHandle.getMenuOption(
|
|
5116
|
+
menuOptionList.forEach((option) => {
|
|
5117
|
+
const oldMenuOption = this.MenuHandle.getMenuOption(option.key);
|
|
5107
5118
|
if (oldMenuOption) {
|
|
5108
5119
|
// 覆盖
|
|
5109
|
-
Object.assign(oldMenuOption,
|
|
5120
|
+
Object.assign(oldMenuOption, option);
|
|
5110
5121
|
}
|
|
5111
5122
|
else {
|
|
5112
|
-
this.__add(
|
|
5123
|
+
this.__add(option);
|
|
5113
5124
|
}
|
|
5114
5125
|
});
|
|
5115
5126
|
this.MenuHandle.$data.data.forEach((value) => {
|
|
@@ -5122,9 +5133,15 @@ class GMMenu {
|
|
|
5122
5133
|
}
|
|
5123
5134
|
/**
|
|
5124
5135
|
* 卸载菜单
|
|
5125
|
-
* @param menuId 已注册的菜单id
|
|
5136
|
+
* @param menuId 已注册的菜单id或者键名
|
|
5126
5137
|
*/
|
|
5127
5138
|
delete(menuId) {
|
|
5139
|
+
if (typeof menuId === "string") {
|
|
5140
|
+
const __menuId = this.getMenuId(menuId);
|
|
5141
|
+
if (__menuId != null) {
|
|
5142
|
+
menuId = __menuId;
|
|
5143
|
+
}
|
|
5144
|
+
}
|
|
5128
5145
|
this.GM_Api.unregisterMenuCommand(menuId);
|
|
5129
5146
|
}
|
|
5130
5147
|
/**
|
|
@@ -5146,7 +5163,9 @@ class GMMenu {
|
|
|
5146
5163
|
* @param menuKey 菜单-键key
|
|
5147
5164
|
*/
|
|
5148
5165
|
getShowTextValue(menuKey) {
|
|
5149
|
-
|
|
5166
|
+
const text = this.getText(menuKey);
|
|
5167
|
+
const enable = this.getEnable(menuKey);
|
|
5168
|
+
return this.MenuHandle.getMenuHandledOption(menuKey).showText(text, enable);
|
|
5150
5169
|
}
|
|
5151
5170
|
/**
|
|
5152
5171
|
* 获取当前已注册菜单的id
|
|
@@ -5155,9 +5174,9 @@ class GMMenu {
|
|
|
5155
5174
|
getMenuId(menuKey) {
|
|
5156
5175
|
let result = null;
|
|
5157
5176
|
for (let index = 0; index < this.MenuHandle.$data.data.length; index++) {
|
|
5158
|
-
const
|
|
5159
|
-
if (
|
|
5160
|
-
result =
|
|
5177
|
+
const option = this.MenuHandle.$data.data[index];
|
|
5178
|
+
if (option.handleData?.key === menuKey) {
|
|
5179
|
+
result = option.id;
|
|
5161
5180
|
break;
|
|
5162
5181
|
}
|
|
5163
5182
|
}
|