@whitesev/utils 1.9.4 → 1.9.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.
Files changed (34) hide show
  1. package/dist/index.amd.js +72 -64
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +72 -64
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +72 -64
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +72 -64
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +72 -64
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +72 -64
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/UtilsCore.d.ts +16 -0
  14. package/package.json +3 -3
  15. package/dist/src/UtilsCore.d.ts +0 -16
  16. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  17. /package/dist/{src → types/src}/AjaxHookerType.d.ts +0 -0
  18. /package/dist/{src → types/src}/ColorConversion.d.ts +0 -0
  19. /package/dist/{src → types/src}/Dictionary.d.ts +0 -0
  20. /package/dist/{src → types/src}/Event.d.ts +0 -0
  21. /package/dist/{src → types/src}/GBKEncoder.d.ts +0 -0
  22. /package/dist/{src → types/src}/Hooks.d.ts +0 -0
  23. /package/dist/{src → types/src}/Httpx.d.ts +0 -0
  24. /package/dist/{src → types/src}/LockFunction.d.ts +0 -0
  25. /package/dist/{src → types/src}/Log.d.ts +0 -0
  26. /package/dist/{src → types/src}/Progress.d.ts +0 -0
  27. /package/dist/{src → types/src}/TryCatch.d.ts +0 -0
  28. /package/dist/{src → types/src}/Utils.d.ts +0 -0
  29. /package/dist/{src → types/src}/UtilsCommon.d.ts +0 -0
  30. /package/dist/{src → types/src}/UtilsGMCookie.d.ts +0 -0
  31. /package/dist/{src → types/src}/UtilsGMMenu.d.ts +0 -0
  32. /package/dist/{src → types/src}/VueObject.d.ts +0 -0
  33. /package/dist/{src → types/src}/ajaxHooker/ajaxHooker.d.ts +0 -0
  34. /package/dist/{src → types/src}/indexedDB.d.ts +0 -0
package/dist/index.umd.js CHANGED
@@ -276,7 +276,7 @@
276
276
  if (typeof cookieName !== "string") {
277
277
  throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
278
278
  }
279
- let cookies = document.cookie.split(";");
279
+ let cookies = UtilsCore.document.cookie.split(";");
280
280
  let findValue = void 0;
281
281
  for (const cookieItem of cookies) {
282
282
  let item = cookieItem.trim();
@@ -286,7 +286,7 @@
286
286
  let itemValue = decodeURIComponent(itemSplit.join(""));
287
287
  if (itemName === cookieName) {
288
288
  findValue = {
289
- domain: globalThis.location.hostname,
289
+ domain: UtilsCore.globalThis.location.hostname,
290
290
  expirationDate: null,
291
291
  hostOnly: true,
292
292
  httpOnly: false,
@@ -316,13 +316,13 @@
316
316
  let resultData = [];
317
317
  try {
318
318
  let details = {
319
- url: globalThis.location.href,
320
- domain: globalThis.location.hostname,
319
+ url: UtilsCore.globalThis.location.href,
320
+ domain: UtilsCore.globalThis.location.hostname,
321
321
  name: "",
322
322
  path: "/",
323
323
  };
324
324
  details = utils.assign(details, paramDetails);
325
- let cookies = document.cookie.split(";");
325
+ let cookies = UtilsCore.document.cookie.split(";");
326
326
  cookies.forEach((item) => {
327
327
  item = item.trim();
328
328
  let itemSplit = item.split("=");
@@ -334,7 +334,7 @@
334
334
  : new RegExp("^" + details.name, "g");
335
335
  if (itemName.match(nameRegexp)) {
336
336
  resultData.push({
337
- domain: globalThis.location.hostname,
337
+ domain: UtilsCore.globalThis.location.hostname,
338
338
  expirationDate: null,
339
339
  hostOnly: true,
340
340
  httpOnly: false,
@@ -367,13 +367,13 @@
367
367
  }
368
368
  let resultData = [];
369
369
  let details = {
370
- url: globalThis.location.href,
371
- domain: globalThis.location.hostname,
370
+ url: UtilsCore.globalThis.location.href,
371
+ domain: UtilsCore.globalThis.location.hostname,
372
372
  name: "",
373
373
  path: "/",
374
374
  };
375
375
  details = utils.assign(details, paramDetails);
376
- let cookies = document.cookie.split(";");
376
+ let cookies = UtilsCore.document.cookie.split(";");
377
377
  cookies.forEach((item) => {
378
378
  item = item.trim();
379
379
  let itemSplit = item.split("=");
@@ -385,7 +385,7 @@
385
385
  : new RegExp("^" + details.name, "g");
386
386
  if (itemName.match(nameRegexp)) {
387
387
  resultData.push({
388
- domain: globalThis.location.hostname,
388
+ domain: UtilsCore.globalThis.location.hostname,
389
389
  expirationDate: null,
390
390
  hostOnly: true,
391
391
  httpOnly: false,
@@ -408,10 +408,10 @@
408
408
  set(paramDetails, callback = (error) => { }) {
409
409
  try {
410
410
  let details = {
411
- url: window.location.href,
411
+ url: UtilsCore.window.location.href,
412
412
  name: "",
413
413
  value: "",
414
- domain: window.location.hostname,
414
+ domain: UtilsCore.window.location.hostname,
415
415
  path: "/",
416
416
  secure: true,
417
417
  httpOnly: false,
@@ -430,7 +430,7 @@
430
430
  ";expires=" +
431
431
  new Date(life).toGMTString() +
432
432
  "; path=/";
433
- document.cookie = cookieStr;
433
+ UtilsCore.document.cookie = cookieStr;
434
434
  callback();
435
435
  }
436
436
  catch (error) {
@@ -445,14 +445,14 @@
445
445
  delete(paramDetails, callback = (error) => { }) {
446
446
  try {
447
447
  let details = {
448
- url: window.location.href,
448
+ url: UtilsCore.window.location.href,
449
449
  name: "",
450
450
  // @ts-ignore
451
451
  firstPartyDomain: "",
452
452
  };
453
453
  details = utils.assign(details, paramDetails);
454
454
  let cookieStr = details.name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
455
- document.cookie = cookieStr;
455
+ UtilsCore.document.cookie = cookieStr;
456
456
  callback();
457
457
  }
458
458
  catch (error) {
@@ -1221,7 +1221,7 @@
1221
1221
  }
1222
1222
  /* 不刷新网页就刷新菜单 */
1223
1223
  if (menuOption.autoReload) {
1224
- window.location.reload();
1224
+ UtilsCore.window.location.reload();
1225
1225
  }
1226
1226
  else {
1227
1227
  that.context.update();
@@ -1913,13 +1913,14 @@
1913
1913
  }
1914
1914
  catch (error) {
1915
1915
  if (details.url.startsWith("//")) {
1916
- details.url = globalThis.location.protocol + details.url;
1916
+ details.url = UtilsCore.globalThis.location.protocol + details.url;
1917
1917
  }
1918
1918
  else if (details.url.startsWith("/")) {
1919
- details.url = globalThis.location.origin + details.url;
1919
+ details.url = UtilsCore.globalThis.location.origin + details.url;
1920
1920
  }
1921
1921
  else {
1922
- details.url = globalThis.location.origin + "/" + details.url;
1922
+ details.url =
1923
+ UtilsCore.globalThis.location.origin + "/" + details.url;
1923
1924
  }
1924
1925
  }
1925
1926
  return details;
@@ -2544,10 +2545,10 @@
2544
2545
  /* websql的版本号,由于ios的问题,版本号的写法不一样 */
2545
2546
  #slqVersion = "1";
2546
2547
  /* 监听IndexDB */
2547
- #indexedDB = window.indexedDB ||
2548
- window.mozIndexedDB ||
2549
- window.webkitIndexedDB ||
2550
- window.msIndexedDB;
2548
+ #indexedDB = UtilsCore.window.indexedDB ||
2549
+ UtilsCore.window.mozIndexedDB ||
2550
+ UtilsCore.window.webkitIndexedDB ||
2551
+ UtilsCore.window.msIndexedDB;
2551
2552
  /* 缓存数据库,避免同一个页面重复创建和销毁 */
2552
2553
  #db = {};
2553
2554
  #store = null;
@@ -2971,7 +2972,7 @@
2971
2972
  * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
2972
2973
  * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
2973
2974
  */
2974
- constructor(_GM_info_, console = globalThis.console) {
2975
+ constructor(_GM_info_, console = UtilsCore.window.console) {
2975
2976
  if (typeof _GM_info_ === "string") {
2976
2977
  this.tag = _GM_info_;
2977
2978
  }
@@ -3232,12 +3233,14 @@
3232
3233
  /* 元素高度 */
3233
3234
  this.#height = this.#config.canvasNode.height;
3234
3235
  /* 清除锯齿 */
3235
- if (window.devicePixelRatio) {
3236
+ if (UtilsCore.window.devicePixelRatio) {
3236
3237
  this.#config.canvasNode.style.width = this.#width + "px";
3237
3238
  this.#config.canvasNode.style.height = this.#height + "px";
3238
- this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
3239
- this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
3240
- this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
3239
+ this.#config.canvasNode.height =
3240
+ this.#height * UtilsCore.window.devicePixelRatio;
3241
+ this.#config.canvasNode.width =
3242
+ this.#width * UtilsCore.window.devicePixelRatio;
3243
+ this.#ctx.scale(UtilsCore.window.devicePixelRatio, UtilsCore.window.devicePixelRatio);
3241
3244
  }
3242
3245
  /* 设置线宽 */
3243
3246
  this.#ctx.lineWidth = this.#config.lineWidth;
@@ -3516,24 +3519,24 @@
3516
3519
  if (typeof cssText !== "string") {
3517
3520
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
3518
3521
  }
3519
- let cssNode = document.createElement("style");
3522
+ let cssNode = UtilsCore.document.createElement("style");
3520
3523
  cssNode.setAttribute("type", "text/css");
3521
3524
  cssNode.innerHTML = cssText;
3522
- if (document.head) {
3525
+ if (UtilsCore.document.head) {
3523
3526
  /* 插入head最后 */
3524
- document.head.appendChild(cssNode);
3527
+ UtilsCore.document.head.appendChild(cssNode);
3525
3528
  }
3526
- else if (document.body) {
3529
+ else if (UtilsCore.document.body) {
3527
3530
  /* 插入body后 */
3528
- document.body.appendChild(cssNode);
3531
+ UtilsCore.document.body.appendChild(cssNode);
3529
3532
  }
3530
- else if (document.documentElement.childNodes.length === 0) {
3533
+ else if (UtilsCore.document.documentElement.childNodes.length === 0) {
3531
3534
  /* 插入#html第一个元素后 */
3532
- document.documentElement.appendChild(cssNode);
3535
+ UtilsCore.document.documentElement.appendChild(cssNode);
3533
3536
  }
3534
3537
  else {
3535
3538
  /* 插入head前面 */
3536
- document.documentElement.insertBefore(cssNode, document.documentElement.childNodes[0]);
3539
+ UtilsCore.document.documentElement.insertBefore(cssNode, UtilsCore.document.documentElement.childNodes[0]);
3537
3540
  }
3538
3541
  return cssNode;
3539
3542
  }
@@ -3664,7 +3667,8 @@
3664
3667
  let elementPosXRight = Number(element.getBoundingClientRect().right); /* 要检测的元素的相对屏幕的横坐标最右边 */
3665
3668
  let elementPosYTop = Number(element.getBoundingClientRect().top); /* 要检测的元素的相对屏幕的纵坐标最上边 */
3666
3669
  let elementPosYBottom = Number(element.getBoundingClientRect().bottom); /* 要检测的元素的相对屏幕的纵坐标最下边 */
3667
- let clickNodeHTML = window.event.target.innerHTML;
3670
+ let clickNodeHTML = UtilsCore.window.event.target
3671
+ .innerHTML;
3668
3672
  if (mouseClickPosX >= elementPosXLeft &&
3669
3673
  mouseClickPosX <= elementPosXRight &&
3670
3674
  mouseClickPosY >= elementPosYTop &&
@@ -3792,18 +3796,18 @@
3792
3796
  }
3793
3797
  if (isIFrame) {
3794
3798
  /* 使用iframe */
3795
- const iframeElement = document.createElement("iframe");
3799
+ const iframeElement = UtilsCore.document.createElement("iframe");
3796
3800
  iframeElement.style.display = "none";
3797
3801
  iframeElement.src = base64Data;
3798
- document.body.appendChild(iframeElement);
3802
+ UtilsCore.document.body.appendChild(iframeElement);
3799
3803
  setTimeout(() => {
3800
3804
  iframeElement.contentWindow.document.execCommand("SaveAs", true, fileName);
3801
- document.body.removeChild(iframeElement);
3805
+ UtilsCore.document.body.removeChild(iframeElement);
3802
3806
  }, 100);
3803
3807
  }
3804
3808
  else {
3805
3809
  /* 使用A标签 */
3806
- const linkElement = document.createElement("a");
3810
+ const linkElement = UtilsCore.document.createElement("a");
3807
3811
  linkElement.setAttribute("target", "_blank");
3808
3812
  linkElement.download = fileName;
3809
3813
  linkElement.href = base64Data;
@@ -3817,7 +3821,7 @@
3817
3821
  /* CODE FOR BROWSERS THAT SUPPORT window.find */
3818
3822
  let windowFind = UtilsCore.self.find;
3819
3823
  strFound = windowFind(str, caseSensitive, true, true, false);
3820
- if (strFound && self.getSelection && !self.getSelection().anchorNode) {
3824
+ if (strFound && UtilsCore.self.getSelection && !UtilsCore.self.getSelection().anchorNode) {
3821
3825
  strFound = windowFind(str, caseSensitive, true, true, false);
3822
3826
  }
3823
3827
  if (!strFound) {
@@ -4212,8 +4216,8 @@
4212
4216
  let maxZIndexCompare = 2 * Math.pow(10, 9);
4213
4217
  // 当前页面最大的z-index
4214
4218
  let zIndex = 0;
4215
- document.querySelectorAll("*").forEach((element, index) => {
4216
- let nodeStyle = window.getComputedStyle(element);
4219
+ UtilsCore.document.querySelectorAll("*").forEach(($ele, index) => {
4220
+ let nodeStyle = UtilsCore.window.getComputedStyle($ele);
4217
4221
  /* 不对position为static和display为none的元素进行获取它们的z-index */
4218
4222
  if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
4219
4223
  let nodeZIndex = parseInt(nodeStyle.zIndex);
@@ -4427,7 +4431,7 @@
4427
4431
  if (url.trim() === "") {
4428
4432
  throw new TypeError("url不能为空字符串或纯空格");
4429
4433
  }
4430
- return `thunder://${globalThis.btoa("AA" + url + "ZZ")}`;
4434
+ return `thunder://${UtilsCore.globalThis.btoa("AA" + url + "ZZ")}`;
4431
4435
  }
4432
4436
  /**
4433
4437
  * 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
@@ -4642,9 +4646,11 @@
4642
4646
  return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
4643
4647
  }
4644
4648
  isNearBottom(nearValue = 50) {
4645
- var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
4646
- var windowHeight = window.innerHeight || document.documentElement.clientHeight;
4647
- var documentHeight = document.documentElement.scrollHeight;
4649
+ var scrollTop = UtilsCore.window.pageYOffset ||
4650
+ UtilsCore.document.documentElement.scrollTop;
4651
+ var windowHeight = UtilsCore.window.innerHeight ||
4652
+ UtilsCore.document.documentElement.clientHeight;
4653
+ var documentHeight = UtilsCore.document.documentElement.scrollHeight;
4648
4654
  return scrollTop + windowHeight >= documentHeight - nearValue;
4649
4655
  }
4650
4656
  isDOM(target) {
@@ -4887,7 +4893,7 @@
4887
4893
  return result;
4888
4894
  }
4889
4895
  isThemeDark() {
4890
- return globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
4896
+ return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
4891
4897
  }
4892
4898
  isVisible(element, inView = false) {
4893
4899
  let needCheckDomList = [];
@@ -4900,15 +4906,17 @@
4900
4906
  }
4901
4907
  let result = true;
4902
4908
  for (const domItem of needCheckDomList) {
4903
- let domDisplay = window.getComputedStyle(domItem);
4909
+ let domDisplay = UtilsCore.window.getComputedStyle(domItem);
4904
4910
  if (domDisplay.display === "none") {
4905
4911
  result = false;
4906
4912
  }
4907
4913
  else {
4908
4914
  let domClientRect = domItem.getBoundingClientRect();
4909
4915
  if (inView) {
4910
- let viewportWidth = window.innerWidth || document.documentElement.clientWidth;
4911
- let viewportHeight = window.innerHeight || document.documentElement.clientHeight;
4916
+ let viewportWidth = UtilsCore.window.innerWidth ||
4917
+ UtilsCore.document.documentElement.clientWidth;
4918
+ let viewportHeight = UtilsCore.window.innerHeight ||
4919
+ UtilsCore.document.documentElement.clientHeight;
4912
4920
  result = !(domClientRect.right < 0 ||
4913
4921
  domClientRect.left > viewportWidth ||
4914
4922
  domClientRect.bottom < 0 ||
@@ -5131,7 +5139,7 @@
5131
5139
  immediate: false,
5132
5140
  };
5133
5141
  observer_config = UtilsContext.assign(default_obverser_config, observer_config);
5134
- let windowMutationObserver = window.MutationObserver ||
5142
+ let windowMutationObserver = UtilsCore.window.MutationObserver ||
5135
5143
  UtilsCore.window.webkitMutationObserver ||
5136
5144
  UtilsCore.window.MozMutationObserver;
5137
5145
  let mutationObserver = new windowMutationObserver(function (mutations, observer) {
@@ -5450,7 +5458,7 @@
5450
5458
  return isNegative ? -reversedNum : reversedNum;
5451
5459
  }
5452
5460
  selectElementText(element, childTextNode, startIndex, endIndex) {
5453
- let range = document.createRange();
5461
+ let range = UtilsCore.document.createRange();
5454
5462
  range.selectNodeContents(element);
5455
5463
  if (childTextNode) {
5456
5464
  if (childTextNode.nodeType !== Node.TEXT_NODE) {
@@ -5461,7 +5469,7 @@
5461
5469
  range.setEnd(childTextNode, endIndex);
5462
5470
  }
5463
5471
  }
5464
- let selection = globalThis.getSelection();
5472
+ let selection = UtilsCore.globalThis.getSelection();
5465
5473
  if (selection) {
5466
5474
  selection.removeAllRanges();
5467
5475
  selection.addRange(range);
@@ -5542,15 +5550,15 @@
5542
5550
  */
5543
5551
  copyTextByTextArea() {
5544
5552
  try {
5545
- let copyElement = document.createElement("textarea");
5553
+ let copyElement = UtilsCore.document.createElement("textarea");
5546
5554
  copyElement.value = this.#copyData;
5547
5555
  copyElement.setAttribute("type", "text");
5548
5556
  copyElement.setAttribute("style", "opacity:0;position:absolute;");
5549
5557
  copyElement.setAttribute("readonly", "readonly");
5550
- document.body.appendChild(copyElement);
5558
+ UtilsCore.document.body.appendChild(copyElement);
5551
5559
  copyElement.select();
5552
- document.execCommand("copy");
5553
- document.body.removeChild(copyElement);
5560
+ UtilsCore.document.execCommand("copy");
5561
+ UtilsCore.document.body.removeChild(copyElement);
5554
5562
  return true;
5555
5563
  }
5556
5564
  catch (error) {
@@ -5627,11 +5635,11 @@
5627
5635
  }
5628
5636
  return new Promise((resolve) => {
5629
5637
  const utilsClipboard = new UtilsClipboard(resolve, data, textType);
5630
- if (document.hasFocus()) {
5638
+ if (UtilsCore.document.hasFocus()) {
5631
5639
  utilsClipboard.init();
5632
5640
  }
5633
5641
  else {
5634
- window.addEventListener("focus", () => {
5642
+ UtilsCore.window.addEventListener("focus", () => {
5635
5643
  utilsClipboard.init();
5636
5644
  }, { once: true });
5637
5645
  }
@@ -5664,12 +5672,12 @@
5664
5672
  dragSlider(selector, offsetX = UtilsCore.window.innerWidth) {
5665
5673
  function initMouseEvent(eventName, offSetX, offSetY) {
5666
5674
  let win = unsafeWindow || window;
5667
- let mouseEvent = document.createEvent("MouseEvents");
5675
+ let mouseEvent = UtilsCore.document.createEvent("MouseEvents");
5668
5676
  mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
5669
5677
  return mouseEvent;
5670
5678
  }
5671
5679
  let sliderElement = typeof selector === "string"
5672
- ? document.querySelector(selector)
5680
+ ? UtilsCore.document.querySelector(selector)
5673
5681
  : selector;
5674
5682
  if (!(sliderElement instanceof Node) ||
5675
5683
  !(sliderElement instanceof Element)) {
@@ -5703,7 +5711,7 @@
5703
5711
  console.error(err);
5704
5712
  }
5705
5713
  }
5706
- exitFullScreen(element = document.documentElement) {
5714
+ exitFullScreen(element = UtilsCore.document.documentElement) {
5707
5715
  if (UtilsCore.document.exitFullscreen) {
5708
5716
  return UtilsCore.document.exitFullscreen();
5709
5717
  }