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