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