@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.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.9";
|
|
247
247
|
|
|
248
248
|
/* eslint-disable */
|
|
249
249
|
// ==UserScript==
|
|
@@ -6133,31 +6133,35 @@
|
|
|
6133
6133
|
* 元素是否可见
|
|
6134
6134
|
* @param $el
|
|
6135
6135
|
* @param $css
|
|
6136
|
+
* @returns
|
|
6137
|
+
* + true 可见
|
|
6138
|
+
* + false 不可见
|
|
6136
6139
|
*/
|
|
6137
|
-
function
|
|
6140
|
+
const isVisibleNode = function ($css, $el) {
|
|
6138
6141
|
let flag = true;
|
|
6139
|
-
if (
|
|
6140
|
-
flag =
|
|
6142
|
+
if (!($el instanceof HTMLElement)) {
|
|
6143
|
+
flag = false;
|
|
6141
6144
|
}
|
|
6142
6145
|
else {
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6146
|
+
if (typeof $el.checkVisibility === "function") {
|
|
6147
|
+
flag = $el.checkVisibility();
|
|
6148
|
+
}
|
|
6149
|
+
else {
|
|
6150
|
+
flag =
|
|
6151
|
+
$css.position !== "static" &&
|
|
6152
|
+
$css.display !== "none" &&
|
|
6153
|
+
$css.visibility !== "hidden" &&
|
|
6154
|
+
$css.opacity !== "0";
|
|
6155
|
+
}
|
|
6152
6156
|
}
|
|
6153
6157
|
return flag;
|
|
6154
|
-
}
|
|
6158
|
+
};
|
|
6155
6159
|
/**
|
|
6156
6160
|
* 查询元素的z-index
|
|
6157
6161
|
* 并比较值是否是已获取的最大值
|
|
6158
6162
|
* @param $el
|
|
6159
6163
|
*/
|
|
6160
|
-
function
|
|
6164
|
+
const queryMaxZIndex = function ($el) {
|
|
6161
6165
|
if (typeof ignoreCallBack === "function") {
|
|
6162
6166
|
const ignoreResult = ignoreCallBack($el);
|
|
6163
6167
|
if (typeof ignoreResult === "boolean" && !ignoreResult) {
|
|
@@ -6165,9 +6169,9 @@
|
|
|
6165
6169
|
}
|
|
6166
6170
|
}
|
|
6167
6171
|
/** 元素的样式 */
|
|
6168
|
-
const nodeStyle = that.windowApi.
|
|
6172
|
+
const nodeStyle = that.windowApi.globalThis.getComputedStyle($el);
|
|
6169
6173
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
6170
|
-
if (isVisibleNode($el
|
|
6174
|
+
if (isVisibleNode(nodeStyle, $el)) {
|
|
6171
6175
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6172
6176
|
if (!isNaN(nodeZIndex)) {
|
|
6173
6177
|
if (nodeZIndex > zIndex) {
|
|
@@ -6183,7 +6187,7 @@
|
|
|
6183
6187
|
});
|
|
6184
6188
|
}
|
|
6185
6189
|
}
|
|
6186
|
-
}
|
|
6190
|
+
};
|
|
6187
6191
|
target.querySelectorAll("*").forEach(($elItem) => {
|
|
6188
6192
|
queryMaxZIndex($elItem);
|
|
6189
6193
|
});
|
|
@@ -6208,33 +6212,31 @@
|
|
|
6208
6212
|
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
6209
6213
|
deviation = 10;
|
|
6210
6214
|
}
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
const
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
center,
|
|
6237
|
-
];
|
|
6215
|
+
/** 坐标偏移 */
|
|
6216
|
+
const positionDistance = 10;
|
|
6217
|
+
const defaultCalcPostion = [];
|
|
6218
|
+
const maxPostionX = globalThis.innerWidth;
|
|
6219
|
+
const maxPostionY = globalThis.innerHeight;
|
|
6220
|
+
const gridXCount = 8;
|
|
6221
|
+
const gridYCount = 8;
|
|
6222
|
+
for (let i = 0; i < gridXCount; i++) {
|
|
6223
|
+
for (let j = 0; j < gridYCount; j++) {
|
|
6224
|
+
const positionX = globalThis.innerWidth * (i / gridXCount) + positionDistance;
|
|
6225
|
+
const positionY = globalThis.innerHeight * (j / gridYCount) + positionDistance;
|
|
6226
|
+
const position = {
|
|
6227
|
+
x: positionX,
|
|
6228
|
+
y: positionY,
|
|
6229
|
+
};
|
|
6230
|
+
if (position.x > maxPostionX) {
|
|
6231
|
+
position.x = maxPostionX;
|
|
6232
|
+
}
|
|
6233
|
+
if (position.y > maxPostionY) {
|
|
6234
|
+
position.y = maxPostionY;
|
|
6235
|
+
}
|
|
6236
|
+
defaultCalcPostion.push(position);
|
|
6237
|
+
}
|
|
6238
|
+
}
|
|
6239
|
+
const delayHandlerElementPostionList = defaultCalcPostion;
|
|
6238
6240
|
if ($el) {
|
|
6239
6241
|
delayHandlerElementPostionList.length = 0;
|
|
6240
6242
|
if (Array.isArray($el)) {
|
|
@@ -6246,61 +6248,79 @@
|
|
|
6246
6248
|
}
|
|
6247
6249
|
const positionInfoList = delayHandlerElementPostionList
|
|
6248
6250
|
.map((position) => {
|
|
6249
|
-
let
|
|
6251
|
+
let $position;
|
|
6250
6252
|
let positionX;
|
|
6251
6253
|
let positionY;
|
|
6252
6254
|
if (position instanceof HTMLElement) {
|
|
6253
|
-
|
|
6255
|
+
$position = position;
|
|
6254
6256
|
const nodeRect = position.getBoundingClientRect();
|
|
6255
6257
|
positionX = nodeRect.x + nodeRect.width / 2;
|
|
6256
6258
|
positionY = nodeRect.y + nodeRect.height / 2;
|
|
6257
6259
|
}
|
|
6258
6260
|
else {
|
|
6259
|
-
|
|
6261
|
+
$position = document.elementFromPoint(position.x, position.y);
|
|
6260
6262
|
positionX = position.x;
|
|
6261
6263
|
positionY = position.y;
|
|
6262
6264
|
}
|
|
6263
|
-
const shadowRoot =
|
|
6265
|
+
const shadowRoot = $position?.shadowRoot;
|
|
6264
6266
|
if (shadowRoot) {
|
|
6265
|
-
|
|
6267
|
+
// 处理ShadowRoot
|
|
6268
|
+
$position = shadowRoot.elementFromPoint(positionX, positionY);
|
|
6266
6269
|
}
|
|
6267
|
-
if (
|
|
6268
|
-
return;
|
|
6269
|
-
if (positionNode instanceof HTMLScriptElement)
|
|
6270
|
-
return;
|
|
6271
|
-
if (positionNode instanceof HTMLMetaElement)
|
|
6272
|
-
return;
|
|
6273
|
-
if (positionNode instanceof HTMLHeadElement)
|
|
6270
|
+
if (!($position instanceof HTMLElement))
|
|
6274
6271
|
return;
|
|
6275
|
-
|
|
6276
|
-
return;
|
|
6277
|
-
let parent = positionNode;
|
|
6272
|
+
let $parent = $position;
|
|
6278
6273
|
let zIndex = 0;
|
|
6279
|
-
let maxZIndexNode = null;
|
|
6280
|
-
|
|
6281
|
-
|
|
6274
|
+
let $maxZIndexNode = null;
|
|
6275
|
+
let rect = {
|
|
6276
|
+
x: 0,
|
|
6277
|
+
y: 0,
|
|
6278
|
+
width: 0,
|
|
6279
|
+
height: 0,
|
|
6280
|
+
top: 0,
|
|
6281
|
+
right: 0,
|
|
6282
|
+
bottom: 0,
|
|
6283
|
+
left: 0,
|
|
6284
|
+
};
|
|
6285
|
+
while ($parent) {
|
|
6286
|
+
const nodeStyle = globalThis.getComputedStyle($parent);
|
|
6282
6287
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6283
6288
|
if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
|
|
6284
6289
|
if (nodeZIndex > zIndex) {
|
|
6285
6290
|
zIndex = nodeZIndex;
|
|
6286
|
-
maxZIndexNode = parent;
|
|
6291
|
+
$maxZIndexNode = $parent;
|
|
6287
6292
|
}
|
|
6288
6293
|
}
|
|
6289
|
-
parent = parent.parentElement;
|
|
6294
|
+
$parent = $parent.parentElement;
|
|
6295
|
+
}
|
|
6296
|
+
if ($maxZIndexNode) {
|
|
6297
|
+
const maxRect = $maxZIndexNode.getBoundingClientRect();
|
|
6298
|
+
rect = {
|
|
6299
|
+
x: maxRect.x,
|
|
6300
|
+
y: maxRect.y,
|
|
6301
|
+
width: maxRect.width,
|
|
6302
|
+
height: maxRect.height,
|
|
6303
|
+
top: maxRect.top,
|
|
6304
|
+
right: maxRect.right,
|
|
6305
|
+
bottom: maxRect.bottom,
|
|
6306
|
+
left: maxRect.left,
|
|
6307
|
+
};
|
|
6290
6308
|
}
|
|
6291
6309
|
return {
|
|
6292
|
-
/**
|
|
6310
|
+
/** 计算偏移量后的z-index值 */
|
|
6293
6311
|
zIndex: zIndex + deviation,
|
|
6294
|
-
/**
|
|
6312
|
+
/** 获取到的最大的z-index值 */
|
|
6295
6313
|
originZIndex: zIndex,
|
|
6296
6314
|
/** 拥有最大z-index的元素 */
|
|
6297
|
-
node: maxZIndexNode,
|
|
6315
|
+
node: $maxZIndexNode,
|
|
6298
6316
|
/** 目标坐标元素 */
|
|
6299
|
-
positionNode:
|
|
6300
|
-
/** x坐标 */
|
|
6317
|
+
positionNode: $position,
|
|
6318
|
+
/** 目标x坐标 */
|
|
6301
6319
|
positionX: positionX,
|
|
6302
|
-
/** y坐标 */
|
|
6320
|
+
/** 目标y坐标 */
|
|
6303
6321
|
positionY: positionY,
|
|
6322
|
+
/** node位置信息 */
|
|
6323
|
+
rect,
|
|
6304
6324
|
};
|
|
6305
6325
|
})
|
|
6306
6326
|
.filter((it) => it != null);
|
|
@@ -8325,6 +8345,20 @@
|
|
|
8325
8345
|
* 深度获取对象的某个属性
|
|
8326
8346
|
* @param target 待获取的对象
|
|
8327
8347
|
* @param handler 获取属性的回调
|
|
8348
|
+
* @example
|
|
8349
|
+
* Utils.queryProperty(window,(target)=>{
|
|
8350
|
+
* if(target.xxx){
|
|
8351
|
+
* return {
|
|
8352
|
+
* isFind: true,
|
|
8353
|
+
* data: target.xxx,
|
|
8354
|
+
* }
|
|
8355
|
+
* }else{
|
|
8356
|
+
* return {
|
|
8357
|
+
* isFind: false,
|
|
8358
|
+
* data: target.aabbcc,
|
|
8359
|
+
* }
|
|
8360
|
+
* }
|
|
8361
|
+
* })
|
|
8328
8362
|
*/
|
|
8329
8363
|
queryProperty(target, handler) {
|
|
8330
8364
|
if (target == null) {
|
|
@@ -8340,10 +8374,23 @@
|
|
|
8340
8374
|
* 异步-深度获取对象属性
|
|
8341
8375
|
* @param target 待获取的对象
|
|
8342
8376
|
* @param handler 获取属性的回调
|
|
8377
|
+
* @example
|
|
8378
|
+
* Utils.asyncQueryProperty(window, async (target)=>{
|
|
8379
|
+
* if(target.xxx){
|
|
8380
|
+
* return {
|
|
8381
|
+
* isFind: true,
|
|
8382
|
+
* data: target.xxx,
|
|
8383
|
+
* }
|
|
8384
|
+
* }else{
|
|
8385
|
+
* return {
|
|
8386
|
+
* isFind: false,
|
|
8387
|
+
* data: target.aabbcc,
|
|
8388
|
+
* }
|
|
8389
|
+
* }
|
|
8390
|
+
* })
|
|
8343
8391
|
*/
|
|
8344
8392
|
async asyncQueryProperty(target, handler) {
|
|
8345
8393
|
if (target == null) {
|
|
8346
|
-
// @ts-expect-error 空返回
|
|
8347
8394
|
return;
|
|
8348
8395
|
}
|
|
8349
8396
|
const handleResult = await handler(target);
|
|
@@ -8355,7 +8402,8 @@
|
|
|
8355
8402
|
/**
|
|
8356
8403
|
* 创建一个新的Utils实例
|
|
8357
8404
|
* @param option
|
|
8358
|
-
* @
|
|
8405
|
+
* @example
|
|
8406
|
+
* Utils.createUtils();
|
|
8359
8407
|
*/
|
|
8360
8408
|
createUtils(option) {
|
|
8361
8409
|
return new Utils(option);
|
|
@@ -8423,7 +8471,9 @@
|
|
|
8423
8471
|
/**
|
|
8424
8472
|
* 覆盖对象中的函数this指向
|
|
8425
8473
|
* @param target 需要覆盖的对象
|
|
8426
|
-
* @param
|
|
8474
|
+
* @param objectThis 覆盖的this指向,如果为传入,则默认为对象本身
|
|
8475
|
+
* @example
|
|
8476
|
+
* Utils.coverObjectFunctionThis({})
|
|
8427
8477
|
*/
|
|
8428
8478
|
coverObjectFunctionThis = commonUtil.coverObjectFunctionThis.bind(commonUtil);
|
|
8429
8479
|
/**
|
|
@@ -8474,7 +8524,7 @@
|
|
|
8474
8524
|
/**
|
|
8475
8525
|
* 自动使用 Worker 执行 setTimeout
|
|
8476
8526
|
* @param callback 回调函数
|
|
8477
|
-
* @param
|
|
8527
|
+
* @param timeout 延迟时间,默认为0
|
|
8478
8528
|
*/
|
|
8479
8529
|
workerSetTimeout(callback, timeout = 0) {
|
|
8480
8530
|
try {
|
|
@@ -8545,6 +8595,10 @@
|
|
|
8545
8595
|
/**
|
|
8546
8596
|
* 判断页面中是否存在`worker-src`的CSP规则
|
|
8547
8597
|
* @param timeout 超时时间,默认为`1500ms`
|
|
8598
|
+
* @example
|
|
8599
|
+
* Utils.hasWorkerCSP().then((hasCSP) => {
|
|
8600
|
+
* console.log(hasCSP);
|
|
8601
|
+
* })
|
|
8548
8602
|
*/
|
|
8549
8603
|
hasWorkerCSP(timeout = 1500) {
|
|
8550
8604
|
return new Promise((resolve) => {
|