@whitesev/utils 2.11.7 → 2.11.9
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 +129 -75
- 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 +129 -75
- 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 +129 -75
- 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 +129 -75
- 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 +129 -75
- 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 +129 -75
- 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 +82 -35
- package/dist/types/src/types/env.d.ts +2 -0
- package/package.json +1 -1
- package/src/Utils.ts +186 -119
- package/src/types/env.d.ts +2 -0
package/dist/index.esm.js
CHANGED
|
@@ -237,7 +237,7 @@ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
|
237
237
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
238
238
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
239
239
|
|
|
240
|
-
const version = "2.11.
|
|
240
|
+
const version = "2.11.9";
|
|
241
241
|
|
|
242
242
|
/* eslint-disable */
|
|
243
243
|
// ==UserScript==
|
|
@@ -6127,31 +6127,35 @@ class Utils {
|
|
|
6127
6127
|
* 元素是否可见
|
|
6128
6128
|
* @param $el
|
|
6129
6129
|
* @param $css
|
|
6130
|
+
* @returns
|
|
6131
|
+
* + true 可见
|
|
6132
|
+
* + false 不可见
|
|
6130
6133
|
*/
|
|
6131
|
-
function
|
|
6134
|
+
const isVisibleNode = function ($css, $el) {
|
|
6132
6135
|
let flag = true;
|
|
6133
|
-
if (
|
|
6134
|
-
flag =
|
|
6136
|
+
if (!($el instanceof HTMLElement)) {
|
|
6137
|
+
flag = false;
|
|
6135
6138
|
}
|
|
6136
6139
|
else {
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6140
|
+
if (typeof $el.checkVisibility === "function") {
|
|
6141
|
+
flag = $el.checkVisibility();
|
|
6142
|
+
}
|
|
6143
|
+
else {
|
|
6144
|
+
flag =
|
|
6145
|
+
$css.position !== "static" &&
|
|
6146
|
+
$css.display !== "none" &&
|
|
6147
|
+
$css.visibility !== "hidden" &&
|
|
6148
|
+
$css.opacity !== "0";
|
|
6149
|
+
}
|
|
6146
6150
|
}
|
|
6147
6151
|
return flag;
|
|
6148
|
-
}
|
|
6152
|
+
};
|
|
6149
6153
|
/**
|
|
6150
6154
|
* 查询元素的z-index
|
|
6151
6155
|
* 并比较值是否是已获取的最大值
|
|
6152
6156
|
* @param $el
|
|
6153
6157
|
*/
|
|
6154
|
-
function
|
|
6158
|
+
const queryMaxZIndex = function ($el) {
|
|
6155
6159
|
if (typeof ignoreCallBack === "function") {
|
|
6156
6160
|
const ignoreResult = ignoreCallBack($el);
|
|
6157
6161
|
if (typeof ignoreResult === "boolean" && !ignoreResult) {
|
|
@@ -6159,9 +6163,9 @@ class Utils {
|
|
|
6159
6163
|
}
|
|
6160
6164
|
}
|
|
6161
6165
|
/** 元素的样式 */
|
|
6162
|
-
const nodeStyle = that.windowApi.
|
|
6166
|
+
const nodeStyle = that.windowApi.globalThis.getComputedStyle($el);
|
|
6163
6167
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
6164
|
-
if (isVisibleNode($el
|
|
6168
|
+
if (isVisibleNode(nodeStyle, $el)) {
|
|
6165
6169
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6166
6170
|
if (!isNaN(nodeZIndex)) {
|
|
6167
6171
|
if (nodeZIndex > zIndex) {
|
|
@@ -6177,7 +6181,7 @@ class Utils {
|
|
|
6177
6181
|
});
|
|
6178
6182
|
}
|
|
6179
6183
|
}
|
|
6180
|
-
}
|
|
6184
|
+
};
|
|
6181
6185
|
target.querySelectorAll("*").forEach(($elItem) => {
|
|
6182
6186
|
queryMaxZIndex($elItem);
|
|
6183
6187
|
});
|
|
@@ -6202,33 +6206,31 @@ class Utils {
|
|
|
6202
6206
|
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
6203
6207
|
deviation = 10;
|
|
6204
6208
|
}
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
const
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
center,
|
|
6231
|
-
];
|
|
6209
|
+
/** 坐标偏移 */
|
|
6210
|
+
const positionDistance = 10;
|
|
6211
|
+
const defaultCalcPostion = [];
|
|
6212
|
+
const maxPostionX = globalThis.innerWidth;
|
|
6213
|
+
const maxPostionY = globalThis.innerHeight;
|
|
6214
|
+
const gridXCount = 8;
|
|
6215
|
+
const gridYCount = 8;
|
|
6216
|
+
for (let i = 0; i < gridXCount; i++) {
|
|
6217
|
+
for (let j = 0; j < gridYCount; j++) {
|
|
6218
|
+
const positionX = globalThis.innerWidth * (i / gridXCount) + positionDistance;
|
|
6219
|
+
const positionY = globalThis.innerHeight * (j / gridYCount) + positionDistance;
|
|
6220
|
+
const position = {
|
|
6221
|
+
x: positionX,
|
|
6222
|
+
y: positionY,
|
|
6223
|
+
};
|
|
6224
|
+
if (position.x > maxPostionX) {
|
|
6225
|
+
position.x = maxPostionX;
|
|
6226
|
+
}
|
|
6227
|
+
if (position.y > maxPostionY) {
|
|
6228
|
+
position.y = maxPostionY;
|
|
6229
|
+
}
|
|
6230
|
+
defaultCalcPostion.push(position);
|
|
6231
|
+
}
|
|
6232
|
+
}
|
|
6233
|
+
const delayHandlerElementPostionList = defaultCalcPostion;
|
|
6232
6234
|
if ($el) {
|
|
6233
6235
|
delayHandlerElementPostionList.length = 0;
|
|
6234
6236
|
if (Array.isArray($el)) {
|
|
@@ -6240,61 +6242,79 @@ class Utils {
|
|
|
6240
6242
|
}
|
|
6241
6243
|
const positionInfoList = delayHandlerElementPostionList
|
|
6242
6244
|
.map((position) => {
|
|
6243
|
-
let
|
|
6245
|
+
let $position;
|
|
6244
6246
|
let positionX;
|
|
6245
6247
|
let positionY;
|
|
6246
6248
|
if (position instanceof HTMLElement) {
|
|
6247
|
-
|
|
6249
|
+
$position = position;
|
|
6248
6250
|
const nodeRect = position.getBoundingClientRect();
|
|
6249
6251
|
positionX = nodeRect.x + nodeRect.width / 2;
|
|
6250
6252
|
positionY = nodeRect.y + nodeRect.height / 2;
|
|
6251
6253
|
}
|
|
6252
6254
|
else {
|
|
6253
|
-
|
|
6255
|
+
$position = document.elementFromPoint(position.x, position.y);
|
|
6254
6256
|
positionX = position.x;
|
|
6255
6257
|
positionY = position.y;
|
|
6256
6258
|
}
|
|
6257
|
-
const shadowRoot =
|
|
6259
|
+
const shadowRoot = $position?.shadowRoot;
|
|
6258
6260
|
if (shadowRoot) {
|
|
6259
|
-
|
|
6261
|
+
// 处理ShadowRoot
|
|
6262
|
+
$position = shadowRoot.elementFromPoint(positionX, positionY);
|
|
6260
6263
|
}
|
|
6261
|
-
if (
|
|
6262
|
-
return;
|
|
6263
|
-
if (positionNode instanceof HTMLScriptElement)
|
|
6264
|
-
return;
|
|
6265
|
-
if (positionNode instanceof HTMLMetaElement)
|
|
6266
|
-
return;
|
|
6267
|
-
if (positionNode instanceof HTMLHeadElement)
|
|
6264
|
+
if (!($position instanceof HTMLElement))
|
|
6268
6265
|
return;
|
|
6269
|
-
|
|
6270
|
-
return;
|
|
6271
|
-
let parent = positionNode;
|
|
6266
|
+
let $parent = $position;
|
|
6272
6267
|
let zIndex = 0;
|
|
6273
|
-
let maxZIndexNode = null;
|
|
6274
|
-
|
|
6275
|
-
|
|
6268
|
+
let $maxZIndexNode = null;
|
|
6269
|
+
let rect = {
|
|
6270
|
+
x: 0,
|
|
6271
|
+
y: 0,
|
|
6272
|
+
width: 0,
|
|
6273
|
+
height: 0,
|
|
6274
|
+
top: 0,
|
|
6275
|
+
right: 0,
|
|
6276
|
+
bottom: 0,
|
|
6277
|
+
left: 0,
|
|
6278
|
+
};
|
|
6279
|
+
while ($parent) {
|
|
6280
|
+
const nodeStyle = globalThis.getComputedStyle($parent);
|
|
6276
6281
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6277
6282
|
if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
|
|
6278
6283
|
if (nodeZIndex > zIndex) {
|
|
6279
6284
|
zIndex = nodeZIndex;
|
|
6280
|
-
maxZIndexNode = parent;
|
|
6285
|
+
$maxZIndexNode = $parent;
|
|
6281
6286
|
}
|
|
6282
6287
|
}
|
|
6283
|
-
parent = parent.parentElement;
|
|
6288
|
+
$parent = $parent.parentElement;
|
|
6289
|
+
}
|
|
6290
|
+
if ($maxZIndexNode) {
|
|
6291
|
+
const maxRect = $maxZIndexNode.getBoundingClientRect();
|
|
6292
|
+
rect = {
|
|
6293
|
+
x: maxRect.x,
|
|
6294
|
+
y: maxRect.y,
|
|
6295
|
+
width: maxRect.width,
|
|
6296
|
+
height: maxRect.height,
|
|
6297
|
+
top: maxRect.top,
|
|
6298
|
+
right: maxRect.right,
|
|
6299
|
+
bottom: maxRect.bottom,
|
|
6300
|
+
left: maxRect.left,
|
|
6301
|
+
};
|
|
6284
6302
|
}
|
|
6285
6303
|
return {
|
|
6286
|
-
/**
|
|
6304
|
+
/** 计算偏移量后的z-index值 */
|
|
6287
6305
|
zIndex: zIndex + deviation,
|
|
6288
|
-
/**
|
|
6306
|
+
/** 获取到的最大的z-index值 */
|
|
6289
6307
|
originZIndex: zIndex,
|
|
6290
6308
|
/** 拥有最大z-index的元素 */
|
|
6291
|
-
node: maxZIndexNode,
|
|
6309
|
+
node: $maxZIndexNode,
|
|
6292
6310
|
/** 目标坐标元素 */
|
|
6293
|
-
positionNode:
|
|
6294
|
-
/** x坐标 */
|
|
6311
|
+
positionNode: $position,
|
|
6312
|
+
/** 目标x坐标 */
|
|
6295
6313
|
positionX: positionX,
|
|
6296
|
-
/** y坐标 */
|
|
6314
|
+
/** 目标y坐标 */
|
|
6297
6315
|
positionY: positionY,
|
|
6316
|
+
/** node位置信息 */
|
|
6317
|
+
rect,
|
|
6298
6318
|
};
|
|
6299
6319
|
})
|
|
6300
6320
|
.filter((it) => it != null);
|
|
@@ -8319,6 +8339,20 @@ class Utils {
|
|
|
8319
8339
|
* 深度获取对象的某个属性
|
|
8320
8340
|
* @param target 待获取的对象
|
|
8321
8341
|
* @param handler 获取属性的回调
|
|
8342
|
+
* @example
|
|
8343
|
+
* Utils.queryProperty(window,(target)=>{
|
|
8344
|
+
* if(target.xxx){
|
|
8345
|
+
* return {
|
|
8346
|
+
* isFind: true,
|
|
8347
|
+
* data: target.xxx,
|
|
8348
|
+
* }
|
|
8349
|
+
* }else{
|
|
8350
|
+
* return {
|
|
8351
|
+
* isFind: false,
|
|
8352
|
+
* data: target.aabbcc,
|
|
8353
|
+
* }
|
|
8354
|
+
* }
|
|
8355
|
+
* })
|
|
8322
8356
|
*/
|
|
8323
8357
|
queryProperty(target, handler) {
|
|
8324
8358
|
if (target == null) {
|
|
@@ -8334,10 +8368,23 @@ class Utils {
|
|
|
8334
8368
|
* 异步-深度获取对象属性
|
|
8335
8369
|
* @param target 待获取的对象
|
|
8336
8370
|
* @param handler 获取属性的回调
|
|
8371
|
+
* @example
|
|
8372
|
+
* Utils.asyncQueryProperty(window, async (target)=>{
|
|
8373
|
+
* if(target.xxx){
|
|
8374
|
+
* return {
|
|
8375
|
+
* isFind: true,
|
|
8376
|
+
* data: target.xxx,
|
|
8377
|
+
* }
|
|
8378
|
+
* }else{
|
|
8379
|
+
* return {
|
|
8380
|
+
* isFind: false,
|
|
8381
|
+
* data: target.aabbcc,
|
|
8382
|
+
* }
|
|
8383
|
+
* }
|
|
8384
|
+
* })
|
|
8337
8385
|
*/
|
|
8338
8386
|
async asyncQueryProperty(target, handler) {
|
|
8339
8387
|
if (target == null) {
|
|
8340
|
-
// @ts-expect-error 空返回
|
|
8341
8388
|
return;
|
|
8342
8389
|
}
|
|
8343
8390
|
const handleResult = await handler(target);
|
|
@@ -8349,7 +8396,8 @@ class Utils {
|
|
|
8349
8396
|
/**
|
|
8350
8397
|
* 创建一个新的Utils实例
|
|
8351
8398
|
* @param option
|
|
8352
|
-
* @
|
|
8399
|
+
* @example
|
|
8400
|
+
* Utils.createUtils();
|
|
8353
8401
|
*/
|
|
8354
8402
|
createUtils(option) {
|
|
8355
8403
|
return new Utils(option);
|
|
@@ -8417,7 +8465,9 @@ class Utils {
|
|
|
8417
8465
|
/**
|
|
8418
8466
|
* 覆盖对象中的函数this指向
|
|
8419
8467
|
* @param target 需要覆盖的对象
|
|
8420
|
-
* @param
|
|
8468
|
+
* @param objectThis 覆盖的this指向,如果为传入,则默认为对象本身
|
|
8469
|
+
* @example
|
|
8470
|
+
* Utils.coverObjectFunctionThis({})
|
|
8421
8471
|
*/
|
|
8422
8472
|
coverObjectFunctionThis = commonUtil.coverObjectFunctionThis.bind(commonUtil);
|
|
8423
8473
|
/**
|
|
@@ -8468,7 +8518,7 @@ class Utils {
|
|
|
8468
8518
|
/**
|
|
8469
8519
|
* 自动使用 Worker 执行 setTimeout
|
|
8470
8520
|
* @param callback 回调函数
|
|
8471
|
-
* @param
|
|
8521
|
+
* @param timeout 延迟时间,默认为0
|
|
8472
8522
|
*/
|
|
8473
8523
|
workerSetTimeout(callback, timeout = 0) {
|
|
8474
8524
|
try {
|
|
@@ -8539,6 +8589,10 @@ class Utils {
|
|
|
8539
8589
|
/**
|
|
8540
8590
|
* 判断页面中是否存在`worker-src`的CSP规则
|
|
8541
8591
|
* @param timeout 超时时间,默认为`1500ms`
|
|
8592
|
+
* @example
|
|
8593
|
+
* Utils.hasWorkerCSP().then((hasCSP) => {
|
|
8594
|
+
* console.log(hasCSP);
|
|
8595
|
+
* })
|
|
8542
8596
|
*/
|
|
8543
8597
|
hasWorkerCSP(timeout = 1500) {
|
|
8544
8598
|
return new Promise((resolve) => {
|