@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.umd.js
CHANGED
|
@@ -441,6 +441,27 @@
|
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* 解析cookie字符串
|
|
446
|
+
* 例如:document.cookie
|
|
447
|
+
* @param cookieStr
|
|
448
|
+
*/
|
|
449
|
+
parseCookie(cookieStr) {
|
|
450
|
+
let cookies = cookieStr.split(";");
|
|
451
|
+
let result = [];
|
|
452
|
+
for (const cookieItem of cookies) {
|
|
453
|
+
let item = cookieItem.trim();
|
|
454
|
+
let itemSplit = item.split("=");
|
|
455
|
+
let itemName = itemSplit[0];
|
|
456
|
+
itemSplit.splice(0, 1);
|
|
457
|
+
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
458
|
+
result.push({
|
|
459
|
+
key: itemName,
|
|
460
|
+
value: itemValue,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
return result;
|
|
464
|
+
}
|
|
444
465
|
}
|
|
445
466
|
|
|
446
467
|
// @name ajaxHooker
|
|
@@ -4124,7 +4145,7 @@
|
|
|
4124
4145
|
this.windowApi = new WindowApi(option);
|
|
4125
4146
|
}
|
|
4126
4147
|
/** 版本号 */
|
|
4127
|
-
version = "
|
|
4148
|
+
version = "2025.1.1";
|
|
4128
4149
|
addStyle(cssText) {
|
|
4129
4150
|
if (typeof cssText !== "string") {
|
|
4130
4151
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -4842,6 +4863,8 @@
|
|
|
4842
4863
|
getMaxZIndexNodeInfo(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
|
|
4843
4864
|
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
4844
4865
|
const UtilsContext = this;
|
|
4866
|
+
// 最大值 2147483647
|
|
4867
|
+
// const maxZIndex = Math.pow(2, 31) - 1;
|
|
4845
4868
|
// 比较值 2000000000
|
|
4846
4869
|
const maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
4847
4870
|
// 当前页面最大的z-index
|
|
@@ -6736,6 +6759,39 @@
|
|
|
6736
6759
|
await UtilsContext.tryCatch(index, item).run(handleFunc);
|
|
6737
6760
|
}));
|
|
6738
6761
|
}
|
|
6762
|
+
wait(checkFn, timeout, parent) {
|
|
6763
|
+
const UtilsContext = this;
|
|
6764
|
+
let __timeout__ = typeof timeout === "number" ? timeout : 0;
|
|
6765
|
+
return new Promise((resolve) => {
|
|
6766
|
+
let observer = UtilsContext.mutationObserver(parent || UtilsContext.windowApi.document, {
|
|
6767
|
+
config: {
|
|
6768
|
+
subtree: true,
|
|
6769
|
+
childList: true,
|
|
6770
|
+
attributes: true,
|
|
6771
|
+
},
|
|
6772
|
+
immediate: true,
|
|
6773
|
+
callback(mutations, __observer__) {
|
|
6774
|
+
let result = checkFn();
|
|
6775
|
+
if (result.success) {
|
|
6776
|
+
// 取消观察器
|
|
6777
|
+
if (typeof __observer__?.disconnect === "function") {
|
|
6778
|
+
__observer__.disconnect();
|
|
6779
|
+
}
|
|
6780
|
+
resolve(result.data);
|
|
6781
|
+
}
|
|
6782
|
+
},
|
|
6783
|
+
});
|
|
6784
|
+
if (__timeout__ > 0) {
|
|
6785
|
+
setTimeout(() => {
|
|
6786
|
+
// 取消观察器
|
|
6787
|
+
if (typeof observer?.disconnect === "function") {
|
|
6788
|
+
observer.disconnect();
|
|
6789
|
+
}
|
|
6790
|
+
resolve(null);
|
|
6791
|
+
}, __timeout__);
|
|
6792
|
+
}
|
|
6793
|
+
});
|
|
6794
|
+
}
|
|
6739
6795
|
waitNode(...args) {
|
|
6740
6796
|
// 过滤掉undefined
|
|
6741
6797
|
args = args.filter((arg) => arg !== void 0);
|
|
@@ -6746,8 +6802,10 @@
|
|
|
6746
6802
|
let parent = UtilsContext.windowApi.document;
|
|
6747
6803
|
// 超时时间
|
|
6748
6804
|
let timeout = 0;
|
|
6749
|
-
if (typeof args[0] !== "string" &&
|
|
6750
|
-
|
|
6805
|
+
if (typeof args[0] !== "string" &&
|
|
6806
|
+
!Array.isArray(args[0]) &&
|
|
6807
|
+
typeof args[0] !== "function") {
|
|
6808
|
+
throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
|
|
6751
6809
|
}
|
|
6752
6810
|
if (args.length === 1) ;
|
|
6753
6811
|
else if (args.length === 2) {
|
|
@@ -6787,53 +6845,41 @@
|
|
|
6787
6845
|
else {
|
|
6788
6846
|
throw new TypeError("Utils.waitNode 参数个数错误");
|
|
6789
6847
|
}
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
result.push(node);
|
|
6798
|
-
}
|
|
6799
|
-
}
|
|
6800
|
-
if (result.length === selector.length) {
|
|
6801
|
-
return result;
|
|
6848
|
+
function getNode() {
|
|
6849
|
+
if (Array.isArray(selector)) {
|
|
6850
|
+
let result = [];
|
|
6851
|
+
for (let index = 0; index < selector.length; index++) {
|
|
6852
|
+
let node = parent.querySelector(selector[index]);
|
|
6853
|
+
if (node) {
|
|
6854
|
+
result.push(node);
|
|
6802
6855
|
}
|
|
6803
6856
|
}
|
|
6804
|
-
|
|
6805
|
-
return
|
|
6857
|
+
if (result.length === selector.length) {
|
|
6858
|
+
return result;
|
|
6806
6859
|
}
|
|
6807
6860
|
}
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
subtree: true,
|
|
6811
|
-
childList: true,
|
|
6812
|
-
attributes: true,
|
|
6813
|
-
},
|
|
6814
|
-
callback() {
|
|
6815
|
-
let node = getNode();
|
|
6816
|
-
if (node) {
|
|
6817
|
-
// 取消观察器
|
|
6818
|
-
if (typeof observer?.disconnect === "function") {
|
|
6819
|
-
observer.disconnect();
|
|
6820
|
-
}
|
|
6821
|
-
resolve(node);
|
|
6822
|
-
return;
|
|
6823
|
-
}
|
|
6824
|
-
},
|
|
6825
|
-
immediate: true,
|
|
6826
|
-
});
|
|
6827
|
-
if (timeout > 0) {
|
|
6828
|
-
setTimeout(() => {
|
|
6829
|
-
// 取消观察器
|
|
6830
|
-
if (typeof observer?.disconnect === "function") {
|
|
6831
|
-
observer.disconnect();
|
|
6832
|
-
}
|
|
6833
|
-
resolve(null);
|
|
6834
|
-
}, timeout);
|
|
6861
|
+
else if (typeof selector === "function") {
|
|
6862
|
+
return selector();
|
|
6835
6863
|
}
|
|
6836
|
-
|
|
6864
|
+
else {
|
|
6865
|
+
return parent.querySelector(selector);
|
|
6866
|
+
}
|
|
6867
|
+
}
|
|
6868
|
+
return UtilsContext.wait(() => {
|
|
6869
|
+
let node = getNode();
|
|
6870
|
+
if (node) {
|
|
6871
|
+
return {
|
|
6872
|
+
success: true,
|
|
6873
|
+
data: node,
|
|
6874
|
+
};
|
|
6875
|
+
}
|
|
6876
|
+
else {
|
|
6877
|
+
return {
|
|
6878
|
+
success: false,
|
|
6879
|
+
data: node,
|
|
6880
|
+
};
|
|
6881
|
+
}
|
|
6882
|
+
}, timeout, parent);
|
|
6837
6883
|
}
|
|
6838
6884
|
waitAnyNode(...args) {
|
|
6839
6885
|
// 过滤掉undefined
|
|
@@ -6942,57 +6988,41 @@
|
|
|
6942
6988
|
else {
|
|
6943
6989
|
throw new TypeError("Utils.waitNodeList 参数个数错误");
|
|
6944
6990
|
}
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
let nodeList = parent.querySelectorAll(selector[index]);
|
|
6951
|
-
if (nodeList.length) {
|
|
6952
|
-
result.push(nodeList);
|
|
6953
|
-
}
|
|
6954
|
-
}
|
|
6955
|
-
if (result.length === selector.length) {
|
|
6956
|
-
return result;
|
|
6957
|
-
}
|
|
6958
|
-
}
|
|
6959
|
-
else {
|
|
6960
|
-
let nodeList = parent.querySelectorAll(selector);
|
|
6991
|
+
function getNodeList() {
|
|
6992
|
+
if (Array.isArray(selector)) {
|
|
6993
|
+
let result = [];
|
|
6994
|
+
for (let index = 0; index < selector.length; index++) {
|
|
6995
|
+
let nodeList = parent.querySelectorAll(selector[index]);
|
|
6961
6996
|
if (nodeList.length) {
|
|
6962
|
-
|
|
6997
|
+
result.push(nodeList);
|
|
6963
6998
|
}
|
|
6964
6999
|
}
|
|
7000
|
+
if (result.length === selector.length) {
|
|
7001
|
+
return result;
|
|
7002
|
+
}
|
|
6965
7003
|
}
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
},
|
|
6972
|
-
callback() {
|
|
6973
|
-
let node = getNodeList();
|
|
6974
|
-
if (node) {
|
|
6975
|
-
// 取消观察器
|
|
6976
|
-
try {
|
|
6977
|
-
observer.disconnect();
|
|
6978
|
-
}
|
|
6979
|
-
catch (error) { }
|
|
6980
|
-
resolve(node);
|
|
6981
|
-
return;
|
|
6982
|
-
}
|
|
6983
|
-
},
|
|
6984
|
-
immediate: true,
|
|
6985
|
-
});
|
|
6986
|
-
if (timeout > 0) {
|
|
6987
|
-
setTimeout(() => {
|
|
6988
|
-
// 取消观察器
|
|
6989
|
-
if (typeof observer?.disconnect === "function") {
|
|
6990
|
-
observer.disconnect();
|
|
6991
|
-
}
|
|
6992
|
-
resolve(null);
|
|
6993
|
-
}, timeout);
|
|
7004
|
+
else {
|
|
7005
|
+
let nodeList = parent.querySelectorAll(selector);
|
|
7006
|
+
if (nodeList.length) {
|
|
7007
|
+
return nodeList;
|
|
7008
|
+
}
|
|
6994
7009
|
}
|
|
6995
|
-
}
|
|
7010
|
+
}
|
|
7011
|
+
return UtilsContext.wait(() => {
|
|
7012
|
+
let node = getNodeList();
|
|
7013
|
+
if (node) {
|
|
7014
|
+
return {
|
|
7015
|
+
success: true,
|
|
7016
|
+
data: node,
|
|
7017
|
+
};
|
|
7018
|
+
}
|
|
7019
|
+
else {
|
|
7020
|
+
return {
|
|
7021
|
+
success: false,
|
|
7022
|
+
data: node,
|
|
7023
|
+
};
|
|
7024
|
+
}
|
|
7025
|
+
}, timeout, parent);
|
|
6996
7026
|
}
|
|
6997
7027
|
waitAnyNodeList(...args) {
|
|
6998
7028
|
// 过滤掉undefined
|