@whitesev/utils 2.8.2 → 2.9.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.
- package/README.md +176 -176
- package/dist/index.amd.js +269 -777
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +2 -0
- package/dist/index.amd.min.js.map +1 -0
- package/dist/index.cjs.js +269 -777
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +2 -0
- package/dist/index.cjs.min.js.map +1 -0
- package/dist/index.esm.js +269 -777
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +2 -0
- package/dist/index.esm.min.js.map +1 -0
- package/dist/index.iife.js +269 -777
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +2 -0
- package/dist/index.iife.min.js.map +1 -0
- package/dist/index.system.js +269 -777
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +2 -0
- package/dist/index.system.min.js.map +1 -0
- package/dist/index.umd.js +269 -777
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +2 -0
- package/dist/index.umd.min.js.map +1 -0
- package/dist/types/src/Utils.d.ts +103 -450
- package/dist/types/src/UtilsGMCookie.d.ts +4 -0
- package/dist/types/src/UtilsGMMenu.d.ts +3 -6
- package/dist/types/src/types/Httpx.d.ts +1344 -1344
- package/dist/types/src/types/Log.d.ts +19 -19
- package/dist/types/src/types/Progress.d.ts +20 -20
- package/dist/types/src/types/React.d.ts +119 -119
- package/dist/types/src/types/TryCatch.d.ts +9 -9
- package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
- package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
- package/dist/types/src/types/Vue2.d.ts +166 -166
- package/dist/types/src/types/WindowApi.d.ts +14 -14
- package/dist/types/src/types/ajaxHooker.d.ts +151 -151
- package/dist/types/src/types/env.d.ts +7 -7
- package/dist/types/src/types/global.d.ts +31 -31
- package/package.json +13 -9
- package/src/ColorConversion.ts +105 -105
- package/src/CommonUtil.ts +280 -280
- package/src/DOMUtils.ts +251 -251
- package/src/Dictionary.ts +153 -153
- package/src/GBKEncoder.ts +108 -108
- package/src/Hooks.ts +73 -73
- package/src/Httpx.ts +1457 -1457
- package/src/LockFunction.ts +62 -62
- package/src/Log.ts +258 -258
- package/src/Progress.ts +108 -108
- package/src/TryCatch.ts +86 -86
- package/src/Utils.ts +3778 -4773
- package/src/UtilsCommon.ts +14 -14
- package/src/UtilsGMCookie.ts +272 -254
- package/src/UtilsGMMenu.ts +441 -445
- package/src/Vue.ts +233 -233
- package/src/WindowApi.ts +59 -59
- package/src/indexedDB.ts +497 -497
- package/src/types/Httpx.d.ts +1344 -1344
- package/src/types/Log.d.ts +19 -19
- package/src/types/Progress.d.ts +20 -20
- package/src/types/React.d.ts +119 -119
- package/src/types/TryCatch.d.ts +9 -9
- package/src/types/UtilsGMCookie.d.ts +93 -93
- package/src/types/UtilsGMMenu.d.ts +77 -77
- package/src/types/Vue2.d.ts +166 -166
- package/src/types/WindowApi.d.ts +14 -14
- package/src/types/ajaxHooker.d.ts +151 -151
- package/src/types/env.d.ts +7 -7
- package/src/types/global.d.ts +31 -31
- package/dist/types/src/types/Event.d.ts +0 -188
- package/src/types/Event.d.ts +0 -188
package/dist/index.esm.js
CHANGED
|
@@ -519,18 +519,12 @@ class UtilsGMCookie {
|
|
|
519
519
|
}
|
|
520
520
|
return findValue;
|
|
521
521
|
}
|
|
522
|
-
/**
|
|
523
|
-
* 获取多组Cookie
|
|
524
|
-
* @param option 配置
|
|
525
|
-
* @param callback 获取操作后的回调
|
|
526
|
-
* + cookies object[]
|
|
527
|
-
* + error string|undefined
|
|
528
|
-
**/
|
|
529
522
|
list(option, callback) {
|
|
530
523
|
if (option == null) {
|
|
531
524
|
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
532
525
|
}
|
|
533
526
|
const resultData = [];
|
|
527
|
+
let error;
|
|
534
528
|
try {
|
|
535
529
|
let defaultOption = {
|
|
536
530
|
url: this.windowApi.window.location.href,
|
|
@@ -564,14 +558,18 @@ class UtilsGMCookie {
|
|
|
564
558
|
});
|
|
565
559
|
}
|
|
566
560
|
});
|
|
567
|
-
if (typeof callback === "function") {
|
|
568
|
-
callback(resultData);
|
|
569
|
-
}
|
|
570
561
|
}
|
|
571
|
-
catch (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
562
|
+
catch (e) {
|
|
563
|
+
error = e;
|
|
564
|
+
}
|
|
565
|
+
if (typeof callback === "function") {
|
|
566
|
+
callback(resultData, error);
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
return {
|
|
570
|
+
cookies: resultData,
|
|
571
|
+
error: error,
|
|
572
|
+
};
|
|
575
573
|
}
|
|
576
574
|
}
|
|
577
575
|
/**
|
|
@@ -1780,7 +1778,7 @@ class GMMenu {
|
|
|
1780
1778
|
},
|
|
1781
1779
|
/**
|
|
1782
1780
|
* 注册油猴菜单
|
|
1783
|
-
* @param menuOptions
|
|
1781
|
+
* @param menuOptions (可选)菜单配置
|
|
1784
1782
|
*/
|
|
1785
1783
|
register(menuOptions) {
|
|
1786
1784
|
const that = this;
|
|
@@ -1804,7 +1802,8 @@ class GMMenu {
|
|
|
1804
1802
|
},
|
|
1805
1803
|
/**
|
|
1806
1804
|
* 获取本地存储菜单键值
|
|
1807
|
-
* @param
|
|
1805
|
+
* @param key 键
|
|
1806
|
+
* @param defaultValue 默认值
|
|
1808
1807
|
*/
|
|
1809
1808
|
getLocalMenuData(key, defaultValue) {
|
|
1810
1809
|
const localData = this.context.GM_Api.getValue(this.$data.key, {});
|
|
@@ -1827,7 +1826,7 @@ class GMMenu {
|
|
|
1827
1826
|
},
|
|
1828
1827
|
/**
|
|
1829
1828
|
* 处理初始化配置
|
|
1830
|
-
* @param menuOption
|
|
1829
|
+
* @param menuOption 菜单配置
|
|
1831
1830
|
*/
|
|
1832
1831
|
handleInitDetail(menuOption) {
|
|
1833
1832
|
menuOption.enable = Boolean(this.getLocalMenuData(menuOption.key, menuOption.enable));
|
|
@@ -1845,7 +1844,7 @@ class GMMenu {
|
|
|
1845
1844
|
},
|
|
1846
1845
|
/**
|
|
1847
1846
|
* 对菜单数据进行处理
|
|
1848
|
-
* @param menuOption
|
|
1847
|
+
* @param menuOption 菜单配置
|
|
1849
1848
|
*/
|
|
1850
1849
|
handleMenuData(menuOption) {
|
|
1851
1850
|
const that = this;
|
|
@@ -1933,6 +1932,9 @@ class GMMenu {
|
|
|
1933
1932
|
return this.$data.data.find((item) => item.handleData.key === menuKey)?.handleData;
|
|
1934
1933
|
},
|
|
1935
1934
|
};
|
|
1935
|
+
/**
|
|
1936
|
+
* @param details 菜单配置
|
|
1937
|
+
*/
|
|
1936
1938
|
constructor(details) {
|
|
1937
1939
|
this.GM_Api.getValue = details.GM_getValue;
|
|
1938
1940
|
this.GM_Api.setValue = details.GM_setValue;
|
|
@@ -2020,14 +2022,6 @@ class GMMenu {
|
|
|
2020
2022
|
delete(menuId) {
|
|
2021
2023
|
this.GM_Api.unregisterMenuCommand(menuId);
|
|
2022
2024
|
}
|
|
2023
|
-
/**
|
|
2024
|
-
* 根据键值获取enable值
|
|
2025
|
-
* @param menuKey 菜单-键key
|
|
2026
|
-
* @deprecated
|
|
2027
|
-
*/
|
|
2028
|
-
get(menuKey) {
|
|
2029
|
-
return this.getEnable(menuKey);
|
|
2030
|
-
}
|
|
2031
2025
|
/**
|
|
2032
2026
|
* 根据键值获取enable值
|
|
2033
2027
|
* @param menuKey 菜单-键key
|
|
@@ -2185,11 +2179,11 @@ class Hooks {
|
|
|
2185
2179
|
return "";
|
|
2186
2180
|
}
|
|
2187
2181
|
try {
|
|
2188
|
-
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2189
|
-
let args = Array.prototype.slice.call(arguments, 0);
|
|
2190
|
-
let obj = this;
|
|
2191
|
-
hookFunc.apply(obj, args);
|
|
2192
|
-
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2182
|
+
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2183
|
+
let args = Array.prototype.slice.call(arguments, 0);
|
|
2184
|
+
let obj = this;
|
|
2185
|
+
hookFunc.apply(obj, args);
|
|
2186
|
+
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2193
2187
|
};`)(_context, _funcName, hookFunc);
|
|
2194
2188
|
_context[_funcName].prototype.isHooked = true;
|
|
2195
2189
|
return true;
|
|
@@ -5478,7 +5472,7 @@ class DOMUtils {
|
|
|
5478
5472
|
}
|
|
5479
5473
|
const domUtils = new DOMUtils();
|
|
5480
5474
|
|
|
5481
|
-
const version = "2.
|
|
5475
|
+
const version = "2.9.0";
|
|
5482
5476
|
|
|
5483
5477
|
class Utils {
|
|
5484
5478
|
windowApi;
|
|
@@ -5487,31 +5481,6 @@ class Utils {
|
|
|
5487
5481
|
}
|
|
5488
5482
|
/** 版本号 */
|
|
5489
5483
|
version = version;
|
|
5490
|
-
addStyle(cssText) {
|
|
5491
|
-
if (typeof cssText !== "string") {
|
|
5492
|
-
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
5493
|
-
}
|
|
5494
|
-
const cssNode = this.windowApi.document.createElement("style");
|
|
5495
|
-
cssNode.setAttribute("type", "text/css");
|
|
5496
|
-
cssNode.innerHTML = cssText;
|
|
5497
|
-
if (this.windowApi.document.head) {
|
|
5498
|
-
/* 插入head最后 */
|
|
5499
|
-
this.windowApi.document.head.appendChild(cssNode);
|
|
5500
|
-
}
|
|
5501
|
-
else if (this.windowApi.document.body) {
|
|
5502
|
-
/* 插入body后 */
|
|
5503
|
-
this.windowApi.document.body.appendChild(cssNode);
|
|
5504
|
-
}
|
|
5505
|
-
else if (this.windowApi.document.documentElement.childNodes.length === 0) {
|
|
5506
|
-
/* 插入#html第一个元素后 */
|
|
5507
|
-
this.windowApi.document.documentElement.appendChild(cssNode);
|
|
5508
|
-
}
|
|
5509
|
-
else {
|
|
5510
|
-
/* 插入head前面 */
|
|
5511
|
-
this.windowApi.document.documentElement.insertBefore(cssNode, this.windowApi.document.documentElement.childNodes[0]);
|
|
5512
|
-
}
|
|
5513
|
-
return cssNode;
|
|
5514
|
-
}
|
|
5515
5484
|
/**
|
|
5516
5485
|
* JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
|
|
5517
5486
|
* @param target 目标数据
|
|
@@ -5529,7 +5498,7 @@ class Utils {
|
|
|
5529
5498
|
*/
|
|
5530
5499
|
assign = commonUtil.assign.bind(commonUtil);
|
|
5531
5500
|
async asyncReplaceAll(string, pattern, asyncFn) {
|
|
5532
|
-
const
|
|
5501
|
+
const that = this;
|
|
5533
5502
|
if (typeof string !== "string") {
|
|
5534
5503
|
throw new TypeError("string必须是字符串");
|
|
5535
5504
|
}
|
|
@@ -5538,7 +5507,7 @@ class Utils {
|
|
|
5538
5507
|
}
|
|
5539
5508
|
let reg;
|
|
5540
5509
|
if (typeof pattern === "string") {
|
|
5541
|
-
reg = new RegExp(
|
|
5510
|
+
reg = new RegExp(that.toRegExpStr(pattern), "g");
|
|
5542
5511
|
}
|
|
5543
5512
|
else if (pattern instanceof RegExp) {
|
|
5544
5513
|
if (!pattern.global) {
|
|
@@ -5570,7 +5539,7 @@ class Utils {
|
|
|
5570
5539
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
5571
5540
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
5572
5541
|
* + 作者:cxxjackie
|
|
5573
|
-
* + 版本:1.4.
|
|
5542
|
+
* + 版本:1.4.8
|
|
5574
5543
|
* + 旧版本:1.2.4
|
|
5575
5544
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5576
5545
|
* @param useOldVersion 是否使用旧版本,默认false
|
|
@@ -5600,41 +5569,6 @@ class Utils {
|
|
|
5600
5569
|
canvasElement.dispatchEvent(new MouseEvent("mousedown", eventInit));
|
|
5601
5570
|
canvasElement.dispatchEvent(new MouseEvent("mouseup", eventInit));
|
|
5602
5571
|
}
|
|
5603
|
-
checkUserClickInNode(element) {
|
|
5604
|
-
const UtilsContext = this;
|
|
5605
|
-
if (!UtilsContext.isDOM(element)) {
|
|
5606
|
-
throw new Error("Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
|
|
5607
|
-
}
|
|
5608
|
-
const clickEvent = UtilsContext.windowApi.window.event;
|
|
5609
|
-
const touchEvent = UtilsContext.windowApi.window.event;
|
|
5610
|
-
const $click = clickEvent?.composedPath()?.[0];
|
|
5611
|
-
// 点击的x坐标
|
|
5612
|
-
const clickPosX = clickEvent?.clientX != null ? clickEvent.clientX : touchEvent.touches[0].clientX;
|
|
5613
|
-
// 点击的y坐标
|
|
5614
|
-
const clickPosY = clickEvent?.clientY != null ? clickEvent.clientY : touchEvent.touches[0].clientY;
|
|
5615
|
-
const {
|
|
5616
|
-
/* 要检测的元素的相对屏幕的横坐标最左边 */
|
|
5617
|
-
left: elementPosXLeft,
|
|
5618
|
-
/* 要检测的元素的相对屏幕的横坐标最右边 */
|
|
5619
|
-
right: elementPosXRight,
|
|
5620
|
-
/* 要检测的元素的相对屏幕的纵坐标最上边 */
|
|
5621
|
-
top: elementPosYTop,
|
|
5622
|
-
/* 要检测的元素的相对屏幕的纵坐标最下边 */
|
|
5623
|
-
bottom: elementPosYBottom, } = element.getBoundingClientRect();
|
|
5624
|
-
if (clickPosX >= elementPosXLeft &&
|
|
5625
|
-
clickPosX <= elementPosXRight &&
|
|
5626
|
-
clickPosY >= elementPosYTop &&
|
|
5627
|
-
clickPosY <= elementPosYBottom) {
|
|
5628
|
-
return true;
|
|
5629
|
-
}
|
|
5630
|
-
else if (($click && element.contains($click)) || $click == element) {
|
|
5631
|
-
/* 这种情况是应对在界面中隐藏的元素,getBoundingClientRect获取的都是0 */
|
|
5632
|
-
return true;
|
|
5633
|
-
}
|
|
5634
|
-
else {
|
|
5635
|
-
return false;
|
|
5636
|
-
}
|
|
5637
|
-
}
|
|
5638
5572
|
/**
|
|
5639
5573
|
* 复制formData数据
|
|
5640
5574
|
* @param formData 需要clone的数据
|
|
@@ -5682,33 +5616,14 @@ class Utils {
|
|
|
5682
5616
|
deepClone = commonUtil.deepClone.bind(commonUtil);
|
|
5683
5617
|
debounce(fn, delay = 0) {
|
|
5684
5618
|
let timer = null;
|
|
5685
|
-
const
|
|
5619
|
+
const that = this;
|
|
5686
5620
|
return function (...args) {
|
|
5687
|
-
|
|
5688
|
-
timer =
|
|
5689
|
-
fn.apply(
|
|
5621
|
+
that.workerClearTimeout(timer);
|
|
5622
|
+
timer = that.workerSetTimeout(function () {
|
|
5623
|
+
fn.apply(that, args);
|
|
5690
5624
|
}, delay);
|
|
5691
5625
|
};
|
|
5692
5626
|
}
|
|
5693
|
-
deleteParentNode(element, targetSelector) {
|
|
5694
|
-
const UtilsContext = this;
|
|
5695
|
-
if (element == null) {
|
|
5696
|
-
return;
|
|
5697
|
-
}
|
|
5698
|
-
if (!UtilsContext.isDOM(element)) {
|
|
5699
|
-
throw new Error("Utils.deleteParentNode 参数 target 必须为 Node|HTMLElement 类型");
|
|
5700
|
-
}
|
|
5701
|
-
if (typeof targetSelector !== "string") {
|
|
5702
|
-
throw new Error("Utils.deleteParentNode 参数 targetSelector 必须为 string 类型");
|
|
5703
|
-
}
|
|
5704
|
-
let result = false;
|
|
5705
|
-
const needRemoveDOM = domUtils.closest(element, targetSelector);
|
|
5706
|
-
if (needRemoveDOM) {
|
|
5707
|
-
needRemoveDOM.remove();
|
|
5708
|
-
result = true;
|
|
5709
|
-
}
|
|
5710
|
-
return result;
|
|
5711
|
-
}
|
|
5712
5627
|
/**
|
|
5713
5628
|
* 字典
|
|
5714
5629
|
* @example
|
|
@@ -5722,25 +5637,8 @@ class Utils {
|
|
|
5722
5637
|
* dictionary.concat(dictionary2);
|
|
5723
5638
|
**/
|
|
5724
5639
|
Dictionary = UtilsDictionary;
|
|
5725
|
-
dispatchEvent(element, eventName, details) {
|
|
5726
|
-
// let UtilsContext = this;
|
|
5727
|
-
let eventNameList = [];
|
|
5728
|
-
if (typeof eventName === "string") {
|
|
5729
|
-
eventNameList = [eventName];
|
|
5730
|
-
}
|
|
5731
|
-
if (Array.isArray(eventName)) {
|
|
5732
|
-
eventNameList = [...eventName];
|
|
5733
|
-
}
|
|
5734
|
-
eventNameList.forEach((_eventName_) => {
|
|
5735
|
-
const event = new Event(_eventName_);
|
|
5736
|
-
if (details) {
|
|
5737
|
-
Object.assign(event, details);
|
|
5738
|
-
}
|
|
5739
|
-
element.dispatchEvent(event);
|
|
5740
|
-
});
|
|
5741
|
-
}
|
|
5742
5640
|
downloadBase64(base64Data, fileName, isIFrame = false) {
|
|
5743
|
-
const
|
|
5641
|
+
const that = this;
|
|
5744
5642
|
if (typeof base64Data !== "string") {
|
|
5745
5643
|
throw new Error("Utils.downloadBase64 参数 base64Data 必须为 string 类型");
|
|
5746
5644
|
}
|
|
@@ -5749,13 +5647,13 @@ class Utils {
|
|
|
5749
5647
|
}
|
|
5750
5648
|
if (isIFrame) {
|
|
5751
5649
|
/* 使用iframe */
|
|
5752
|
-
const
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
this.windowApi.document.body.appendChild(
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
this.windowApi.document.body.removeChild(
|
|
5650
|
+
const $iframe = this.windowApi.document.createElement("iframe");
|
|
5651
|
+
$iframe.style.display = "none";
|
|
5652
|
+
$iframe.src = base64Data;
|
|
5653
|
+
(this.windowApi.document.body || this.windowApi.document.documentElement).appendChild($iframe);
|
|
5654
|
+
that.workerSetTimeout(() => {
|
|
5655
|
+
$iframe.contentWindow.document.execCommand("SaveAs", true, fileName);
|
|
5656
|
+
(this.windowApi.document.body || this.windowApi.document.documentElement).removeChild($iframe);
|
|
5759
5657
|
}, 100);
|
|
5760
5658
|
}
|
|
5761
5659
|
else {
|
|
@@ -5805,50 +5703,6 @@ class Utils {
|
|
|
5805
5703
|
}
|
|
5806
5704
|
return strFound ? true : false;
|
|
5807
5705
|
}
|
|
5808
|
-
*findElementsWithText(element, text, filter) {
|
|
5809
|
-
const that = this;
|
|
5810
|
-
if (element.outerHTML.includes(text)) {
|
|
5811
|
-
if (element.children.length === 0) {
|
|
5812
|
-
const filterResult = typeof filter === "function" ? filter(element) : false;
|
|
5813
|
-
if (!filterResult) {
|
|
5814
|
-
yield element;
|
|
5815
|
-
}
|
|
5816
|
-
}
|
|
5817
|
-
else {
|
|
5818
|
-
const textElement = Array.from(element.childNodes).filter((ele) => ele.nodeType === Node.TEXT_NODE);
|
|
5819
|
-
for (const $child of textElement) {
|
|
5820
|
-
if ($child.textContent.includes(text)) {
|
|
5821
|
-
const filterResult = typeof filter === "function" ? filter(element) : false;
|
|
5822
|
-
if (!filterResult) {
|
|
5823
|
-
yield $child;
|
|
5824
|
-
}
|
|
5825
|
-
}
|
|
5826
|
-
}
|
|
5827
|
-
}
|
|
5828
|
-
}
|
|
5829
|
-
for (let index = 0; index < element.children.length; index++) {
|
|
5830
|
-
const $child = element.children[index];
|
|
5831
|
-
yield* that.findElementsWithText($child, text, filter);
|
|
5832
|
-
}
|
|
5833
|
-
}
|
|
5834
|
-
/**
|
|
5835
|
-
* 判断该元素是否可见,如果不可见,向上找它的父元素直至找到可见的元素
|
|
5836
|
-
* @param element
|
|
5837
|
-
* @example
|
|
5838
|
-
* let visibleElement = Utils.findVisibleElement(document.querySelector("a.xx"));
|
|
5839
|
-
* > <HTMLElement>
|
|
5840
|
-
*/
|
|
5841
|
-
findVisibleElement(element) {
|
|
5842
|
-
let currentElement = element;
|
|
5843
|
-
while (currentElement) {
|
|
5844
|
-
const elementRect = currentElement.getBoundingClientRect();
|
|
5845
|
-
if (elementRect.length) {
|
|
5846
|
-
return currentElement;
|
|
5847
|
-
}
|
|
5848
|
-
currentElement = currentElement.parentElement;
|
|
5849
|
-
}
|
|
5850
|
-
return null;
|
|
5851
|
-
}
|
|
5852
5706
|
formatByteToSize(byteSize, addType = true) {
|
|
5853
5707
|
byteSize = parseInt(byteSize.toString());
|
|
5854
5708
|
if (isNaN(byteSize)) {
|
|
@@ -5897,9 +5751,9 @@ class Utils {
|
|
|
5897
5751
|
}
|
|
5898
5752
|
getNonNullValue(...args) {
|
|
5899
5753
|
let resultValue = args[args.length - 1];
|
|
5900
|
-
const
|
|
5754
|
+
const that = this;
|
|
5901
5755
|
for (const argValue of args) {
|
|
5902
|
-
if (
|
|
5756
|
+
if (that.isNotNull(argValue)) {
|
|
5903
5757
|
resultValue = argValue;
|
|
5904
5758
|
break;
|
|
5905
5759
|
}
|
|
@@ -5973,20 +5827,8 @@ class Utils {
|
|
|
5973
5827
|
* > 测试
|
|
5974
5828
|
*/
|
|
5975
5829
|
GBKEncoder = GBKEncoder;
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
*/
|
|
5979
|
-
getTransitionEndNameList() {
|
|
5980
|
-
return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
|
|
5981
|
-
}
|
|
5982
|
-
/**
|
|
5983
|
-
* 获取 animationend 的在各个浏览器的兼容名
|
|
5984
|
-
*/
|
|
5985
|
-
getAnimationEndNameList() {
|
|
5986
|
-
return ["webkitAnimationEnd", "mozAnimationEnd", "MSAnimationEnd", "oanimationend", "animationend"];
|
|
5987
|
-
}
|
|
5988
|
-
getArrayLastValue(targetObj) {
|
|
5989
|
-
return targetObj[targetObj.length - 1];
|
|
5830
|
+
getArrayLastValue(target) {
|
|
5831
|
+
return target[target.length - 1];
|
|
5990
5832
|
}
|
|
5991
5833
|
getArrayRealValue(...args) {
|
|
5992
5834
|
let result = null;
|
|
@@ -6071,30 +5913,6 @@ class Utils {
|
|
|
6071
5913
|
}
|
|
6072
5914
|
return diffValue;
|
|
6073
5915
|
}
|
|
6074
|
-
getElementSelector(element) {
|
|
6075
|
-
const UtilsContext = this;
|
|
6076
|
-
if (!element)
|
|
6077
|
-
return void 0;
|
|
6078
|
-
if (!element.parentElement)
|
|
6079
|
-
return void 0;
|
|
6080
|
-
/* 如果元素有id属性,则直接返回id选择器 */
|
|
6081
|
-
if (element.id)
|
|
6082
|
-
return `#${element.id}`;
|
|
6083
|
-
/* 递归地获取父元素的选择器 */
|
|
6084
|
-
let selector = UtilsContext.getElementSelector(element.parentElement);
|
|
6085
|
-
if (!selector) {
|
|
6086
|
-
return element.tagName.toLowerCase();
|
|
6087
|
-
}
|
|
6088
|
-
/* 如果有多个相同类型的兄弟元素,则需要添加索引 */
|
|
6089
|
-
if (element.parentElement.querySelectorAll(element.tagName).length > 1) {
|
|
6090
|
-
const index = Array.prototype.indexOf.call(element.parentElement.children, element) + 1;
|
|
6091
|
-
selector += ` > ${element.tagName.toLowerCase()}:nth-child(${index})`;
|
|
6092
|
-
}
|
|
6093
|
-
else {
|
|
6094
|
-
selector += ` > ${element.tagName.toLowerCase()}`;
|
|
6095
|
-
}
|
|
6096
|
-
return selector;
|
|
6097
|
-
}
|
|
6098
5916
|
/**
|
|
6099
5917
|
* 获取最大值
|
|
6100
5918
|
* @example
|
|
@@ -6135,7 +5953,7 @@ class Utils {
|
|
|
6135
5953
|
}
|
|
6136
5954
|
getMaxZIndexNodeInfo(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
|
|
6137
5955
|
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
6138
|
-
const
|
|
5956
|
+
const that = this;
|
|
6139
5957
|
// 最大值 2147483647
|
|
6140
5958
|
// const maxZIndex = Math.pow(2, 31) - 1;
|
|
6141
5959
|
// 比较值 2000000000
|
|
@@ -6164,7 +5982,7 @@ class Utils {
|
|
|
6164
5982
|
}
|
|
6165
5983
|
}
|
|
6166
5984
|
/** 元素的样式 */
|
|
6167
|
-
const nodeStyle =
|
|
5985
|
+
const nodeStyle = that.windowApi.window.getComputedStyle($ele);
|
|
6168
5986
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
6169
5987
|
if (isVisibleNode(nodeStyle)) {
|
|
6170
5988
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
@@ -6238,7 +6056,7 @@ class Utils {
|
|
|
6238
6056
|
* > 'Mozilla/5.0 (Linux; Android 10; MI 13 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.3490.40 Mobile Safari/537.36'
|
|
6239
6057
|
**/
|
|
6240
6058
|
getRandomAndroidUA() {
|
|
6241
|
-
const
|
|
6059
|
+
const that = this;
|
|
6242
6060
|
const mobileNameList = [
|
|
6243
6061
|
"LDN-LX3",
|
|
6244
6062
|
"RNE-L03",
|
|
@@ -6256,14 +6074,14 @@ class Utils {
|
|
|
6256
6074
|
"MI 13 Build/OPR1.170623.027; wv",
|
|
6257
6075
|
];
|
|
6258
6076
|
/* 安卓版本 */
|
|
6259
|
-
const androidVersion =
|
|
6077
|
+
const androidVersion = that.getRandomValue(12, 14);
|
|
6260
6078
|
/* 手机型号 */
|
|
6261
|
-
const randomMobile =
|
|
6079
|
+
const randomMobile = that.getRandomValue(mobileNameList);
|
|
6262
6080
|
/* chrome大版本号 */
|
|
6263
|
-
const chromeVersion1 =
|
|
6264
|
-
const chromeVersion2 =
|
|
6265
|
-
const chromeVersion3 =
|
|
6266
|
-
const chromeVersion4 =
|
|
6081
|
+
const chromeVersion1 = that.getRandomValue(130, 140);
|
|
6082
|
+
const chromeVersion2 = that.getRandomValue(0, 0);
|
|
6083
|
+
const chromeVersion3 = that.getRandomValue(2272, 6099);
|
|
6084
|
+
const chromeVersion4 = that.getRandomValue(1, 218);
|
|
6267
6085
|
return `Mozilla/5.0 (Linux; Android ${androidVersion}; ${randomMobile}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Mobile Safari/537.36`;
|
|
6268
6086
|
}
|
|
6269
6087
|
/**
|
|
@@ -6285,12 +6103,12 @@ class Utils {
|
|
|
6285
6103
|
* > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
|
|
6286
6104
|
**/
|
|
6287
6105
|
getRandomPCUA() {
|
|
6288
|
-
const
|
|
6106
|
+
const that = this;
|
|
6289
6107
|
/* chrome大版本号 */
|
|
6290
|
-
const chromeVersion1 =
|
|
6291
|
-
const chromeVersion2 =
|
|
6292
|
-
const chromeVersion3 =
|
|
6293
|
-
const chromeVersion4 =
|
|
6108
|
+
const chromeVersion1 = that.getRandomValue(130, 140);
|
|
6109
|
+
const chromeVersion2 = that.getRandomValue(0, 0);
|
|
6110
|
+
const chromeVersion3 = that.getRandomValue(2272, 6099);
|
|
6111
|
+
const chromeVersion4 = that.getRandomValue(1, 218);
|
|
6294
6112
|
return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Safari/537.36`;
|
|
6295
6113
|
}
|
|
6296
6114
|
getRandomValue(...args) {
|
|
@@ -6324,9 +6142,9 @@ class Utils {
|
|
|
6324
6142
|
* @param element 需要获取的目标元素
|
|
6325
6143
|
* @returns
|
|
6326
6144
|
* @example
|
|
6327
|
-
* Utils.
|
|
6145
|
+
* Utils.getReactInstance(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
|
|
6328
6146
|
*/
|
|
6329
|
-
|
|
6147
|
+
getReactInstance(element) {
|
|
6330
6148
|
const result = {};
|
|
6331
6149
|
if (element == null) {
|
|
6332
6150
|
return result;
|
|
@@ -6336,7 +6154,9 @@ class Utils {
|
|
|
6336
6154
|
if (domPropsName.startsWith("__react")) {
|
|
6337
6155
|
const propsName = domPropsName.replace(/__(.+)\$.+/i, "$1");
|
|
6338
6156
|
const propsValue = Reflect.get(element, domPropsName);
|
|
6339
|
-
if (propsName in result)
|
|
6157
|
+
if (propsName in result) {
|
|
6158
|
+
console.error(`重复属性 ${domPropsName}`);
|
|
6159
|
+
}
|
|
6340
6160
|
else {
|
|
6341
6161
|
Reflect.set(result, propsName, propsValue);
|
|
6342
6162
|
}
|
|
@@ -6391,8 +6211,8 @@ class Utils {
|
|
|
6391
6211
|
return bytes.length;
|
|
6392
6212
|
}
|
|
6393
6213
|
getTextStorageSize(text, addType = true) {
|
|
6394
|
-
const
|
|
6395
|
-
return
|
|
6214
|
+
const that = this;
|
|
6215
|
+
return that.formatByteToSize(that.getTextLength(text), addType);
|
|
6396
6216
|
}
|
|
6397
6217
|
getThunderUrl(url) {
|
|
6398
6218
|
if (url == null) {
|
|
@@ -6966,12 +6786,12 @@ class Utils {
|
|
|
6966
6786
|
}
|
|
6967
6787
|
isWebView_Via() {
|
|
6968
6788
|
let result = true;
|
|
6969
|
-
const
|
|
6789
|
+
const that = this;
|
|
6970
6790
|
if (typeof this.windowApi.top.window.via === "object") {
|
|
6971
6791
|
for (const key in Object.values(this.windowApi.top.window.via)) {
|
|
6972
6792
|
if (Reflect.has(this.windowApi.top.window.via, key)) {
|
|
6973
6793
|
const objValueFunc = this.windowApi.top.window.via[key];
|
|
6974
|
-
if (typeof objValueFunc === "function" &&
|
|
6794
|
+
if (typeof objValueFunc === "function" && that.isNativeFunc(objValueFunc)) {
|
|
6975
6795
|
result = true;
|
|
6976
6796
|
}
|
|
6977
6797
|
else {
|
|
@@ -6988,12 +6808,12 @@ class Utils {
|
|
|
6988
6808
|
}
|
|
6989
6809
|
isWebView_X() {
|
|
6990
6810
|
let result = true;
|
|
6991
|
-
const
|
|
6811
|
+
const that = this;
|
|
6992
6812
|
if (typeof this.windowApi.top.window.mbrowser === "object") {
|
|
6993
6813
|
for (const key in Object.values(this.windowApi.top.window.mbrowser)) {
|
|
6994
6814
|
if (Reflect.has(this.windowApi.top.window.mbrowser, key)) {
|
|
6995
6815
|
const objValueFunc = this.windowApi.top.window.mbrowser[key];
|
|
6996
|
-
if (typeof objValueFunc === "function" &&
|
|
6816
|
+
if (typeof objValueFunc === "function" && that.isNativeFunc(objValueFunc)) {
|
|
6997
6817
|
result = true;
|
|
6998
6818
|
}
|
|
6999
6819
|
else {
|
|
@@ -7013,8 +6833,10 @@ class Utils {
|
|
|
7013
6833
|
throw new Error("Utils.parseObjectToArray 参数 target 必须为 object 类型");
|
|
7014
6834
|
}
|
|
7015
6835
|
let result = [];
|
|
7016
|
-
Object.keys(target)
|
|
7017
|
-
|
|
6836
|
+
const keys = Object.keys(target);
|
|
6837
|
+
keys.forEach(function (keyName) {
|
|
6838
|
+
const value = Reflect.get(target, keyName);
|
|
6839
|
+
result = result.concat(value);
|
|
7018
6840
|
});
|
|
7019
6841
|
return result;
|
|
7020
6842
|
}
|
|
@@ -7087,7 +6909,7 @@ class Utils {
|
|
|
7087
6909
|
return content;
|
|
7088
6910
|
}
|
|
7089
6911
|
mutationObserver(target, observer_config) {
|
|
7090
|
-
const
|
|
6912
|
+
const that = this;
|
|
7091
6913
|
const default_obverser_config = {
|
|
7092
6914
|
/* 监听到元素有反馈,需执行的函数 */
|
|
7093
6915
|
callback: () => { },
|
|
@@ -7129,7 +6951,7 @@ class Utils {
|
|
|
7129
6951
|
},
|
|
7130
6952
|
immediate: false,
|
|
7131
6953
|
};
|
|
7132
|
-
observer_config =
|
|
6954
|
+
observer_config = that.assign(default_obverser_config, observer_config);
|
|
7133
6955
|
const windowMutationObserver = this.windowApi.window.MutationObserver ||
|
|
7134
6956
|
this.windowApi.window.webkitMutationObserver ||
|
|
7135
6957
|
this.windowApi.window.MozMutationObserver;
|
|
@@ -7145,7 +6967,7 @@ class Utils {
|
|
|
7145
6967
|
mutationObserver.observe(item, observer_config.config);
|
|
7146
6968
|
});
|
|
7147
6969
|
}
|
|
7148
|
-
else if (
|
|
6970
|
+
else if (that.isJQuery(target)) {
|
|
7149
6971
|
/* 传入的参数是jQuery对象 */
|
|
7150
6972
|
target.each((_, item) => {
|
|
7151
6973
|
mutationObserver.observe(item, observer_config.config);
|
|
@@ -7215,7 +7037,7 @@ class Utils {
|
|
|
7215
7037
|
return utils;
|
|
7216
7038
|
}
|
|
7217
7039
|
noConflictFunc(needReleaseObject, needReleaseName, functionNameList = [], release = true) {
|
|
7218
|
-
const
|
|
7040
|
+
const that = this;
|
|
7219
7041
|
if (typeof needReleaseObject !== "object") {
|
|
7220
7042
|
throw new Error("Utils.noConflictFunc 参数 needReleaseObject 必须为 object 类型");
|
|
7221
7043
|
}
|
|
@@ -7230,11 +7052,11 @@ class Utils {
|
|
|
7230
7052
|
* 释放所有
|
|
7231
7053
|
*/
|
|
7232
7054
|
function releaseAll() {
|
|
7233
|
-
if (typeof
|
|
7055
|
+
if (typeof that.windowApi.window[needReleaseKey] !== "undefined") {
|
|
7234
7056
|
/* 已存在 */
|
|
7235
7057
|
return;
|
|
7236
7058
|
}
|
|
7237
|
-
|
|
7059
|
+
that.windowApi.window[needReleaseKey] = that.deepClone(needReleaseObject);
|
|
7238
7060
|
Object.values(needReleaseObject).forEach((value) => {
|
|
7239
7061
|
if (typeof value === "function") {
|
|
7240
7062
|
needReleaseObject[value.name] = () => { };
|
|
@@ -7248,11 +7070,11 @@ class Utils {
|
|
|
7248
7070
|
Array.from(functionNameList).forEach((item) => {
|
|
7249
7071
|
Object.values(needReleaseObject).forEach((value) => {
|
|
7250
7072
|
if (typeof value === "function") {
|
|
7251
|
-
if (typeof
|
|
7252
|
-
|
|
7073
|
+
if (typeof that.windowApi.window[needReleaseKey] === "undefined") {
|
|
7074
|
+
that.windowApi.window[needReleaseKey] = {};
|
|
7253
7075
|
}
|
|
7254
7076
|
if (item === value.name) {
|
|
7255
|
-
|
|
7077
|
+
that.windowApi.window[needReleaseKey][value.name] = needReleaseObject[value.name];
|
|
7256
7078
|
needReleaseObject[value.name] = () => { };
|
|
7257
7079
|
}
|
|
7258
7080
|
}
|
|
@@ -7263,26 +7085,26 @@ class Utils {
|
|
|
7263
7085
|
* 恢复所有
|
|
7264
7086
|
*/
|
|
7265
7087
|
function recoveryAll() {
|
|
7266
|
-
if (typeof
|
|
7088
|
+
if (typeof that.windowApi.window[needReleaseKey] === "undefined") {
|
|
7267
7089
|
/* 未存在 */
|
|
7268
7090
|
return;
|
|
7269
7091
|
}
|
|
7270
|
-
Object.assign(needReleaseObject,
|
|
7271
|
-
Reflect.deleteProperty(
|
|
7092
|
+
Object.assign(needReleaseObject, that.windowApi.window[needReleaseKey]);
|
|
7093
|
+
Reflect.deleteProperty(that.windowApi.window, "needReleaseKey");
|
|
7272
7094
|
}
|
|
7273
7095
|
/**
|
|
7274
7096
|
* 恢复单个
|
|
7275
7097
|
*/
|
|
7276
7098
|
function recoveryOne() {
|
|
7277
|
-
if (typeof
|
|
7099
|
+
if (typeof that.windowApi.window[needReleaseKey] === "undefined") {
|
|
7278
7100
|
/* 未存在 */
|
|
7279
7101
|
return;
|
|
7280
7102
|
}
|
|
7281
7103
|
Array.from(functionNameList).forEach((item) => {
|
|
7282
|
-
if (
|
|
7283
|
-
needReleaseObject[item] =
|
|
7284
|
-
Reflect.deleteProperty(
|
|
7285
|
-
if (Object.keys(
|
|
7104
|
+
if (that.windowApi.window[needReleaseKey][item]) {
|
|
7105
|
+
needReleaseObject[item] = that.windowApi.window[needReleaseKey][item];
|
|
7106
|
+
Reflect.deleteProperty(that.windowApi.window[needReleaseKey], item);
|
|
7107
|
+
if (Object.keys(that.windowApi.window[needReleaseKey]).length === 0) {
|
|
7286
7108
|
Reflect.deleteProperty(window, needReleaseKey);
|
|
7287
7109
|
}
|
|
7288
7110
|
}
|
|
@@ -7386,39 +7208,44 @@ class Utils {
|
|
|
7386
7208
|
const parser = new DOMParser();
|
|
7387
7209
|
return parser.parseFromString(text, mimeType);
|
|
7388
7210
|
}
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
event?.stopImmediatePropagation();
|
|
7404
|
-
return false;
|
|
7211
|
+
/**
|
|
7212
|
+
* 字符串转正则,用于把字符串中不规范的字符进行转义
|
|
7213
|
+
* @param text 需要进行转换的字符串
|
|
7214
|
+
* @param flags (可选)正则标志,默认`gi`
|
|
7215
|
+
* @example
|
|
7216
|
+
* Utils.toRegExp("^替换$");
|
|
7217
|
+
* > /^替换$/gi
|
|
7218
|
+
*/
|
|
7219
|
+
toRegExp(text, flags = "gi") {
|
|
7220
|
+
let regExp;
|
|
7221
|
+
flags = flags.toLowerCase();
|
|
7222
|
+
if (typeof text === "string") {
|
|
7223
|
+
const pattern = this.toRegExpStr(text);
|
|
7224
|
+
regExp = new RegExp(pattern, flags);
|
|
7405
7225
|
}
|
|
7406
|
-
if (
|
|
7407
|
-
|
|
7408
|
-
// eslint-disable-next-line prefer-rest-params
|
|
7409
|
-
return stopEvent(arguments[0]);
|
|
7226
|
+
else if (text instanceof RegExp) {
|
|
7227
|
+
regExp = text;
|
|
7410
7228
|
}
|
|
7411
7229
|
else {
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7230
|
+
throw new Error("Utils.toRegExp 参数text必须是string|Regexp类型");
|
|
7231
|
+
}
|
|
7232
|
+
return regExp;
|
|
7233
|
+
}
|
|
7234
|
+
/**
|
|
7235
|
+
* 将字符串进行正则转义
|
|
7236
|
+
* 例如:^替换$
|
|
7237
|
+
* 转换:\^替换\$
|
|
7238
|
+
* @param text 需要转义的字符串
|
|
7239
|
+
* @example
|
|
7240
|
+
* Utils.toRegExpStr("^替换$");
|
|
7241
|
+
* > \^替换\$
|
|
7242
|
+
*/
|
|
7243
|
+
toRegExpStr(text) {
|
|
7244
|
+
if (typeof text !== "string") {
|
|
7245
|
+
throw new TypeError("toRegExpStr 参数text必须是string类型");
|
|
7421
7246
|
}
|
|
7247
|
+
const regExpStr = text.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
|
7248
|
+
return regExpStr;
|
|
7422
7249
|
}
|
|
7423
7250
|
/**
|
|
7424
7251
|
* 在canvas元素节点上绘制进度圆圈
|
|
@@ -7427,7 +7254,7 @@ class Utils {
|
|
|
7427
7254
|
progress.draw();
|
|
7428
7255
|
* **/
|
|
7429
7256
|
Progress = Progress;
|
|
7430
|
-
|
|
7257
|
+
hookEvent_isTrusted(isTrustValue = true, filter) {
|
|
7431
7258
|
function trustEvent(event) {
|
|
7432
7259
|
return new Proxy(event, {
|
|
7433
7260
|
get: function (target, property) {
|
|
@@ -7490,25 +7317,7 @@ class Utils {
|
|
|
7490
7317
|
}
|
|
7491
7318
|
return isNegative ? -reversedNum : reversedNum;
|
|
7492
7319
|
}
|
|
7493
|
-
|
|
7494
|
-
const range = this.windowApi.document.createRange();
|
|
7495
|
-
range.selectNodeContents(element);
|
|
7496
|
-
if (childTextNode) {
|
|
7497
|
-
if (childTextNode.nodeType !== Node.TEXT_NODE) {
|
|
7498
|
-
throw new TypeError("childTextNode必须是#text元素");
|
|
7499
|
-
}
|
|
7500
|
-
if (startIndex != null && endIndex != null) {
|
|
7501
|
-
range.setStart(childTextNode, startIndex);
|
|
7502
|
-
range.setEnd(childTextNode, endIndex);
|
|
7503
|
-
}
|
|
7504
|
-
}
|
|
7505
|
-
const selection = this.windowApi.globalThis.getSelection();
|
|
7506
|
-
if (selection) {
|
|
7507
|
-
selection.removeAllRanges();
|
|
7508
|
-
selection.addRange(range);
|
|
7509
|
-
}
|
|
7510
|
-
}
|
|
7511
|
-
setClip(data, info = {
|
|
7320
|
+
copy(data, info = {
|
|
7512
7321
|
type: "text",
|
|
7513
7322
|
mimetype: "text/plain",
|
|
7514
7323
|
}) {
|
|
@@ -7530,7 +7339,7 @@ class Utils {
|
|
|
7530
7339
|
else {
|
|
7531
7340
|
textType = "text/plain";
|
|
7532
7341
|
}
|
|
7533
|
-
const
|
|
7342
|
+
const that = this;
|
|
7534
7343
|
class UtilsClipboard {
|
|
7535
7344
|
#resolve;
|
|
7536
7345
|
#copyData;
|
|
@@ -7581,15 +7390,15 @@ class Utils {
|
|
|
7581
7390
|
*/
|
|
7582
7391
|
copyTextByTextArea() {
|
|
7583
7392
|
try {
|
|
7584
|
-
const copyElement =
|
|
7393
|
+
const copyElement = that.windowApi.document.createElement("textarea");
|
|
7585
7394
|
copyElement.value = this.#copyData;
|
|
7586
7395
|
copyElement.setAttribute("type", "text");
|
|
7587
7396
|
copyElement.setAttribute("style", "opacity:0;position:absolute;");
|
|
7588
7397
|
copyElement.setAttribute("readonly", "readonly");
|
|
7589
|
-
|
|
7398
|
+
that.windowApi.document.body.appendChild(copyElement);
|
|
7590
7399
|
copyElement.select();
|
|
7591
|
-
|
|
7592
|
-
|
|
7400
|
+
that.windowApi.document.execCommand("copy");
|
|
7401
|
+
that.windowApi.document.body.removeChild(copyElement);
|
|
7593
7402
|
return true;
|
|
7594
7403
|
}
|
|
7595
7404
|
catch (error) {
|
|
@@ -7659,18 +7468,88 @@ class Utils {
|
|
|
7659
7468
|
}
|
|
7660
7469
|
return new Promise((resolve) => {
|
|
7661
7470
|
const utilsClipboard = new UtilsClipboard(resolve, data, textType);
|
|
7662
|
-
if (
|
|
7471
|
+
if (that.windowApi.document.hasFocus()) {
|
|
7663
7472
|
utilsClipboard.init();
|
|
7664
7473
|
}
|
|
7665
7474
|
else {
|
|
7666
|
-
|
|
7475
|
+
that.windowApi.window.addEventListener("focus", () => {
|
|
7667
7476
|
utilsClipboard.init();
|
|
7668
7477
|
}, { once: true });
|
|
7669
7478
|
}
|
|
7670
7479
|
});
|
|
7671
7480
|
}
|
|
7481
|
+
/**
|
|
7482
|
+
* 获取剪贴板信息
|
|
7483
|
+
* @example
|
|
7484
|
+
* await Utils.getClipboardInfo();
|
|
7485
|
+
* > { error: null, content: "剪贴板内容" }
|
|
7486
|
+
*/
|
|
7487
|
+
async getClipboardInfo() {
|
|
7488
|
+
return new Promise((resolve) => {
|
|
7489
|
+
/** 读取剪贴板 */
|
|
7490
|
+
function readClipboardText() {
|
|
7491
|
+
navigator.clipboard
|
|
7492
|
+
.readText()
|
|
7493
|
+
.then((clipboardText) => {
|
|
7494
|
+
resolve({
|
|
7495
|
+
error: null,
|
|
7496
|
+
content: clipboardText,
|
|
7497
|
+
});
|
|
7498
|
+
})
|
|
7499
|
+
.catch((error) => {
|
|
7500
|
+
resolve({
|
|
7501
|
+
error: error,
|
|
7502
|
+
content: "",
|
|
7503
|
+
});
|
|
7504
|
+
});
|
|
7505
|
+
}
|
|
7506
|
+
/** 申请读取剪贴板的权限 */
|
|
7507
|
+
function requestPermissionsWithClipboard() {
|
|
7508
|
+
navigator.permissions
|
|
7509
|
+
.query({
|
|
7510
|
+
name: "clipboard-read",
|
|
7511
|
+
})
|
|
7512
|
+
.then(() => {
|
|
7513
|
+
readClipboardText();
|
|
7514
|
+
})
|
|
7515
|
+
.catch(() => {
|
|
7516
|
+
/* 该权限申请Api可能在该环境下不生效,尝试直接读取剪贴板 */
|
|
7517
|
+
readClipboardText();
|
|
7518
|
+
});
|
|
7519
|
+
}
|
|
7520
|
+
/**
|
|
7521
|
+
* 检查当前环境是否支持读取剪贴板Api
|
|
7522
|
+
*/
|
|
7523
|
+
function checkClipboardApi() {
|
|
7524
|
+
if (typeof navigator?.clipboard?.readText !== "function") {
|
|
7525
|
+
return false;
|
|
7526
|
+
}
|
|
7527
|
+
if (typeof navigator?.permissions?.query !== "function") {
|
|
7528
|
+
return false;
|
|
7529
|
+
}
|
|
7530
|
+
return true;
|
|
7531
|
+
}
|
|
7532
|
+
if (!checkClipboardApi()) {
|
|
7533
|
+
resolve({
|
|
7534
|
+
error: new Error("当前环境不支持读取剪贴板Api"),
|
|
7535
|
+
content: "",
|
|
7536
|
+
});
|
|
7537
|
+
return;
|
|
7538
|
+
}
|
|
7539
|
+
if (document.hasFocus()) {
|
|
7540
|
+
requestPermissionsWithClipboard();
|
|
7541
|
+
}
|
|
7542
|
+
else {
|
|
7543
|
+
window.addEventListener("focus", () => {
|
|
7544
|
+
requestPermissionsWithClipboard();
|
|
7545
|
+
}, {
|
|
7546
|
+
once: true,
|
|
7547
|
+
});
|
|
7548
|
+
}
|
|
7549
|
+
});
|
|
7550
|
+
}
|
|
7672
7551
|
setTimeout(callback, delayTime = 0) {
|
|
7673
|
-
const
|
|
7552
|
+
const that = this;
|
|
7674
7553
|
if (typeof callback !== "function" && typeof callback !== "string") {
|
|
7675
7554
|
throw new TypeError("Utils.setTimeout 参数 callback 必须为 function|string 类型");
|
|
7676
7555
|
}
|
|
@@ -7678,27 +7557,27 @@ class Utils {
|
|
|
7678
7557
|
throw new TypeError("Utils.setTimeout 参数 delayTime 必须为 number 类型");
|
|
7679
7558
|
}
|
|
7680
7559
|
return new Promise((resolve) => {
|
|
7681
|
-
|
|
7682
|
-
resolve(
|
|
7560
|
+
that.workerSetTimeout(() => {
|
|
7561
|
+
resolve(that.tryCatch().run(callback));
|
|
7683
7562
|
}, delayTime);
|
|
7684
7563
|
});
|
|
7685
7564
|
}
|
|
7686
7565
|
sleep(delayTime = 0) {
|
|
7687
|
-
const
|
|
7566
|
+
const that = this;
|
|
7688
7567
|
if (typeof delayTime !== "number") {
|
|
7689
7568
|
throw new Error("Utils.sleep 参数 delayTime 必须为 number 类型");
|
|
7690
7569
|
}
|
|
7691
7570
|
return new Promise((resolve) => {
|
|
7692
|
-
|
|
7571
|
+
that.workerSetTimeout(() => {
|
|
7693
7572
|
resolve(void 0);
|
|
7694
7573
|
}, delayTime);
|
|
7695
7574
|
});
|
|
7696
7575
|
}
|
|
7697
7576
|
dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
|
|
7698
|
-
const
|
|
7577
|
+
const that = this;
|
|
7699
7578
|
function initMouseEvent(eventName, offSetX, offSetY) {
|
|
7700
7579
|
const win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
|
|
7701
|
-
const mouseEvent =
|
|
7580
|
+
const mouseEvent = that.windowApi.document.createEvent("MouseEvents");
|
|
7702
7581
|
mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
|
|
7703
7582
|
return mouseEvent;
|
|
7704
7583
|
}
|
|
@@ -7754,7 +7633,7 @@ class Utils {
|
|
|
7754
7633
|
}
|
|
7755
7634
|
}
|
|
7756
7635
|
sortListByProperty(data, getPropertyValueFunc, sortByDesc = true) {
|
|
7757
|
-
const
|
|
7636
|
+
const that = this;
|
|
7758
7637
|
if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
|
|
7759
7638
|
throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
|
|
7760
7639
|
}
|
|
@@ -7766,9 +7645,8 @@ class Utils {
|
|
|
7766
7645
|
};
|
|
7767
7646
|
/**
|
|
7768
7647
|
* 排序方法
|
|
7769
|
-
* @param
|
|
7770
|
-
* @param
|
|
7771
|
-
* @returns
|
|
7648
|
+
* @param after_obj
|
|
7649
|
+
* @param before_obj
|
|
7772
7650
|
*/
|
|
7773
7651
|
const sortFunc = function (after_obj, before_obj) {
|
|
7774
7652
|
const beforeValue = getObjValue(before_obj); /* 前 */
|
|
@@ -7798,7 +7676,7 @@ class Utils {
|
|
|
7798
7676
|
};
|
|
7799
7677
|
/**
|
|
7800
7678
|
* 排序元素方法
|
|
7801
|
-
* @param
|
|
7679
|
+
* @param nodeList 元素列表
|
|
7802
7680
|
* @param getNodeListFunc 获取元素列表的函数
|
|
7803
7681
|
*/
|
|
7804
7682
|
const sortNodeFunc = function (nodeList, getNodeListFunc) {
|
|
@@ -7836,7 +7714,7 @@ class Utils {
|
|
|
7836
7714
|
if (Array.isArray(data)) {
|
|
7837
7715
|
data.sort(sortFunc);
|
|
7838
7716
|
}
|
|
7839
|
-
else if (data instanceof NodeList ||
|
|
7717
|
+
else if (data instanceof NodeList || that.isJQuery(data)) {
|
|
7840
7718
|
sortNodeFunc(data, getDataFunc);
|
|
7841
7719
|
result = getDataFunc();
|
|
7842
7720
|
}
|
|
@@ -7845,20 +7723,6 @@ class Utils {
|
|
|
7845
7723
|
}
|
|
7846
7724
|
return result;
|
|
7847
7725
|
}
|
|
7848
|
-
stringToRegular(targetString, flags = "ig") {
|
|
7849
|
-
let reg;
|
|
7850
|
-
flags = flags.toLowerCase();
|
|
7851
|
-
if (typeof targetString === "string") {
|
|
7852
|
-
reg = new RegExp(targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"), flags);
|
|
7853
|
-
}
|
|
7854
|
-
else if (targetString instanceof RegExp) {
|
|
7855
|
-
reg = targetString;
|
|
7856
|
-
}
|
|
7857
|
-
else {
|
|
7858
|
-
throw new Error("Utils.stringToRegular 参数targetString必须是string|Regexp类型");
|
|
7859
|
-
}
|
|
7860
|
-
return reg;
|
|
7861
|
-
}
|
|
7862
7726
|
stringTitleToUpperCase(targetString, otherStrToLowerCase = false) {
|
|
7863
7727
|
let newTargetString = targetString.slice(0, 1).toUpperCase();
|
|
7864
7728
|
if (otherStrToLowerCase) {
|
|
@@ -7870,7 +7734,7 @@ class Utils {
|
|
|
7870
7734
|
return newTargetString;
|
|
7871
7735
|
}
|
|
7872
7736
|
startsWith(target, searchString, position = 0) {
|
|
7873
|
-
const
|
|
7737
|
+
const that = this;
|
|
7874
7738
|
if (position > target.length) {
|
|
7875
7739
|
/* 超出目标字符串的长度 */
|
|
7876
7740
|
return false;
|
|
@@ -7885,7 +7749,7 @@ class Utils {
|
|
|
7885
7749
|
else if (Array.isArray(searchString)) {
|
|
7886
7750
|
let flag = false;
|
|
7887
7751
|
for (const searcStr of searchString) {
|
|
7888
|
-
if (!
|
|
7752
|
+
if (!that.startsWith(target, searcStr, position)) {
|
|
7889
7753
|
flag = true;
|
|
7890
7754
|
break;
|
|
7891
7755
|
}
|
|
@@ -7894,13 +7758,18 @@ class Utils {
|
|
|
7894
7758
|
}
|
|
7895
7759
|
return Boolean(target.match(searchStringRegexp));
|
|
7896
7760
|
}
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7761
|
+
/**
|
|
7762
|
+
* 字符串首字母转小写
|
|
7763
|
+
* @param text 目标字符串
|
|
7764
|
+
* @param otherStrToLowerCase (可选)剩余部分字符串转大写,默认false
|
|
7765
|
+
*/
|
|
7766
|
+
firstLetterToLowercase(text, otherToUpperCase = false) {
|
|
7767
|
+
let newTargetString = text.slice(0, 1).toLowerCase();
|
|
7768
|
+
if (otherToUpperCase) {
|
|
7769
|
+
newTargetString = newTargetString + text.slice(1).toUpperCase();
|
|
7901
7770
|
}
|
|
7902
7771
|
else {
|
|
7903
|
-
newTargetString = newTargetString +
|
|
7772
|
+
newTargetString = newTargetString + text.slice(1);
|
|
7904
7773
|
}
|
|
7905
7774
|
return newTargetString;
|
|
7906
7775
|
}
|
|
@@ -7914,15 +7783,15 @@ class Utils {
|
|
|
7914
7783
|
*/
|
|
7915
7784
|
toJSON = commonUtil.toJSON.bind(commonUtil);
|
|
7916
7785
|
toSearchParamsStr(obj, addPrefix) {
|
|
7917
|
-
const
|
|
7786
|
+
const that = this;
|
|
7918
7787
|
let searhParamsStr = "";
|
|
7919
7788
|
if (Array.isArray(obj)) {
|
|
7920
7789
|
obj.forEach((item) => {
|
|
7921
7790
|
if (searhParamsStr === "") {
|
|
7922
|
-
searhParamsStr +=
|
|
7791
|
+
searhParamsStr += that.toSearchParamsStr(item);
|
|
7923
7792
|
}
|
|
7924
7793
|
else {
|
|
7925
|
-
searhParamsStr += `&${
|
|
7794
|
+
searhParamsStr += `&${that.toSearchParamsStr(item)}`;
|
|
7926
7795
|
}
|
|
7927
7796
|
});
|
|
7928
7797
|
}
|
|
@@ -7977,341 +7846,33 @@ class Utils {
|
|
|
7977
7846
|
}));
|
|
7978
7847
|
}
|
|
7979
7848
|
}
|
|
7849
|
+
/**
|
|
7850
|
+
* 等待函数数组全部执行完毕,注意,每个函数的顺序不是同步
|
|
7851
|
+
* @param data 需要遍历的数组
|
|
7852
|
+
* @param handleFunc 对该数组进行操作的函数,该函数的参数为数组格式的参数,[数组下标,数组项]
|
|
7853
|
+
* @example
|
|
7854
|
+
* await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
|
|
7855
|
+
**/
|
|
7980
7856
|
waitArrayLoopToEnd(data, handleFunc) {
|
|
7981
|
-
const
|
|
7857
|
+
const that = this;
|
|
7982
7858
|
if (typeof handleFunc !== "function" && typeof handleFunc !== "string") {
|
|
7983
7859
|
throw new Error("Utils.waitArrayLoopToEnd 参数 handleDataFunction 必须为 function|string 类型");
|
|
7984
7860
|
}
|
|
7985
7861
|
return Promise.all(Array.from(data).map(async (item, index) => {
|
|
7986
|
-
await
|
|
7862
|
+
await that.tryCatch(index, item).run(handleFunc);
|
|
7987
7863
|
}));
|
|
7988
7864
|
}
|
|
7989
|
-
|
|
7990
|
-
const UtilsContext = this;
|
|
7991
|
-
const __timeout__ = typeof timeout === "number" ? timeout : 0;
|
|
7992
|
-
return new Promise((resolve) => {
|
|
7993
|
-
const observer = UtilsContext.mutationObserver(parent || UtilsContext.windowApi.document, {
|
|
7994
|
-
config: {
|
|
7995
|
-
subtree: true,
|
|
7996
|
-
childList: true,
|
|
7997
|
-
attributes: true,
|
|
7998
|
-
},
|
|
7999
|
-
immediate: true,
|
|
8000
|
-
callback(_, __observer__) {
|
|
8001
|
-
const result = checkFn();
|
|
8002
|
-
if (result.success) {
|
|
8003
|
-
// 取消观察器
|
|
8004
|
-
if (typeof __observer__?.disconnect === "function") {
|
|
8005
|
-
__observer__.disconnect();
|
|
8006
|
-
}
|
|
8007
|
-
resolve(result.data);
|
|
8008
|
-
}
|
|
8009
|
-
},
|
|
8010
|
-
});
|
|
8011
|
-
if (__timeout__ > 0) {
|
|
8012
|
-
UtilsContext.workerSetTimeout(() => {
|
|
8013
|
-
// 取消观察器
|
|
8014
|
-
if (typeof observer?.disconnect === "function") {
|
|
8015
|
-
observer.disconnect();
|
|
8016
|
-
}
|
|
8017
|
-
resolve(null);
|
|
8018
|
-
}, __timeout__);
|
|
8019
|
-
}
|
|
8020
|
-
});
|
|
8021
|
-
}
|
|
8022
|
-
waitNode(...args) {
|
|
8023
|
-
// 过滤掉undefined
|
|
8024
|
-
args = args.filter((arg) => arg !== void 0);
|
|
8025
|
-
const UtilsContext = this;
|
|
8026
|
-
// 选择器
|
|
8027
|
-
const selector = args[0];
|
|
8028
|
-
// 父元素(监听的元素)
|
|
8029
|
-
let parent = UtilsContext.windowApi.document;
|
|
8030
|
-
// 超时时间
|
|
8031
|
-
let timeout = 0;
|
|
8032
|
-
if (typeof args[0] !== "string" && !Array.isArray(args[0]) && typeof args[0] !== "function") {
|
|
8033
|
-
throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
|
|
8034
|
-
}
|
|
8035
|
-
if (args.length === 1) ;
|
|
8036
|
-
else if (args.length === 2) {
|
|
8037
|
-
const secondParam = args[1];
|
|
8038
|
-
if (typeof secondParam === "number") {
|
|
8039
|
-
// "div",10000
|
|
8040
|
-
timeout = secondParam;
|
|
8041
|
-
}
|
|
8042
|
-
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8043
|
-
// "div",document
|
|
8044
|
-
parent = secondParam;
|
|
8045
|
-
}
|
|
8046
|
-
else {
|
|
8047
|
-
throw new TypeError("Utils.waitNode 第二个参数必须是number|Node");
|
|
8048
|
-
}
|
|
8049
|
-
}
|
|
8050
|
-
else if (args.length === 3) {
|
|
8051
|
-
// "div",document,10000
|
|
8052
|
-
// 第二个参数,parent
|
|
8053
|
-
const secondParam = args[1];
|
|
8054
|
-
// 第三个参数,timeout
|
|
8055
|
-
const thirdParam = args[2];
|
|
8056
|
-
if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8057
|
-
parent = secondParam;
|
|
8058
|
-
if (typeof thirdParam === "number") {
|
|
8059
|
-
timeout = thirdParam;
|
|
8060
|
-
}
|
|
8061
|
-
else {
|
|
8062
|
-
throw new TypeError("Utils.waitNode 第三个参数必须是number");
|
|
8063
|
-
}
|
|
8064
|
-
}
|
|
8065
|
-
else {
|
|
8066
|
-
throw new TypeError("Utils.waitNode 第二个参数必须是Node");
|
|
8067
|
-
}
|
|
8068
|
-
}
|
|
8069
|
-
else {
|
|
8070
|
-
throw new TypeError("Utils.waitNode 参数个数错误");
|
|
8071
|
-
}
|
|
8072
|
-
function getNode() {
|
|
8073
|
-
if (Array.isArray(selector)) {
|
|
8074
|
-
const result = [];
|
|
8075
|
-
for (let index = 0; index < selector.length; index++) {
|
|
8076
|
-
const node = domUtils.selector(selector[index]);
|
|
8077
|
-
if (node) {
|
|
8078
|
-
result.push(node);
|
|
8079
|
-
}
|
|
8080
|
-
}
|
|
8081
|
-
if (result.length === selector.length) {
|
|
8082
|
-
return result;
|
|
8083
|
-
}
|
|
8084
|
-
}
|
|
8085
|
-
else if (typeof selector === "function") {
|
|
8086
|
-
return selector();
|
|
8087
|
-
}
|
|
8088
|
-
else {
|
|
8089
|
-
return domUtils.selector(selector, parent);
|
|
8090
|
-
}
|
|
8091
|
-
}
|
|
8092
|
-
return UtilsContext.wait(() => {
|
|
8093
|
-
const node = getNode();
|
|
8094
|
-
if (node) {
|
|
8095
|
-
return {
|
|
8096
|
-
success: true,
|
|
8097
|
-
data: node,
|
|
8098
|
-
};
|
|
8099
|
-
}
|
|
8100
|
-
else {
|
|
8101
|
-
return {
|
|
8102
|
-
success: false,
|
|
8103
|
-
data: node,
|
|
8104
|
-
};
|
|
8105
|
-
}
|
|
8106
|
-
}, timeout, parent);
|
|
8107
|
-
}
|
|
8108
|
-
waitAnyNode(...args) {
|
|
8109
|
-
// 过滤掉undefined
|
|
8110
|
-
args = args.filter((arg) => arg !== void 0);
|
|
8111
|
-
const UtilsContext = this;
|
|
8112
|
-
// 选择器
|
|
8113
|
-
const selectorList = args[0];
|
|
8114
|
-
// 父元素(监听的元素)
|
|
8115
|
-
let parent = UtilsContext.windowApi.document;
|
|
8116
|
-
// 超时时间
|
|
8117
|
-
let timeout = 0;
|
|
8118
|
-
if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
|
|
8119
|
-
throw new TypeError("Utils.waitAnyNode 第一个参数必须是string[]");
|
|
8120
|
-
}
|
|
8121
|
-
if (args.length === 1) ;
|
|
8122
|
-
else if (args.length === 2) {
|
|
8123
|
-
const secondParam = args[1];
|
|
8124
|
-
if (typeof secondParam === "number") {
|
|
8125
|
-
// "div",10000
|
|
8126
|
-
timeout = secondParam;
|
|
8127
|
-
}
|
|
8128
|
-
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8129
|
-
// "div",document
|
|
8130
|
-
parent = secondParam;
|
|
8131
|
-
}
|
|
8132
|
-
else {
|
|
8133
|
-
throw new TypeError("Utils.waitAnyNode 第二个参数必须是number|Node");
|
|
8134
|
-
}
|
|
8135
|
-
}
|
|
8136
|
-
else if (args.length === 3) {
|
|
8137
|
-
// "div",document,10000
|
|
8138
|
-
// 第二个参数,parent
|
|
8139
|
-
const secondParam = args[1];
|
|
8140
|
-
// 第三个参数,timeout
|
|
8141
|
-
const thirdParam = args[2];
|
|
8142
|
-
if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8143
|
-
parent = secondParam;
|
|
8144
|
-
if (typeof thirdParam === "number") {
|
|
8145
|
-
timeout = thirdParam;
|
|
8146
|
-
}
|
|
8147
|
-
else {
|
|
8148
|
-
throw new TypeError("Utils.waitAnyNode 第三个参数必须是number");
|
|
8149
|
-
}
|
|
8150
|
-
}
|
|
8151
|
-
else {
|
|
8152
|
-
throw new TypeError("Utils.waitAnyNode 第二个参数必须是Node");
|
|
8153
|
-
}
|
|
8154
|
-
}
|
|
8155
|
-
else {
|
|
8156
|
-
throw new TypeError("Utils.waitAnyNode 参数个数错误");
|
|
8157
|
-
}
|
|
8158
|
-
const promiseList = selectorList.map((selector) => {
|
|
8159
|
-
return UtilsContext.waitNode(selector, parent, timeout);
|
|
8160
|
-
});
|
|
8161
|
-
return Promise.any(promiseList);
|
|
8162
|
-
}
|
|
8163
|
-
waitNodeList(...args) {
|
|
8164
|
-
// 过滤掉undefined
|
|
8165
|
-
args = args.filter((arg) => arg !== void 0);
|
|
8166
|
-
const UtilsContext = this;
|
|
8167
|
-
// 选择器数组
|
|
8168
|
-
const selector = args[0];
|
|
8169
|
-
// 父元素(监听的元素)
|
|
8170
|
-
let parent = UtilsContext.windowApi.document;
|
|
8171
|
-
// 超时时间
|
|
8172
|
-
let timeout = 0;
|
|
8173
|
-
if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
|
|
8174
|
-
throw new TypeError("Utils.waitNodeList 第一个参数必须是string|string[]");
|
|
8175
|
-
}
|
|
8176
|
-
if (args.length === 1) ;
|
|
8177
|
-
else if (args.length === 2) {
|
|
8178
|
-
const secondParam = args[1];
|
|
8179
|
-
if (typeof secondParam === "number") {
|
|
8180
|
-
// "div",10000
|
|
8181
|
-
timeout = secondParam;
|
|
8182
|
-
}
|
|
8183
|
-
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8184
|
-
// "div",document
|
|
8185
|
-
parent = secondParam;
|
|
8186
|
-
}
|
|
8187
|
-
else {
|
|
8188
|
-
throw new TypeError("Utils.waitNodeList 第二个参数必须是number|Node");
|
|
8189
|
-
}
|
|
8190
|
-
}
|
|
8191
|
-
else if (args.length === 3) {
|
|
8192
|
-
// "div",document,10000
|
|
8193
|
-
// 第二个参数,parent
|
|
8194
|
-
const secondParam = args[1];
|
|
8195
|
-
// 第三个参数,timeout
|
|
8196
|
-
const thirdParam = args[2];
|
|
8197
|
-
if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8198
|
-
parent = secondParam;
|
|
8199
|
-
if (typeof thirdParam === "number") {
|
|
8200
|
-
timeout = thirdParam;
|
|
8201
|
-
}
|
|
8202
|
-
else {
|
|
8203
|
-
throw new TypeError("Utils.waitNodeList 第三个参数必须是number");
|
|
8204
|
-
}
|
|
8205
|
-
}
|
|
8206
|
-
else {
|
|
8207
|
-
throw new TypeError("Utils.waitNodeList 第二个参数必须是Node");
|
|
8208
|
-
}
|
|
8209
|
-
}
|
|
8210
|
-
else {
|
|
8211
|
-
throw new TypeError("Utils.waitNodeList 参数个数错误");
|
|
8212
|
-
}
|
|
8213
|
-
function getNodeList() {
|
|
8214
|
-
if (Array.isArray(selector)) {
|
|
8215
|
-
const result = [];
|
|
8216
|
-
for (let index = 0; index < selector.length; index++) {
|
|
8217
|
-
const nodeList = domUtils.selectorAll(selector[index], parent);
|
|
8218
|
-
if (nodeList.length) {
|
|
8219
|
-
result.push(nodeList);
|
|
8220
|
-
}
|
|
8221
|
-
}
|
|
8222
|
-
if (result.length === selector.length) {
|
|
8223
|
-
return result;
|
|
8224
|
-
}
|
|
8225
|
-
}
|
|
8226
|
-
else {
|
|
8227
|
-
const nodeList = domUtils.selectorAll(selector, parent);
|
|
8228
|
-
if (nodeList.length) {
|
|
8229
|
-
return nodeList;
|
|
8230
|
-
}
|
|
8231
|
-
}
|
|
8232
|
-
}
|
|
8233
|
-
return UtilsContext.wait(() => {
|
|
8234
|
-
const node = getNodeList();
|
|
8235
|
-
if (node) {
|
|
8236
|
-
return {
|
|
8237
|
-
success: true,
|
|
8238
|
-
data: node,
|
|
8239
|
-
};
|
|
8240
|
-
}
|
|
8241
|
-
else {
|
|
8242
|
-
return {
|
|
8243
|
-
success: false,
|
|
8244
|
-
data: node,
|
|
8245
|
-
};
|
|
8246
|
-
}
|
|
8247
|
-
}, timeout, parent);
|
|
8248
|
-
}
|
|
8249
|
-
waitAnyNodeList(...args) {
|
|
8250
|
-
// 过滤掉undefined
|
|
8251
|
-
args = args.filter((arg) => arg !== void 0);
|
|
8252
|
-
const UtilsContext = this;
|
|
8253
|
-
// 选择器数组
|
|
8254
|
-
const selectorList = args[0];
|
|
8255
|
-
// 父元素(监听的元素)
|
|
8256
|
-
let parent = UtilsContext.windowApi.document;
|
|
8257
|
-
// 超时时间
|
|
8258
|
-
let timeout = 0;
|
|
8259
|
-
if (!Array.isArray(args[0])) {
|
|
8260
|
-
throw new TypeError("Utils.waitAnyNodeList 第一个参数必须是string[]");
|
|
8261
|
-
}
|
|
8262
|
-
if (args.length === 1) ;
|
|
8263
|
-
else if (args.length === 2) {
|
|
8264
|
-
const secondParam = args[1];
|
|
8265
|
-
if (typeof secondParam === "number") {
|
|
8266
|
-
// "div",10000
|
|
8267
|
-
timeout = secondParam;
|
|
8268
|
-
}
|
|
8269
|
-
else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8270
|
-
// "div",document
|
|
8271
|
-
parent = secondParam;
|
|
8272
|
-
}
|
|
8273
|
-
else {
|
|
8274
|
-
throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是number|Node");
|
|
8275
|
-
}
|
|
8276
|
-
}
|
|
8277
|
-
else if (args.length === 3) {
|
|
8278
|
-
// "div",document,10000
|
|
8279
|
-
// 第二个参数,parent
|
|
8280
|
-
const secondParam = args[1];
|
|
8281
|
-
// 第三个参数,timeout
|
|
8282
|
-
const thirdParam = args[2];
|
|
8283
|
-
if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
8284
|
-
parent = secondParam;
|
|
8285
|
-
if (typeof thirdParam === "number") {
|
|
8286
|
-
timeout = thirdParam;
|
|
8287
|
-
}
|
|
8288
|
-
else {
|
|
8289
|
-
throw new TypeError("Utils.waitAnyNodeList 第三个参数必须是number");
|
|
8290
|
-
}
|
|
8291
|
-
}
|
|
8292
|
-
else {
|
|
8293
|
-
throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是Node");
|
|
8294
|
-
}
|
|
8295
|
-
}
|
|
8296
|
-
else {
|
|
8297
|
-
throw new TypeError("Utils.waitAnyNodeList 参数个数错误");
|
|
8298
|
-
}
|
|
8299
|
-
const promiseList = selectorList.map((selector) => {
|
|
8300
|
-
return UtilsContext.waitNodeList(selector, parent, timeout);
|
|
8301
|
-
});
|
|
8302
|
-
return Promise.any(promiseList);
|
|
8303
|
-
}
|
|
8304
|
-
waitProperty(checkObj, checkPropertyName) {
|
|
7865
|
+
waitProperty(target, propertyName) {
|
|
8305
7866
|
return new Promise((resolve) => {
|
|
8306
|
-
let obj =
|
|
8307
|
-
if (typeof
|
|
8308
|
-
obj =
|
|
7867
|
+
let obj = target;
|
|
7868
|
+
if (typeof target === "function") {
|
|
7869
|
+
obj = target();
|
|
8309
7870
|
}
|
|
8310
|
-
if (Reflect.has(obj,
|
|
8311
|
-
resolve(obj[
|
|
7871
|
+
if (Reflect.has(obj, propertyName)) {
|
|
7872
|
+
resolve(obj[propertyName]);
|
|
8312
7873
|
}
|
|
8313
7874
|
else {
|
|
8314
|
-
Object.defineProperty(obj,
|
|
7875
|
+
Object.defineProperty(obj, propertyName, {
|
|
8315
7876
|
set: function (value) {
|
|
8316
7877
|
try {
|
|
8317
7878
|
resolve(value);
|
|
@@ -8324,49 +7885,48 @@ class Utils {
|
|
|
8324
7885
|
}
|
|
8325
7886
|
});
|
|
8326
7887
|
}
|
|
8327
|
-
waitPropertyByInterval(
|
|
8328
|
-
const
|
|
8329
|
-
if (
|
|
7888
|
+
waitPropertyByInterval(checkFn, propertyName, intervalTimer = 250, maxTime = -1) {
|
|
7889
|
+
const that = this;
|
|
7890
|
+
if (checkFn == null) {
|
|
8330
7891
|
throw new TypeError("checkObj 不能为空对象 ");
|
|
8331
7892
|
}
|
|
8332
7893
|
let isResolve = false;
|
|
8333
7894
|
return new Promise((resolve, reject) => {
|
|
8334
|
-
const interval =
|
|
8335
|
-
let
|
|
8336
|
-
if (typeof
|
|
8337
|
-
|
|
7895
|
+
const interval = that.workerSetInterval(() => {
|
|
7896
|
+
let inst = checkFn;
|
|
7897
|
+
if (typeof checkFn === "function") {
|
|
7898
|
+
inst = checkFn();
|
|
8338
7899
|
}
|
|
8339
|
-
if (typeof
|
|
7900
|
+
if (typeof inst !== "object") {
|
|
8340
7901
|
return;
|
|
8341
7902
|
}
|
|
8342
|
-
if (
|
|
7903
|
+
if (inst == null) {
|
|
8343
7904
|
return;
|
|
8344
7905
|
}
|
|
8345
|
-
if ((typeof
|
|
8346
|
-
Reflect.has(obj, checkPropertyName)) {
|
|
7906
|
+
if ((typeof propertyName === "function" && propertyName(inst)) || Reflect.has(inst, propertyName)) {
|
|
8347
7907
|
isResolve = true;
|
|
8348
|
-
|
|
8349
|
-
resolve(
|
|
7908
|
+
that.workerClearInterval(interval);
|
|
7909
|
+
resolve(inst[propertyName]);
|
|
8350
7910
|
}
|
|
8351
7911
|
}, intervalTimer);
|
|
8352
7912
|
if (maxTime !== -1) {
|
|
8353
|
-
|
|
7913
|
+
that.workerSetTimeout(() => {
|
|
8354
7914
|
if (!isResolve) {
|
|
8355
|
-
|
|
7915
|
+
that.workerClearInterval(interval);
|
|
8356
7916
|
reject();
|
|
8357
7917
|
}
|
|
8358
7918
|
}, maxTime);
|
|
8359
7919
|
}
|
|
8360
7920
|
});
|
|
8361
7921
|
}
|
|
8362
|
-
async waitVueByInterval(
|
|
8363
|
-
if (
|
|
7922
|
+
async waitVueByInterval($el, propertyName, timer = 250, maxTime = -1, vueName = "__vue__") {
|
|
7923
|
+
if ($el == null) {
|
|
8364
7924
|
throw new Error("Utils.waitVueByInterval 参数element 不能为空");
|
|
8365
7925
|
}
|
|
8366
7926
|
let flag = false;
|
|
8367
|
-
const
|
|
7927
|
+
const that = this;
|
|
8368
7928
|
try {
|
|
8369
|
-
await
|
|
7929
|
+
await that.waitPropertyByInterval($el, function (targetElement) {
|
|
8370
7930
|
if (targetElement == null) {
|
|
8371
7931
|
return false;
|
|
8372
7932
|
}
|
|
@@ -8376,25 +7936,24 @@ class Utils {
|
|
|
8376
7936
|
if (propertyName == null) {
|
|
8377
7937
|
return true;
|
|
8378
7938
|
}
|
|
8379
|
-
const
|
|
7939
|
+
const $vueEl = targetElement[vueName];
|
|
8380
7940
|
if (typeof propertyName === "string") {
|
|
8381
|
-
if (propertyName in
|
|
7941
|
+
if (propertyName in $vueEl) {
|
|
8382
7942
|
flag = true;
|
|
8383
7943
|
return true;
|
|
8384
7944
|
}
|
|
8385
7945
|
}
|
|
8386
7946
|
else {
|
|
8387
7947
|
/* Function */
|
|
8388
|
-
if (propertyName(
|
|
7948
|
+
if (propertyName($vueEl)) {
|
|
8389
7949
|
flag = true;
|
|
8390
7950
|
return true;
|
|
8391
7951
|
}
|
|
8392
7952
|
}
|
|
8393
7953
|
return false;
|
|
8394
7954
|
}, timer, maxTime);
|
|
8395
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8396
7955
|
}
|
|
8397
|
-
catch
|
|
7956
|
+
catch {
|
|
8398
7957
|
return flag;
|
|
8399
7958
|
}
|
|
8400
7959
|
return flag;
|
|
@@ -8631,73 +8190,6 @@ class Utils {
|
|
|
8631
8190
|
this.windowApi.clearInterval(timeId);
|
|
8632
8191
|
}
|
|
8633
8192
|
}
|
|
8634
|
-
/**
|
|
8635
|
-
* 获取剪贴板信息
|
|
8636
|
-
*/
|
|
8637
|
-
async getClipboardInfo() {
|
|
8638
|
-
return new Promise((resolve) => {
|
|
8639
|
-
/** 读取剪贴板 */
|
|
8640
|
-
function readClipboardText() {
|
|
8641
|
-
navigator.clipboard
|
|
8642
|
-
.readText()
|
|
8643
|
-
.then((clipboardText) => {
|
|
8644
|
-
resolve({
|
|
8645
|
-
error: null,
|
|
8646
|
-
content: clipboardText,
|
|
8647
|
-
});
|
|
8648
|
-
})
|
|
8649
|
-
.catch((error) => {
|
|
8650
|
-
resolve({
|
|
8651
|
-
error: error,
|
|
8652
|
-
content: "",
|
|
8653
|
-
});
|
|
8654
|
-
});
|
|
8655
|
-
}
|
|
8656
|
-
/** 申请读取剪贴板的权限 */
|
|
8657
|
-
function requestPermissionsWithClipboard() {
|
|
8658
|
-
navigator.permissions
|
|
8659
|
-
.query({
|
|
8660
|
-
name: "clipboard-read",
|
|
8661
|
-
})
|
|
8662
|
-
.then(() => {
|
|
8663
|
-
readClipboardText();
|
|
8664
|
-
})
|
|
8665
|
-
.catch(() => {
|
|
8666
|
-
/* 该权限申请Api可能在该环境下不生效,尝试直接读取剪贴板 */
|
|
8667
|
-
readClipboardText();
|
|
8668
|
-
});
|
|
8669
|
-
}
|
|
8670
|
-
/**
|
|
8671
|
-
* 检查当前环境是否支持读取剪贴板Api
|
|
8672
|
-
*/
|
|
8673
|
-
function checkClipboardApi() {
|
|
8674
|
-
if (typeof navigator?.clipboard?.readText !== "function") {
|
|
8675
|
-
return false;
|
|
8676
|
-
}
|
|
8677
|
-
if (typeof navigator?.permissions?.query !== "function") {
|
|
8678
|
-
return false;
|
|
8679
|
-
}
|
|
8680
|
-
return true;
|
|
8681
|
-
}
|
|
8682
|
-
if (!checkClipboardApi()) {
|
|
8683
|
-
resolve({
|
|
8684
|
-
error: new Error("当前环境不支持读取剪贴板Api"),
|
|
8685
|
-
content: "",
|
|
8686
|
-
});
|
|
8687
|
-
return;
|
|
8688
|
-
}
|
|
8689
|
-
if (document.hasFocus()) {
|
|
8690
|
-
requestPermissionsWithClipboard();
|
|
8691
|
-
}
|
|
8692
|
-
else {
|
|
8693
|
-
window.addEventListener("focus", () => {
|
|
8694
|
-
requestPermissionsWithClipboard();
|
|
8695
|
-
}, {
|
|
8696
|
-
once: true,
|
|
8697
|
-
});
|
|
8698
|
-
}
|
|
8699
|
-
});
|
|
8700
|
-
}
|
|
8701
8193
|
}
|
|
8702
8194
|
const utils = new Utils();
|
|
8703
8195
|
|