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