@whitesev/utils 2.9.10 → 2.9.12
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 +77 -43
- 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 +77 -43
- 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 +77 -43
- 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 +77 -43
- 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 +77 -43
- 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 +77 -43
- 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/CommonUtil.ts +32 -16
- package/src/UtilsGMMenu.ts +47 -28
package/dist/index.amd.js
CHANGED
|
@@ -239,7 +239,7 @@ define((function () { 'use strict';
|
|
|
239
239
|
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
240
240
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
241
241
|
|
|
242
|
-
const version = "2.9.
|
|
242
|
+
const version = "2.9.12";
|
|
243
243
|
|
|
244
244
|
/* eslint-disable */
|
|
245
245
|
// ==UserScript==
|
|
@@ -1473,40 +1473,55 @@ define((function () { 'use strict';
|
|
|
1473
1473
|
isNull(...args) {
|
|
1474
1474
|
let result = true;
|
|
1475
1475
|
const checkList = [...args];
|
|
1476
|
-
for (const
|
|
1477
|
-
let
|
|
1478
|
-
if (
|
|
1479
|
-
|
|
1476
|
+
for (const obj of checkList) {
|
|
1477
|
+
let flag = false;
|
|
1478
|
+
if (obj === null || obj === undefined) {
|
|
1479
|
+
// null undefined
|
|
1480
|
+
flag = true;
|
|
1480
1481
|
}
|
|
1481
1482
|
else {
|
|
1482
|
-
switch (typeof
|
|
1483
|
+
switch (typeof obj) {
|
|
1483
1484
|
case "object":
|
|
1484
|
-
if (typeof
|
|
1485
|
-
|
|
1486
|
-
|
|
1485
|
+
if (typeof obj[Symbol.iterator] === "function") {
|
|
1486
|
+
// 可迭代
|
|
1487
|
+
// Map Array NodeList HTMLCollection
|
|
1488
|
+
if (obj instanceof Map) {
|
|
1489
|
+
flag = obj.size === 0;
|
|
1490
|
+
}
|
|
1491
|
+
else {
|
|
1492
|
+
const length = obj.length;
|
|
1493
|
+
if (typeof length === "number") {
|
|
1494
|
+
flag = length === 0;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1487
1497
|
}
|
|
1488
1498
|
else {
|
|
1489
|
-
|
|
1499
|
+
if (obj?.toString() === "[object Object]") {
|
|
1500
|
+
// {}
|
|
1501
|
+
flag = Object.keys(obj).length === 0;
|
|
1502
|
+
}
|
|
1490
1503
|
}
|
|
1491
1504
|
break;
|
|
1492
1505
|
case "number":
|
|
1493
|
-
|
|
1506
|
+
flag = isNaN(obj) ? true : obj === 0;
|
|
1494
1507
|
break;
|
|
1495
|
-
case "string":
|
|
1496
|
-
|
|
1508
|
+
case "string": {
|
|
1509
|
+
const trimStr = obj.trim();
|
|
1510
|
+
flag = trimStr.trim() === "" || trimStr === "null" || trimStr === "undefined";
|
|
1497
1511
|
break;
|
|
1512
|
+
}
|
|
1498
1513
|
case "boolean":
|
|
1499
|
-
|
|
1514
|
+
flag = !obj;
|
|
1500
1515
|
break;
|
|
1501
1516
|
case "function": {
|
|
1502
|
-
const funcStr =
|
|
1517
|
+
const funcStr = obj.toString().replace(/\s/g, "");
|
|
1503
1518
|
/* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
|
|
1504
|
-
|
|
1519
|
+
flag = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
|
|
1505
1520
|
break;
|
|
1506
1521
|
}
|
|
1507
1522
|
}
|
|
1508
1523
|
}
|
|
1509
|
-
result = result &&
|
|
1524
|
+
result = result && flag;
|
|
1510
1525
|
}
|
|
1511
1526
|
return result;
|
|
1512
1527
|
}
|
|
@@ -5040,29 +5055,30 @@ define((function () { 'use strict';
|
|
|
5040
5055
|
},
|
|
5041
5056
|
};
|
|
5042
5057
|
/**
|
|
5043
|
-
* @param
|
|
5058
|
+
* @param constructOptions 菜单配置
|
|
5044
5059
|
*/
|
|
5045
|
-
constructor(
|
|
5046
|
-
this.GM_Api.getValue =
|
|
5047
|
-
this.GM_Api.setValue =
|
|
5048
|
-
this.GM_Api.registerMenuCommand =
|
|
5049
|
-
this.GM_Api.unregisterMenuCommand =
|
|
5050
|
-
this.MenuHandle.$default.autoReload =
|
|
5060
|
+
constructor(constructOptions) {
|
|
5061
|
+
this.GM_Api.getValue = constructOptions.GM_getValue;
|
|
5062
|
+
this.GM_Api.setValue = constructOptions.GM_setValue;
|
|
5063
|
+
this.GM_Api.registerMenuCommand = constructOptions.GM_registerMenuCommand;
|
|
5064
|
+
this.GM_Api.unregisterMenuCommand = constructOptions.GM_unregisterMenuCommand;
|
|
5065
|
+
this.MenuHandle.$default.autoReload =
|
|
5066
|
+
typeof constructOptions.autoReload === "boolean" ? constructOptions.autoReload : true;
|
|
5051
5067
|
for (const keyName of Object.keys(this.GM_Api)) {
|
|
5052
5068
|
if (typeof this.GM_Api[keyName] !== "function") {
|
|
5053
5069
|
throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
|
|
5054
5070
|
}
|
|
5055
5071
|
}
|
|
5056
|
-
this.add(
|
|
5072
|
+
this.add(constructOptions?.data || []);
|
|
5057
5073
|
}
|
|
5058
5074
|
/**
|
|
5059
5075
|
* 新增菜单数据
|
|
5060
|
-
* @param
|
|
5076
|
+
* @param options
|
|
5061
5077
|
*/
|
|
5062
|
-
__add(
|
|
5063
|
-
if (Array.isArray(
|
|
5064
|
-
for (let index = 0; index <
|
|
5065
|
-
const option =
|
|
5078
|
+
__add(options) {
|
|
5079
|
+
if (Array.isArray(options)) {
|
|
5080
|
+
for (let index = 0; index < options.length; index++) {
|
|
5081
|
+
const option = options[index];
|
|
5066
5082
|
this.MenuHandle.$data.data.push({
|
|
5067
5083
|
data: option,
|
|
5068
5084
|
id: void 0,
|
|
@@ -5071,7 +5087,7 @@ define((function () { 'use strict';
|
|
|
5071
5087
|
}
|
|
5072
5088
|
else {
|
|
5073
5089
|
this.MenuHandle.$data.data.push({
|
|
5074
|
-
data:
|
|
5090
|
+
data: options,
|
|
5075
5091
|
id: void 0,
|
|
5076
5092
|
});
|
|
5077
5093
|
}
|
|
@@ -5080,11 +5096,21 @@ define((function () { 'use strict';
|
|
|
5080
5096
|
* 新增菜单数据
|
|
5081
5097
|
*
|
|
5082
5098
|
* 自动调用.update()
|
|
5083
|
-
* @param
|
|
5099
|
+
* @param options
|
|
5084
5100
|
*/
|
|
5085
|
-
add(
|
|
5086
|
-
this.__add(
|
|
5101
|
+
add(options) {
|
|
5102
|
+
this.__add(options);
|
|
5087
5103
|
this.update();
|
|
5104
|
+
return {
|
|
5105
|
+
destory: () => {
|
|
5106
|
+
if (!Array.isArray(options)) {
|
|
5107
|
+
options = [options];
|
|
5108
|
+
}
|
|
5109
|
+
options.forEach((option) => {
|
|
5110
|
+
this.delete(option.key);
|
|
5111
|
+
});
|
|
5112
|
+
},
|
|
5113
|
+
};
|
|
5088
5114
|
}
|
|
5089
5115
|
/**
|
|
5090
5116
|
* 更新菜单数据
|
|
@@ -5104,14 +5130,14 @@ define((function () { 'use strict';
|
|
|
5104
5130
|
else if (options != null) {
|
|
5105
5131
|
menuOptionList = [...menuOptionList, options];
|
|
5106
5132
|
}
|
|
5107
|
-
menuOptionList.forEach((
|
|
5108
|
-
const oldMenuOption = this.MenuHandle.getMenuOption(
|
|
5133
|
+
menuOptionList.forEach((option) => {
|
|
5134
|
+
const oldMenuOption = this.MenuHandle.getMenuOption(option.key);
|
|
5109
5135
|
if (oldMenuOption) {
|
|
5110
5136
|
// 覆盖
|
|
5111
|
-
Object.assign(oldMenuOption,
|
|
5137
|
+
Object.assign(oldMenuOption, option);
|
|
5112
5138
|
}
|
|
5113
5139
|
else {
|
|
5114
|
-
this.__add(
|
|
5140
|
+
this.__add(option);
|
|
5115
5141
|
}
|
|
5116
5142
|
});
|
|
5117
5143
|
this.MenuHandle.$data.data.forEach((value) => {
|
|
@@ -5124,9 +5150,15 @@ define((function () { 'use strict';
|
|
|
5124
5150
|
}
|
|
5125
5151
|
/**
|
|
5126
5152
|
* 卸载菜单
|
|
5127
|
-
* @param menuId 已注册的菜单id
|
|
5153
|
+
* @param menuId 已注册的菜单id或者键名
|
|
5128
5154
|
*/
|
|
5129
5155
|
delete(menuId) {
|
|
5156
|
+
if (typeof menuId === "string") {
|
|
5157
|
+
const __menuId = this.getMenuId(menuId);
|
|
5158
|
+
if (__menuId != null) {
|
|
5159
|
+
menuId = __menuId;
|
|
5160
|
+
}
|
|
5161
|
+
}
|
|
5130
5162
|
this.GM_Api.unregisterMenuCommand(menuId);
|
|
5131
5163
|
}
|
|
5132
5164
|
/**
|
|
@@ -5148,7 +5180,9 @@ define((function () { 'use strict';
|
|
|
5148
5180
|
* @param menuKey 菜单-键key
|
|
5149
5181
|
*/
|
|
5150
5182
|
getShowTextValue(menuKey) {
|
|
5151
|
-
|
|
5183
|
+
const text = this.getText(menuKey);
|
|
5184
|
+
const enable = this.getEnable(menuKey);
|
|
5185
|
+
return this.MenuHandle.getMenuHandledOption(menuKey).showText(text, enable);
|
|
5152
5186
|
}
|
|
5153
5187
|
/**
|
|
5154
5188
|
* 获取当前已注册菜单的id
|
|
@@ -5157,9 +5191,9 @@ define((function () { 'use strict';
|
|
|
5157
5191
|
getMenuId(menuKey) {
|
|
5158
5192
|
let result = null;
|
|
5159
5193
|
for (let index = 0; index < this.MenuHandle.$data.data.length; index++) {
|
|
5160
|
-
const
|
|
5161
|
-
if (
|
|
5162
|
-
result =
|
|
5194
|
+
const option = this.MenuHandle.$data.data[index];
|
|
5195
|
+
if (option.handleData?.key === menuKey) {
|
|
5196
|
+
result = option.id;
|
|
5163
5197
|
break;
|
|
5164
5198
|
}
|
|
5165
5199
|
}
|