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