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