@whitesev/utils 2.11.5 → 2.11.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 +161 -24
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +161 -24
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +161 -24
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +161 -24
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +161 -24
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +161 -24
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +61 -1
- package/dist/types/src/types/env.d.ts +4 -0
- package/package.json +1 -1
- package/src/Utils.ts +225 -20
- package/src/types/env.d.ts +4 -0
package/dist/index.umd.js
CHANGED
|
@@ -243,7 +243,7 @@
|
|
|
243
243
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
244
244
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
245
245
|
|
|
246
|
-
const version = "2.11.
|
|
246
|
+
const version = "2.11.7";
|
|
247
247
|
|
|
248
248
|
/* eslint-disable */
|
|
249
249
|
// ==UserScript==
|
|
@@ -6079,15 +6079,9 @@
|
|
|
6079
6079
|
}
|
|
6080
6080
|
return diffValue;
|
|
6081
6081
|
}
|
|
6082
|
-
/**
|
|
6083
|
-
* 获取最大值
|
|
6084
|
-
* @example
|
|
6085
|
-
* Utils.getMaxValue([{1:123},{2:345},{3:456}],(index,value)=>{return parseInt(index)})
|
|
6086
|
-
* > 2
|
|
6087
|
-
*/
|
|
6088
6082
|
getMaxValue(...args) {
|
|
6089
6083
|
const result = [...args];
|
|
6090
|
-
|
|
6084
|
+
const newResult = [];
|
|
6091
6085
|
if (result.length === 0) {
|
|
6092
6086
|
return void 0;
|
|
6093
6087
|
}
|
|
@@ -6096,13 +6090,20 @@
|
|
|
6096
6090
|
const data = result[0];
|
|
6097
6091
|
const handleDataFunc = result[1];
|
|
6098
6092
|
Object.keys(data).forEach((keyName) => {
|
|
6099
|
-
newResult
|
|
6093
|
+
newResult.push(handleDataFunc(keyName, data[keyName]));
|
|
6094
|
+
});
|
|
6095
|
+
}
|
|
6096
|
+
else if (result.length === 2 && Array.isArray(result[0]) && typeof result[1] === "function") {
|
|
6097
|
+
const data = result[0];
|
|
6098
|
+
const handleDataFunc = result[1];
|
|
6099
|
+
data.forEach((value, index, __data__) => {
|
|
6100
|
+
newResult.push(handleDataFunc(value, index, __data__));
|
|
6100
6101
|
});
|
|
6101
6102
|
}
|
|
6102
6103
|
else {
|
|
6103
6104
|
result.forEach((item) => {
|
|
6104
6105
|
if (!isNaN(parseFloat(item))) {
|
|
6105
|
-
newResult
|
|
6106
|
+
newResult.push(parseFloat(item));
|
|
6106
6107
|
}
|
|
6107
6108
|
});
|
|
6108
6109
|
}
|
|
@@ -6111,7 +6112,7 @@
|
|
|
6111
6112
|
else {
|
|
6112
6113
|
result[0].forEach((item) => {
|
|
6113
6114
|
if (!isNaN(parseFloat(item))) {
|
|
6114
|
-
newResult
|
|
6115
|
+
newResult.push(parseFloat(item));
|
|
6115
6116
|
}
|
|
6116
6117
|
});
|
|
6117
6118
|
return Math.max(...newResult);
|
|
@@ -6130,45 +6131,61 @@
|
|
|
6130
6131
|
let maxZIndexNode = null;
|
|
6131
6132
|
/**
|
|
6132
6133
|
* 元素是否可见
|
|
6134
|
+
* @param $el
|
|
6133
6135
|
* @param $css
|
|
6134
6136
|
*/
|
|
6135
|
-
function isVisibleNode($css) {
|
|
6136
|
-
|
|
6137
|
+
function isVisibleNode($el, $css) {
|
|
6138
|
+
let flag = true;
|
|
6139
|
+
if (typeof $el.checkVisibility === "function") {
|
|
6140
|
+
flag = $el.checkVisibility();
|
|
6141
|
+
}
|
|
6142
|
+
else {
|
|
6143
|
+
flag =
|
|
6144
|
+
$css.position !== "static" && $css.display !== "none" && $css.visibility !== "hidden" && $css.opacity !== "0";
|
|
6145
|
+
}
|
|
6146
|
+
if (flag) {
|
|
6147
|
+
// css样式上可见
|
|
6148
|
+
// 再判断宽高
|
|
6149
|
+
const rect = $el.getBoundingClientRect();
|
|
6150
|
+
// 确保该元素的中心点在屏幕内
|
|
6151
|
+
flag = rect.width > 0 && rect.height > 0 && rect.x > 0 && rect.y > 0;
|
|
6152
|
+
}
|
|
6153
|
+
return flag;
|
|
6137
6154
|
}
|
|
6138
6155
|
/**
|
|
6139
6156
|
* 查询元素的z-index
|
|
6140
6157
|
* 并比较值是否是已获取的最大值
|
|
6141
|
-
* @param $
|
|
6158
|
+
* @param $el
|
|
6142
6159
|
*/
|
|
6143
|
-
function queryMaxZIndex($
|
|
6160
|
+
function queryMaxZIndex($el) {
|
|
6144
6161
|
if (typeof ignoreCallBack === "function") {
|
|
6145
|
-
const ignoreResult = ignoreCallBack($
|
|
6162
|
+
const ignoreResult = ignoreCallBack($el);
|
|
6146
6163
|
if (typeof ignoreResult === "boolean" && !ignoreResult) {
|
|
6147
6164
|
return;
|
|
6148
6165
|
}
|
|
6149
6166
|
}
|
|
6150
6167
|
/** 元素的样式 */
|
|
6151
|
-
const nodeStyle = that.windowApi.window.getComputedStyle($
|
|
6168
|
+
const nodeStyle = that.windowApi.window.getComputedStyle($el);
|
|
6152
6169
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
6153
|
-
if (isVisibleNode(nodeStyle)) {
|
|
6170
|
+
if (isVisibleNode($el, nodeStyle)) {
|
|
6154
6171
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6155
6172
|
if (!isNaN(nodeZIndex)) {
|
|
6156
6173
|
if (nodeZIndex > zIndex) {
|
|
6157
6174
|
// 赋值到全局
|
|
6158
6175
|
zIndex = nodeZIndex;
|
|
6159
|
-
maxZIndexNode = $
|
|
6176
|
+
maxZIndexNode = $el;
|
|
6160
6177
|
}
|
|
6161
6178
|
}
|
|
6162
6179
|
// 判断shadowRoot
|
|
6163
|
-
if ($
|
|
6164
|
-
$
|
|
6180
|
+
if ($el.shadowRoot != null && $el instanceof ShadowRoot) {
|
|
6181
|
+
$el.shadowRoot.querySelectorAll("*").forEach(($shadowEle) => {
|
|
6165
6182
|
queryMaxZIndex($shadowEle);
|
|
6166
6183
|
});
|
|
6167
6184
|
}
|
|
6168
6185
|
}
|
|
6169
6186
|
}
|
|
6170
|
-
target.querySelectorAll("*").forEach(($
|
|
6171
|
-
queryMaxZIndex($
|
|
6187
|
+
target.querySelectorAll("*").forEach(($elItem) => {
|
|
6188
|
+
queryMaxZIndex($elItem);
|
|
6172
6189
|
});
|
|
6173
6190
|
zIndex += deviation;
|
|
6174
6191
|
if (zIndex >= maxZIndexCompare) {
|
|
@@ -6180,6 +6197,127 @@
|
|
|
6180
6197
|
zIndex: zIndex,
|
|
6181
6198
|
};
|
|
6182
6199
|
}
|
|
6200
|
+
getMaxZIndexNodeInfoFromPoint($el, deviation) {
|
|
6201
|
+
if (typeof $el === "function") {
|
|
6202
|
+
$el = $el();
|
|
6203
|
+
}
|
|
6204
|
+
if (typeof $el === "number") {
|
|
6205
|
+
deviation = $el;
|
|
6206
|
+
$el = void 0;
|
|
6207
|
+
}
|
|
6208
|
+
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
6209
|
+
deviation = 10;
|
|
6210
|
+
}
|
|
6211
|
+
const leftTop = {
|
|
6212
|
+
x: globalThis.innerWidth * (1 / 8),
|
|
6213
|
+
y: globalThis.innerHeight * (1 / 8),
|
|
6214
|
+
};
|
|
6215
|
+
const leftBottom = {
|
|
6216
|
+
x: globalThis.innerWidth * (1 / 8),
|
|
6217
|
+
y: globalThis.innerHeight * (7 / 8),
|
|
6218
|
+
};
|
|
6219
|
+
const rightTop = {
|
|
6220
|
+
x: globalThis.innerWidth * (7 / 8),
|
|
6221
|
+
y: globalThis.innerHeight * (1 / 8),
|
|
6222
|
+
};
|
|
6223
|
+
const rightBottom = {
|
|
6224
|
+
x: globalThis.innerWidth * (7 / 8),
|
|
6225
|
+
y: globalThis.innerHeight * (7 / 8),
|
|
6226
|
+
};
|
|
6227
|
+
const center = {
|
|
6228
|
+
x: globalThis.innerWidth / 2,
|
|
6229
|
+
y: globalThis.innerHeight / 2,
|
|
6230
|
+
};
|
|
6231
|
+
const delayHandlerElementPostionList = [
|
|
6232
|
+
leftTop,
|
|
6233
|
+
leftBottom,
|
|
6234
|
+
rightTop,
|
|
6235
|
+
rightBottom,
|
|
6236
|
+
center,
|
|
6237
|
+
];
|
|
6238
|
+
if ($el) {
|
|
6239
|
+
delayHandlerElementPostionList.length = 0;
|
|
6240
|
+
if (Array.isArray($el)) {
|
|
6241
|
+
delayHandlerElementPostionList.push(...$el);
|
|
6242
|
+
}
|
|
6243
|
+
else {
|
|
6244
|
+
delayHandlerElementPostionList.push($el);
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6247
|
+
const positionInfoList = delayHandlerElementPostionList
|
|
6248
|
+
.map((position) => {
|
|
6249
|
+
let positionNode;
|
|
6250
|
+
let positionX;
|
|
6251
|
+
let positionY;
|
|
6252
|
+
if (position instanceof HTMLElement) {
|
|
6253
|
+
positionNode = position;
|
|
6254
|
+
const nodeRect = position.getBoundingClientRect();
|
|
6255
|
+
positionX = nodeRect.x + nodeRect.width / 2;
|
|
6256
|
+
positionY = nodeRect.y + nodeRect.height / 2;
|
|
6257
|
+
}
|
|
6258
|
+
else {
|
|
6259
|
+
positionNode = document.elementFromPoint(position.x, position.y);
|
|
6260
|
+
positionX = position.x;
|
|
6261
|
+
positionY = position.y;
|
|
6262
|
+
}
|
|
6263
|
+
const shadowRoot = positionNode?.shadowRoot;
|
|
6264
|
+
if (shadowRoot) {
|
|
6265
|
+
positionNode = shadowRoot.elementFromPoint(positionX, positionY);
|
|
6266
|
+
}
|
|
6267
|
+
if (positionNode instanceof HTMLStyleElement)
|
|
6268
|
+
return;
|
|
6269
|
+
if (positionNode instanceof HTMLScriptElement)
|
|
6270
|
+
return;
|
|
6271
|
+
if (positionNode instanceof HTMLMetaElement)
|
|
6272
|
+
return;
|
|
6273
|
+
if (positionNode instanceof HTMLHeadElement)
|
|
6274
|
+
return;
|
|
6275
|
+
if (!(positionNode instanceof HTMLElement))
|
|
6276
|
+
return;
|
|
6277
|
+
let parent = positionNode;
|
|
6278
|
+
let zIndex = 0;
|
|
6279
|
+
let maxZIndexNode = null;
|
|
6280
|
+
while (parent) {
|
|
6281
|
+
const nodeStyle = globalThis.getComputedStyle(parent);
|
|
6282
|
+
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6283
|
+
if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
|
|
6284
|
+
if (nodeZIndex > zIndex) {
|
|
6285
|
+
zIndex = nodeZIndex;
|
|
6286
|
+
maxZIndexNode = parent;
|
|
6287
|
+
}
|
|
6288
|
+
}
|
|
6289
|
+
parent = parent.parentElement;
|
|
6290
|
+
}
|
|
6291
|
+
return {
|
|
6292
|
+
/** 处理了偏移量后的z-index值 */
|
|
6293
|
+
zIndex: zIndex + deviation,
|
|
6294
|
+
/** 原始z-index值 */
|
|
6295
|
+
originZIndex: zIndex,
|
|
6296
|
+
/** 拥有最大z-index的元素 */
|
|
6297
|
+
node: maxZIndexNode,
|
|
6298
|
+
/** 目标坐标元素 */
|
|
6299
|
+
positionNode: positionNode,
|
|
6300
|
+
/** x坐标 */
|
|
6301
|
+
positionX: positionX,
|
|
6302
|
+
/** y坐标 */
|
|
6303
|
+
positionY: positionY,
|
|
6304
|
+
};
|
|
6305
|
+
})
|
|
6306
|
+
.filter((it) => it != null);
|
|
6307
|
+
// 降序排序
|
|
6308
|
+
positionInfoList.sort((a, b) => {
|
|
6309
|
+
if (a.zIndex < b.zIndex) {
|
|
6310
|
+
return 1;
|
|
6311
|
+
}
|
|
6312
|
+
else if (a.zIndex > b.zIndex) {
|
|
6313
|
+
return -1;
|
|
6314
|
+
}
|
|
6315
|
+
else {
|
|
6316
|
+
return 0;
|
|
6317
|
+
}
|
|
6318
|
+
});
|
|
6319
|
+
return positionInfoList;
|
|
6320
|
+
}
|
|
6183
6321
|
getMaxZIndex(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
|
|
6184
6322
|
return this.getMaxZIndexNodeInfo(deviation, target, ignoreCallBack).zIndex;
|
|
6185
6323
|
}
|
|
@@ -6733,7 +6871,6 @@
|
|
|
6733
6871
|
"is",
|
|
6734
6872
|
"jquery",
|
|
6735
6873
|
"keydown",
|
|
6736
|
-
"keypress",
|
|
6737
6874
|
"keyup",
|
|
6738
6875
|
"last",
|
|
6739
6876
|
"load",
|