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