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