@whitesev/utils 1.9.6 → 1.9.8
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 +43 -33
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +43 -33
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +43 -33
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +43 -33
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +43 -33
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +43 -33
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -205,6 +205,7 @@ class GBKEncoder {
|
|
|
205
205
|
decode(str) {
|
|
206
206
|
var GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
|
|
207
207
|
var UTFMatcher = /%[0-9A-F]{2}/;
|
|
208
|
+
// @ts-ignore
|
|
208
209
|
var utf = true;
|
|
209
210
|
let that = this;
|
|
210
211
|
while (utf) {
|
|
@@ -1165,6 +1166,7 @@ class GMMenu {
|
|
|
1165
1166
|
let defaultEnable = Boolean(this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable));
|
|
1166
1167
|
/** 油猴菜单上显示的文本 */
|
|
1167
1168
|
let showText = menuOption.showText(menuOption.text, defaultEnable);
|
|
1169
|
+
// @ts-ignore
|
|
1168
1170
|
({
|
|
1169
1171
|
/**
|
|
1170
1172
|
* 菜单的id
|
|
@@ -2537,6 +2539,7 @@ class indexedDB {
|
|
|
2537
2539
|
#storeName;
|
|
2538
2540
|
#dbVersion;
|
|
2539
2541
|
/* websql的版本号,由于ios的问题,版本号的写法不一样 */
|
|
2542
|
+
// @ts-ignore
|
|
2540
2543
|
#slqVersion = "1";
|
|
2541
2544
|
/* 监听IndexDB */
|
|
2542
2545
|
#indexedDB = UtilsCore.window.indexedDB ||
|
|
@@ -2545,6 +2548,7 @@ class indexedDB {
|
|
|
2545
2548
|
UtilsCore.window.msIndexedDB;
|
|
2546
2549
|
/* 缓存数据库,避免同一个页面重复创建和销毁 */
|
|
2547
2550
|
#db = {};
|
|
2551
|
+
// @ts-ignore
|
|
2548
2552
|
#store = null;
|
|
2549
2553
|
#errorCode = {
|
|
2550
2554
|
/* 错误码 */
|
|
@@ -2659,6 +2663,7 @@ class indexedDB {
|
|
|
2659
2663
|
let request = idbStore.put(inData);
|
|
2660
2664
|
request.onsuccess = function (event) {
|
|
2661
2665
|
/* 保存成功有success 字段 */
|
|
2666
|
+
// @ts-ignore
|
|
2662
2667
|
event.target;
|
|
2663
2668
|
resolve({
|
|
2664
2669
|
success: true,
|
|
@@ -2668,6 +2673,7 @@ class indexedDB {
|
|
|
2668
2673
|
});
|
|
2669
2674
|
};
|
|
2670
2675
|
request.onerror = function (event) {
|
|
2676
|
+
// @ts-ignore
|
|
2671
2677
|
event.target;
|
|
2672
2678
|
resolve({
|
|
2673
2679
|
success: false,
|
|
@@ -2729,6 +2735,7 @@ class indexedDB {
|
|
|
2729
2735
|
}
|
|
2730
2736
|
};
|
|
2731
2737
|
request.onerror = function (event) {
|
|
2738
|
+
// @ts-ignore
|
|
2732
2739
|
event.target;
|
|
2733
2740
|
resolve({
|
|
2734
2741
|
success: false,
|
|
@@ -2786,6 +2793,7 @@ class indexedDB {
|
|
|
2786
2793
|
});
|
|
2787
2794
|
};
|
|
2788
2795
|
request.onerror = function (event) {
|
|
2796
|
+
// @ts-ignore
|
|
2789
2797
|
event.target;
|
|
2790
2798
|
resolve({
|
|
2791
2799
|
success: false,
|
|
@@ -2840,6 +2848,7 @@ class indexedDB {
|
|
|
2840
2848
|
}
|
|
2841
2849
|
};
|
|
2842
2850
|
request.onerror = function (event) {
|
|
2851
|
+
// @ts-ignore
|
|
2843
2852
|
event.target;
|
|
2844
2853
|
resolve({
|
|
2845
2854
|
success: false,
|
|
@@ -3815,7 +3824,9 @@ class Utils {
|
|
|
3815
3824
|
/* CODE FOR BROWSERS THAT SUPPORT window.find */
|
|
3816
3825
|
let windowFind = UtilsCore.self.find;
|
|
3817
3826
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
3818
|
-
if (strFound &&
|
|
3827
|
+
if (strFound &&
|
|
3828
|
+
UtilsCore.self.getSelection &&
|
|
3829
|
+
!UtilsCore.self.getSelection().anchorNode) {
|
|
3819
3830
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
3820
3831
|
}
|
|
3821
3832
|
if (!strFound) {
|
|
@@ -4887,7 +4898,8 @@ class Utils {
|
|
|
4887
4898
|
return result;
|
|
4888
4899
|
}
|
|
4889
4900
|
isThemeDark() {
|
|
4890
|
-
return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
4901
|
+
return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
4902
|
+
.matches;
|
|
4891
4903
|
}
|
|
4892
4904
|
isVisible(element, inView = false) {
|
|
4893
4905
|
let needCheckDomList = [];
|
|
@@ -5086,11 +5098,6 @@ class Utils {
|
|
|
5086
5098
|
}
|
|
5087
5099
|
mutationObserver(target, observer_config) {
|
|
5088
5100
|
let UtilsContext = this;
|
|
5089
|
-
if (!(target instanceof Node) &&
|
|
5090
|
-
!(target instanceof NodeList) &&
|
|
5091
|
-
!UtilsContext.isJQuery(target)) {
|
|
5092
|
-
throw new Error("Utils.mutationObserver 参数 target 必须为 Node|NodeList|jQuery类型");
|
|
5093
|
-
}
|
|
5094
5101
|
let default_obverser_config = {
|
|
5095
5102
|
/* 监听到元素有反馈,需执行的函数 */
|
|
5096
5103
|
callback: () => { },
|
|
@@ -5136,15 +5143,14 @@ class Utils {
|
|
|
5136
5143
|
let windowMutationObserver = UtilsCore.window.MutationObserver ||
|
|
5137
5144
|
UtilsCore.window.webkitMutationObserver ||
|
|
5138
5145
|
UtilsCore.window.MozMutationObserver;
|
|
5146
|
+
// 观察者对象
|
|
5139
5147
|
let mutationObserver = new windowMutationObserver(function (mutations, observer) {
|
|
5140
|
-
observer_config
|
|
5148
|
+
if (typeof observer_config.callback === "function") {
|
|
5149
|
+
observer_config.callback(mutations, observer);
|
|
5150
|
+
}
|
|
5141
5151
|
});
|
|
5142
|
-
if (target instanceof
|
|
5143
|
-
|
|
5144
|
-
mutationObserver.observe(target, observer_config.config);
|
|
5145
|
-
}
|
|
5146
|
-
else if (target instanceof NodeList) {
|
|
5147
|
-
/* 传入的参数是节点元素数组 */
|
|
5152
|
+
if (Array.isArray(target) || target instanceof NodeList) {
|
|
5153
|
+
// 传入的是数组或者元素数组
|
|
5148
5154
|
target.forEach((item) => {
|
|
5149
5155
|
mutationObserver.observe(item, observer_config.config);
|
|
5150
5156
|
});
|
|
@@ -5156,12 +5162,13 @@ class Utils {
|
|
|
5156
5162
|
});
|
|
5157
5163
|
}
|
|
5158
5164
|
else {
|
|
5159
|
-
|
|
5160
|
-
console.error("Utils.mutationObserver 未知参数", arguments);
|
|
5165
|
+
mutationObserver.observe(target, observer_config.config);
|
|
5161
5166
|
}
|
|
5162
5167
|
if (observer_config.immediate) {
|
|
5163
5168
|
/* 主动触发一次 */
|
|
5164
|
-
observer_config.callback
|
|
5169
|
+
if (typeof observer_config.callback === "function") {
|
|
5170
|
+
observer_config.callback([], mutationObserver);
|
|
5171
|
+
}
|
|
5165
5172
|
}
|
|
5166
5173
|
return mutationObserver;
|
|
5167
5174
|
}
|
|
@@ -5409,6 +5416,7 @@ class Utils {
|
|
|
5409
5416
|
EventTarget.prototype.addEventListener = function (...args) {
|
|
5410
5417
|
let type = args[0];
|
|
5411
5418
|
let callback = args[1];
|
|
5419
|
+
// @ts-ignore
|
|
5412
5420
|
args[2];
|
|
5413
5421
|
if (filter(type)) {
|
|
5414
5422
|
if (typeof callback === "function") {
|
|
@@ -5502,6 +5510,7 @@ class Utils {
|
|
|
5502
5510
|
}
|
|
5503
5511
|
async init() {
|
|
5504
5512
|
let copyStatus = false;
|
|
5513
|
+
// @ts-ignore
|
|
5505
5514
|
await this.requestClipboardPermission();
|
|
5506
5515
|
if (this.hasClipboard() &&
|
|
5507
5516
|
(this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
@@ -6035,12 +6044,7 @@ class Utils {
|
|
|
6035
6044
|
return parent.querySelector(selector);
|
|
6036
6045
|
}
|
|
6037
6046
|
}
|
|
6038
|
-
|
|
6039
|
-
if (node) {
|
|
6040
|
-
resolve(node);
|
|
6041
|
-
return;
|
|
6042
|
-
}
|
|
6043
|
-
let observer = that.mutationObserver(parent, {
|
|
6047
|
+
var observer = that.mutationObserver(parent, {
|
|
6044
6048
|
config: {
|
|
6045
6049
|
subtree: true,
|
|
6046
6050
|
childList: true,
|
|
@@ -6050,16 +6054,21 @@ class Utils {
|
|
|
6050
6054
|
let node = getNode();
|
|
6051
6055
|
if (node) {
|
|
6052
6056
|
// 取消观察器
|
|
6053
|
-
observer
|
|
6057
|
+
if (typeof observer?.disconnect === "function") {
|
|
6058
|
+
observer.disconnect();
|
|
6059
|
+
}
|
|
6054
6060
|
resolve(node);
|
|
6055
6061
|
return;
|
|
6056
6062
|
}
|
|
6057
6063
|
},
|
|
6064
|
+
immediate: true,
|
|
6058
6065
|
});
|
|
6059
6066
|
if (timeout > 0) {
|
|
6060
6067
|
setTimeout(() => {
|
|
6061
6068
|
// 取消观察器
|
|
6062
|
-
observer
|
|
6069
|
+
if (typeof observer?.disconnect === "function") {
|
|
6070
|
+
observer.disconnect();
|
|
6071
|
+
}
|
|
6063
6072
|
resolve(null);
|
|
6064
6073
|
}, timeout);
|
|
6065
6074
|
}
|
|
@@ -6193,12 +6202,7 @@ class Utils {
|
|
|
6193
6202
|
}
|
|
6194
6203
|
}
|
|
6195
6204
|
}
|
|
6196
|
-
|
|
6197
|
-
if (nodeList) {
|
|
6198
|
-
resolve(nodeList);
|
|
6199
|
-
return;
|
|
6200
|
-
}
|
|
6201
|
-
let observer = that.mutationObserver(parent, {
|
|
6205
|
+
var observer = that.mutationObserver(parent, {
|
|
6202
6206
|
config: {
|
|
6203
6207
|
subtree: true,
|
|
6204
6208
|
childList: true,
|
|
@@ -6208,16 +6212,22 @@ class Utils {
|
|
|
6208
6212
|
let node = getNodeList();
|
|
6209
6213
|
if (node) {
|
|
6210
6214
|
// 取消观察器
|
|
6211
|
-
|
|
6215
|
+
try {
|
|
6216
|
+
observer.disconnect();
|
|
6217
|
+
}
|
|
6218
|
+
catch (error) { }
|
|
6212
6219
|
resolve(node);
|
|
6213
6220
|
return;
|
|
6214
6221
|
}
|
|
6215
6222
|
},
|
|
6223
|
+
immediate: true,
|
|
6216
6224
|
});
|
|
6217
6225
|
if (timeout > 0) {
|
|
6218
6226
|
setTimeout(() => {
|
|
6219
6227
|
// 取消观察器
|
|
6220
|
-
observer
|
|
6228
|
+
if (typeof observer?.disconnect === "function") {
|
|
6229
|
+
observer.disconnect();
|
|
6230
|
+
}
|
|
6221
6231
|
resolve(null);
|
|
6222
6232
|
}, timeout);
|
|
6223
6233
|
}
|