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