@whitesev/utils 2.5.5 → 2.5.7
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/dist/index.amd.js +121 -91
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +121 -91
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +121 -91
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +121 -91
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +121 -91
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +121 -91
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +65 -18
- package/dist/types/src/UtilsGMCookie.d.ts +9 -0
- package/dist/types/src/types/global.d.ts +1 -0
- package/package.json +1 -1
- package/src/Utils.ts +204 -114
- package/src/UtilsGMCookie.ts +21 -0
- package/src/types/global.d.ts +1 -0
package/dist/index.amd.js
CHANGED
|
@@ -437,6 +437,27 @@ define((function () { 'use strict';
|
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* 解析cookie字符串
|
|
442
|
+
* 例如:document.cookie
|
|
443
|
+
* @param cookieStr
|
|
444
|
+
*/
|
|
445
|
+
parseCookie(cookieStr) {
|
|
446
|
+
let cookies = cookieStr.split(";");
|
|
447
|
+
let result = [];
|
|
448
|
+
for (const cookieItem of cookies) {
|
|
449
|
+
let item = cookieItem.trim();
|
|
450
|
+
let itemSplit = item.split("=");
|
|
451
|
+
let itemName = itemSplit[0];
|
|
452
|
+
itemSplit.splice(0, 1);
|
|
453
|
+
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
454
|
+
result.push({
|
|
455
|
+
key: itemName,
|
|
456
|
+
value: itemValue,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
return result;
|
|
460
|
+
}
|
|
440
461
|
}
|
|
441
462
|
|
|
442
463
|
// @name ajaxHooker
|
|
@@ -4120,7 +4141,7 @@ define((function () { 'use strict';
|
|
|
4120
4141
|
this.windowApi = new WindowApi(option);
|
|
4121
4142
|
}
|
|
4122
4143
|
/** 版本号 */
|
|
4123
|
-
version = "
|
|
4144
|
+
version = "2025.1.1";
|
|
4124
4145
|
addStyle(cssText) {
|
|
4125
4146
|
if (typeof cssText !== "string") {
|
|
4126
4147
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -4838,6 +4859,8 @@ define((function () { 'use strict';
|
|
|
4838
4859
|
getMaxZIndexNodeInfo(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
|
|
4839
4860
|
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
4840
4861
|
const UtilsContext = this;
|
|
4862
|
+
// 最大值 2147483647
|
|
4863
|
+
// const maxZIndex = Math.pow(2, 31) - 1;
|
|
4841
4864
|
// 比较值 2000000000
|
|
4842
4865
|
const maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
4843
4866
|
// 当前页面最大的z-index
|
|
@@ -6732,6 +6755,39 @@ define((function () { 'use strict';
|
|
|
6732
6755
|
await UtilsContext.tryCatch(index, item).run(handleFunc);
|
|
6733
6756
|
}));
|
|
6734
6757
|
}
|
|
6758
|
+
wait(checkFn, timeout, parent) {
|
|
6759
|
+
const UtilsContext = this;
|
|
6760
|
+
let __timeout__ = typeof timeout === "number" ? timeout : 0;
|
|
6761
|
+
return new Promise((resolve) => {
|
|
6762
|
+
let observer = UtilsContext.mutationObserver(parent || UtilsContext.windowApi.document, {
|
|
6763
|
+
config: {
|
|
6764
|
+
subtree: true,
|
|
6765
|
+
childList: true,
|
|
6766
|
+
attributes: true,
|
|
6767
|
+
},
|
|
6768
|
+
immediate: true,
|
|
6769
|
+
callback(mutations, __observer__) {
|
|
6770
|
+
let result = checkFn();
|
|
6771
|
+
if (result.success) {
|
|
6772
|
+
// 取消观察器
|
|
6773
|
+
if (typeof __observer__?.disconnect === "function") {
|
|
6774
|
+
__observer__.disconnect();
|
|
6775
|
+
}
|
|
6776
|
+
resolve(result.data);
|
|
6777
|
+
}
|
|
6778
|
+
},
|
|
6779
|
+
});
|
|
6780
|
+
if (__timeout__ > 0) {
|
|
6781
|
+
setTimeout(() => {
|
|
6782
|
+
// 取消观察器
|
|
6783
|
+
if (typeof observer?.disconnect === "function") {
|
|
6784
|
+
observer.disconnect();
|
|
6785
|
+
}
|
|
6786
|
+
resolve(null);
|
|
6787
|
+
}, __timeout__);
|
|
6788
|
+
}
|
|
6789
|
+
});
|
|
6790
|
+
}
|
|
6735
6791
|
waitNode(...args) {
|
|
6736
6792
|
// 过滤掉undefined
|
|
6737
6793
|
args = args.filter((arg) => arg !== void 0);
|
|
@@ -6742,8 +6798,10 @@ define((function () { 'use strict';
|
|
|
6742
6798
|
let parent = UtilsContext.windowApi.document;
|
|
6743
6799
|
// 超时时间
|
|
6744
6800
|
let timeout = 0;
|
|
6745
|
-
if (typeof args[0] !== "string" &&
|
|
6746
|
-
|
|
6801
|
+
if (typeof args[0] !== "string" &&
|
|
6802
|
+
!Array.isArray(args[0]) &&
|
|
6803
|
+
typeof args[0] !== "function") {
|
|
6804
|
+
throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
|
|
6747
6805
|
}
|
|
6748
6806
|
if (args.length === 1) ;
|
|
6749
6807
|
else if (args.length === 2) {
|
|
@@ -6783,53 +6841,41 @@ define((function () { 'use strict';
|
|
|
6783
6841
|
else {
|
|
6784
6842
|
throw new TypeError("Utils.waitNode 参数个数错误");
|
|
6785
6843
|
}
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
result.push(node);
|
|
6794
|
-
}
|
|
6795
|
-
}
|
|
6796
|
-
if (result.length === selector.length) {
|
|
6797
|
-
return result;
|
|
6844
|
+
function getNode() {
|
|
6845
|
+
if (Array.isArray(selector)) {
|
|
6846
|
+
let result = [];
|
|
6847
|
+
for (let index = 0; index < selector.length; index++) {
|
|
6848
|
+
let node = parent.querySelector(selector[index]);
|
|
6849
|
+
if (node) {
|
|
6850
|
+
result.push(node);
|
|
6798
6851
|
}
|
|
6799
6852
|
}
|
|
6800
|
-
|
|
6801
|
-
return
|
|
6853
|
+
if (result.length === selector.length) {
|
|
6854
|
+
return result;
|
|
6802
6855
|
}
|
|
6803
6856
|
}
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
subtree: true,
|
|
6807
|
-
childList: true,
|
|
6808
|
-
attributes: true,
|
|
6809
|
-
},
|
|
6810
|
-
callback() {
|
|
6811
|
-
let node = getNode();
|
|
6812
|
-
if (node) {
|
|
6813
|
-
// 取消观察器
|
|
6814
|
-
if (typeof observer?.disconnect === "function") {
|
|
6815
|
-
observer.disconnect();
|
|
6816
|
-
}
|
|
6817
|
-
resolve(node);
|
|
6818
|
-
return;
|
|
6819
|
-
}
|
|
6820
|
-
},
|
|
6821
|
-
immediate: true,
|
|
6822
|
-
});
|
|
6823
|
-
if (timeout > 0) {
|
|
6824
|
-
setTimeout(() => {
|
|
6825
|
-
// 取消观察器
|
|
6826
|
-
if (typeof observer?.disconnect === "function") {
|
|
6827
|
-
observer.disconnect();
|
|
6828
|
-
}
|
|
6829
|
-
resolve(null);
|
|
6830
|
-
}, timeout);
|
|
6857
|
+
else if (typeof selector === "function") {
|
|
6858
|
+
return selector();
|
|
6831
6859
|
}
|
|
6832
|
-
|
|
6860
|
+
else {
|
|
6861
|
+
return parent.querySelector(selector);
|
|
6862
|
+
}
|
|
6863
|
+
}
|
|
6864
|
+
return UtilsContext.wait(() => {
|
|
6865
|
+
let node = getNode();
|
|
6866
|
+
if (node) {
|
|
6867
|
+
return {
|
|
6868
|
+
success: true,
|
|
6869
|
+
data: node,
|
|
6870
|
+
};
|
|
6871
|
+
}
|
|
6872
|
+
else {
|
|
6873
|
+
return {
|
|
6874
|
+
success: false,
|
|
6875
|
+
data: node,
|
|
6876
|
+
};
|
|
6877
|
+
}
|
|
6878
|
+
}, timeout, parent);
|
|
6833
6879
|
}
|
|
6834
6880
|
waitAnyNode(...args) {
|
|
6835
6881
|
// 过滤掉undefined
|
|
@@ -6938,57 +6984,41 @@ define((function () { 'use strict';
|
|
|
6938
6984
|
else {
|
|
6939
6985
|
throw new TypeError("Utils.waitNodeList 参数个数错误");
|
|
6940
6986
|
}
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
let nodeList = parent.querySelectorAll(selector[index]);
|
|
6947
|
-
if (nodeList.length) {
|
|
6948
|
-
result.push(nodeList);
|
|
6949
|
-
}
|
|
6950
|
-
}
|
|
6951
|
-
if (result.length === selector.length) {
|
|
6952
|
-
return result;
|
|
6953
|
-
}
|
|
6954
|
-
}
|
|
6955
|
-
else {
|
|
6956
|
-
let nodeList = parent.querySelectorAll(selector);
|
|
6987
|
+
function getNodeList() {
|
|
6988
|
+
if (Array.isArray(selector)) {
|
|
6989
|
+
let result = [];
|
|
6990
|
+
for (let index = 0; index < selector.length; index++) {
|
|
6991
|
+
let nodeList = parent.querySelectorAll(selector[index]);
|
|
6957
6992
|
if (nodeList.length) {
|
|
6958
|
-
|
|
6993
|
+
result.push(nodeList);
|
|
6959
6994
|
}
|
|
6960
6995
|
}
|
|
6996
|
+
if (result.length === selector.length) {
|
|
6997
|
+
return result;
|
|
6998
|
+
}
|
|
6961
6999
|
}
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
},
|
|
6968
|
-
callback() {
|
|
6969
|
-
let node = getNodeList();
|
|
6970
|
-
if (node) {
|
|
6971
|
-
// 取消观察器
|
|
6972
|
-
try {
|
|
6973
|
-
observer.disconnect();
|
|
6974
|
-
}
|
|
6975
|
-
catch (error) { }
|
|
6976
|
-
resolve(node);
|
|
6977
|
-
return;
|
|
6978
|
-
}
|
|
6979
|
-
},
|
|
6980
|
-
immediate: true,
|
|
6981
|
-
});
|
|
6982
|
-
if (timeout > 0) {
|
|
6983
|
-
setTimeout(() => {
|
|
6984
|
-
// 取消观察器
|
|
6985
|
-
if (typeof observer?.disconnect === "function") {
|
|
6986
|
-
observer.disconnect();
|
|
6987
|
-
}
|
|
6988
|
-
resolve(null);
|
|
6989
|
-
}, timeout);
|
|
7000
|
+
else {
|
|
7001
|
+
let nodeList = parent.querySelectorAll(selector);
|
|
7002
|
+
if (nodeList.length) {
|
|
7003
|
+
return nodeList;
|
|
7004
|
+
}
|
|
6990
7005
|
}
|
|
6991
|
-
}
|
|
7006
|
+
}
|
|
7007
|
+
return UtilsContext.wait(() => {
|
|
7008
|
+
let node = getNodeList();
|
|
7009
|
+
if (node) {
|
|
7010
|
+
return {
|
|
7011
|
+
success: true,
|
|
7012
|
+
data: node,
|
|
7013
|
+
};
|
|
7014
|
+
}
|
|
7015
|
+
else {
|
|
7016
|
+
return {
|
|
7017
|
+
success: false,
|
|
7018
|
+
data: node,
|
|
7019
|
+
};
|
|
7020
|
+
}
|
|
7021
|
+
}, timeout, parent);
|
|
6992
7022
|
}
|
|
6993
7023
|
waitAnyNodeList(...args) {
|
|
6994
7024
|
// 过滤掉undefined
|