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