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