@whitesev/utils 2.11.7 → 2.11.8

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.
@@ -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.7";
243
+ const version = "2.11.8";
244
244
 
245
245
  /* eslint-disable */
246
246
  // ==UserScript==
@@ -6130,31 +6130,35 @@ var Utils = (function () {
6130
6130
  * 元素是否可见
6131
6131
  * @param $el
6132
6132
  * @param $css
6133
+ * @returns
6134
+ * + true 可见
6135
+ * + false 不可见
6133
6136
  */
6134
- function isVisibleNode($el, $css) {
6137
+ const isVisibleNode = function ($css, $el) {
6135
6138
  let flag = true;
6136
- if (typeof $el.checkVisibility === "function") {
6137
- flag = $el.checkVisibility();
6139
+ if (!($el instanceof HTMLElement)) {
6140
+ flag = false;
6138
6141
  }
6139
6142
  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;
6143
+ if (typeof $el.checkVisibility === "function") {
6144
+ flag = $el.checkVisibility();
6145
+ }
6146
+ else {
6147
+ flag =
6148
+ $css.position !== "static" &&
6149
+ $css.display !== "none" &&
6150
+ $css.visibility !== "hidden" &&
6151
+ $css.opacity !== "0";
6152
+ }
6149
6153
  }
6150
6154
  return flag;
6151
- }
6155
+ };
6152
6156
  /**
6153
6157
  * 查询元素的z-index
6154
6158
  * 并比较值是否是已获取的最大值
6155
6159
  * @param $el
6156
6160
  */
6157
- function queryMaxZIndex($el) {
6161
+ const queryMaxZIndex = function ($el) {
6158
6162
  if (typeof ignoreCallBack === "function") {
6159
6163
  const ignoreResult = ignoreCallBack($el);
6160
6164
  if (typeof ignoreResult === "boolean" && !ignoreResult) {
@@ -6162,9 +6166,9 @@ var Utils = (function () {
6162
6166
  }
6163
6167
  }
6164
6168
  /** 元素的样式 */
6165
- const nodeStyle = that.windowApi.window.getComputedStyle($el);
6169
+ const nodeStyle = that.windowApi.globalThis.getComputedStyle($el);
6166
6170
  /* 不对position为static和display为none的元素进行获取它们的z-index */
6167
- if (isVisibleNode($el, nodeStyle)) {
6171
+ if (isVisibleNode(nodeStyle, $el)) {
6168
6172
  const nodeZIndex = parseInt(nodeStyle.zIndex);
6169
6173
  if (!isNaN(nodeZIndex)) {
6170
6174
  if (nodeZIndex > zIndex) {
@@ -6180,7 +6184,7 @@ var Utils = (function () {
6180
6184
  });
6181
6185
  }
6182
6186
  }
6183
- }
6187
+ };
6184
6188
  target.querySelectorAll("*").forEach(($elItem) => {
6185
6189
  queryMaxZIndex($elItem);
6186
6190
  });
@@ -6205,33 +6209,31 @@ var Utils = (function () {
6205
6209
  if (typeof deviation !== "number" || Number.isNaN(deviation)) {
6206
6210
  deviation = 10;
6207
6211
  }
6208
- const leftTop = {
6209
- x: globalThis.innerWidth * (1 / 8),
6210
- y: globalThis.innerHeight * (1 / 8),
6211
- };
6212
- const leftBottom = {
6213
- x: globalThis.innerWidth * (1 / 8),
6214
- y: globalThis.innerHeight * (7 / 8),
6215
- };
6216
- const rightTop = {
6217
- x: globalThis.innerWidth * (7 / 8),
6218
- y: globalThis.innerHeight * (1 / 8),
6219
- };
6220
- const rightBottom = {
6221
- x: globalThis.innerWidth * (7 / 8),
6222
- y: globalThis.innerHeight * (7 / 8),
6223
- };
6224
- const center = {
6225
- x: globalThis.innerWidth / 2,
6226
- y: globalThis.innerHeight / 2,
6227
- };
6228
- const delayHandlerElementPostionList = [
6229
- leftTop,
6230
- leftBottom,
6231
- rightTop,
6232
- rightBottom,
6233
- center,
6234
- ];
6212
+ /** 坐标偏移 */
6213
+ const positionDistance = 10;
6214
+ const defaultCalcPostion = [];
6215
+ const maxPostionX = globalThis.innerWidth;
6216
+ const maxPostionY = globalThis.innerHeight;
6217
+ const gridXCount = 8;
6218
+ const gridYCount = 8;
6219
+ for (let i = 0; i < gridXCount; i++) {
6220
+ for (let j = 0; j < gridYCount; j++) {
6221
+ const positionX = globalThis.innerWidth * (i / gridXCount) + positionDistance;
6222
+ const positionY = globalThis.innerHeight * (j / gridYCount) + positionDistance;
6223
+ const position = {
6224
+ x: positionX,
6225
+ y: positionY,
6226
+ };
6227
+ if (position.x > maxPostionX) {
6228
+ position.x = maxPostionX;
6229
+ }
6230
+ if (position.y > maxPostionY) {
6231
+ position.y = maxPostionY;
6232
+ }
6233
+ defaultCalcPostion.push(position);
6234
+ }
6235
+ }
6236
+ const delayHandlerElementPostionList = defaultCalcPostion;
6235
6237
  if ($el) {
6236
6238
  delayHandlerElementPostionList.length = 0;
6237
6239
  if (Array.isArray($el)) {
@@ -6243,61 +6245,79 @@ var Utils = (function () {
6243
6245
  }
6244
6246
  const positionInfoList = delayHandlerElementPostionList
6245
6247
  .map((position) => {
6246
- let positionNode;
6248
+ let $position;
6247
6249
  let positionX;
6248
6250
  let positionY;
6249
6251
  if (position instanceof HTMLElement) {
6250
- positionNode = position;
6252
+ $position = position;
6251
6253
  const nodeRect = position.getBoundingClientRect();
6252
6254
  positionX = nodeRect.x + nodeRect.width / 2;
6253
6255
  positionY = nodeRect.y + nodeRect.height / 2;
6254
6256
  }
6255
6257
  else {
6256
- positionNode = document.elementFromPoint(position.x, position.y);
6258
+ $position = document.elementFromPoint(position.x, position.y);
6257
6259
  positionX = position.x;
6258
6260
  positionY = position.y;
6259
6261
  }
6260
- const shadowRoot = positionNode?.shadowRoot;
6262
+ const shadowRoot = $position?.shadowRoot;
6261
6263
  if (shadowRoot) {
6262
- positionNode = shadowRoot.elementFromPoint(positionX, positionY);
6264
+ // 处理ShadowRoot
6265
+ $position = shadowRoot.elementFromPoint(positionX, positionY);
6263
6266
  }
6264
- if (positionNode instanceof HTMLStyleElement)
6267
+ if (!($position instanceof HTMLElement))
6265
6268
  return;
6266
- if (positionNode instanceof HTMLScriptElement)
6267
- return;
6268
- if (positionNode instanceof HTMLMetaElement)
6269
- return;
6270
- if (positionNode instanceof HTMLHeadElement)
6271
- return;
6272
- if (!(positionNode instanceof HTMLElement))
6273
- return;
6274
- let parent = positionNode;
6269
+ let $parent = $position;
6275
6270
  let zIndex = 0;
6276
- let maxZIndexNode = null;
6277
- while (parent) {
6278
- const nodeStyle = globalThis.getComputedStyle(parent);
6271
+ let $maxZIndexNode = null;
6272
+ let rect = {
6273
+ x: 0,
6274
+ y: 0,
6275
+ width: 0,
6276
+ height: 0,
6277
+ top: 0,
6278
+ right: 0,
6279
+ bottom: 0,
6280
+ left: 0,
6281
+ };
6282
+ while ($parent) {
6283
+ const nodeStyle = globalThis.getComputedStyle($parent);
6279
6284
  const nodeZIndex = parseInt(nodeStyle.zIndex);
6280
6285
  if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
6281
6286
  if (nodeZIndex > zIndex) {
6282
6287
  zIndex = nodeZIndex;
6283
- maxZIndexNode = parent;
6288
+ $maxZIndexNode = $parent;
6284
6289
  }
6285
6290
  }
6286
- parent = parent.parentElement;
6291
+ $parent = $parent.parentElement;
6292
+ }
6293
+ if ($maxZIndexNode) {
6294
+ const maxRect = $maxZIndexNode.getBoundingClientRect();
6295
+ rect = {
6296
+ x: maxRect.x,
6297
+ y: maxRect.y,
6298
+ width: maxRect.width,
6299
+ height: maxRect.height,
6300
+ top: maxRect.top,
6301
+ right: maxRect.right,
6302
+ bottom: maxRect.bottom,
6303
+ left: maxRect.left,
6304
+ };
6287
6305
  }
6288
6306
  return {
6289
- /** 处理了偏移量后的z-index值 */
6307
+ /** 计算偏移量后的z-index值 */
6290
6308
  zIndex: zIndex + deviation,
6291
- /** 原始z-index值 */
6309
+ /** 获取到的最大的z-index值 */
6292
6310
  originZIndex: zIndex,
6293
6311
  /** 拥有最大z-index的元素 */
6294
- node: maxZIndexNode,
6312
+ node: $maxZIndexNode,
6295
6313
  /** 目标坐标元素 */
6296
- positionNode: positionNode,
6297
- /** x坐标 */
6314
+ positionNode: $position,
6315
+ /** 目标x坐标 */
6298
6316
  positionX: positionX,
6299
- /** y坐标 */
6317
+ /** 目标y坐标 */
6300
6318
  positionY: positionY,
6319
+ /** node位置信息 */
6320
+ rect,
6301
6321
  };
6302
6322
  })
6303
6323
  .filter((it) => it != null);