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