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