WhiteSevsUtils

一个好用的工具类

当前为 2024-11-06 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/455186/1478725/WhiteSevsUtils.js

  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Utils = factory());
  5. })(this, (function () { 'use strict';
  6.  
  7. class ColorConversion {
  8. /**
  9. * 判断是否是16进制颜色
  10. * @param str
  11. */
  12. isHex(str) {
  13. if (typeof str !== "string") {
  14. return false;
  15. }
  16. if (!str.match(/^(\#|)[0-9a-fA-F]{6}$/)) {
  17. return false;
  18. }
  19. return true;
  20. }
  21. /**
  22. * 16进制颜色转rgba
  23. *
  24. * #ff0000 转 rgba(123,123,123, 0.4)
  25. * @param hex
  26. * @param opacity
  27. */
  28. hexToRgba(hex, opacity) {
  29. if (!this.isHex(hex)) {
  30. // @ts-ignore
  31. throw new TypeError("输入错误的hex", hex);
  32. }
  33. return hex && hex.replace(/\s+/g, "").length === 7
  34. ? "rgba(" +
  35. parseInt("0x" + hex.slice(1, 3)) +
  36. "," +
  37. parseInt("0x" + hex.slice(3, 5)) +
  38. "," +
  39. parseInt("0x" + hex.slice(5, 7)) +
  40. "," +
  41. opacity +
  42. ")"
  43. : "";
  44. }
  45. /**
  46. * hex转rgb
  47. * @param str
  48. * @returns
  49. */
  50. hexToRgb(str) {
  51. if (!this.isHex(str)) {
  52. // @ts-ignore
  53. throw new TypeError("输入错误的hex", str);
  54. }
  55. /* replace替换查找的到的字符串 */
  56. str = str.replace("#", "");
  57. /* match得到查询数组 */
  58. let hxs = str.match(/../g);
  59. for (let index = 0; index < 3; index++) {
  60. // @ts-ignore
  61. hxs[index] = parseInt(hxs[index], 16);
  62. }
  63. return hxs;
  64. }
  65. /**
  66. * rgb转hex
  67. * @param redValue
  68. * @param greenValue
  69. * @param blueValue
  70. * @returns
  71. */
  72. rgbToHex(redValue, greenValue, blueValue) {
  73. /* 验证输入的rgb值是否合法 */
  74. let validPattern = /^\d{1,3}$/;
  75. if (!validPattern.test(redValue.toString()) ||
  76. !validPattern.test(greenValue.toString()) ||
  77. !validPattern.test(blueValue.toString()))
  78. throw new TypeError("输入错误的rgb颜色值");
  79. let hexs = [
  80. redValue.toString(16),
  81. greenValue.toString(16),
  82. blueValue.toString(16),
  83. ];
  84. for (let index = 0; index < 3; index++)
  85. if (hexs[index].length == 1)
  86. hexs[index] = "0" + hexs[index];
  87. return "#" + hexs.join("");
  88. }
  89. /**
  90. * 获取颜色变暗或亮
  91. * @param color 颜色
  92. * @param level 0~1.0
  93. * @returns
  94. */
  95. getDarkColor(color, level) {
  96. if (!this.isHex(color)) {
  97. // @ts-ignore
  98. throw new TypeError("输入错误的hex", color);
  99. }
  100. let rgbc = this.hexToRgb(color);
  101. for (let index = 0; index < 3; index++) {
  102. // @ts-ignore
  103. rgbc[index] = Math.floor(rgbc[index] * (1 - level));
  104. }
  105. // @ts-ignore
  106. return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
  107. }
  108. /**
  109. * 获取颜色变亮
  110. * @param color 颜色
  111. * @param level 0~1.0
  112. * @returns
  113. */
  114. getLightColor(color, level) {
  115. if (!this.isHex(color)) {
  116. // @ts-ignore
  117. throw new TypeError("输入错误的hex", color);
  118. }
  119. let rgbc = this.hexToRgb(color);
  120. for (let index = 0; index < 3; index++) {
  121. // @ts-ignore
  122. rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
  123. }
  124. // @ts-ignore
  125. return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
  126. }
  127. }
  128.  
  129. class GBKEncoder {
  130. #data = [];
  131. #U2Ghash = {};
  132. #G2Uhash = {};
  133. constructor() {
  134. let dataText = this.handleText("4e:020405060f12171f20212326292e2f313335373c40414244464a5155575a5b6263646567686a6b6c6d6e6f727475767778797a7b7c7d7f808182838485878a#909697999c9d9ea3aaafb0b1b4b6b7b8b9bcbdbec8cccfd0d2dadbdce0e2e6e7e9edeeeff1f4f8f9fafcfe,4f:00020304050607080b0c12131415161c1d212328292c2d2e31333537393b3e3f40414244454748494a4b4c525456616266686a6b6d6e7172757778797a7d8081828586878a8c8e909293959698999a9c9e9fa1a2a4abadb0b1b2b3b4b6b7b8b9babbbcbdbec0c1c2c6c7c8c9cbcccdd2d3d4d5d6d9dbe0e2e4e5e7ebecf0f2f4f5f6f7f9fbfcfdff,50:000102030405060708090a#0b0e1011131516171b1d1e20222324272b2f303132333435363738393b3d3f404142444546494a4b4d5051525354565758595b5d5e5f6061626364666768696a6b6d6e6f70717273747578797a7c7d818283848687898a8b8c8e8f909192939495969798999a9b9c9d9e9fa0a1a2a4a6aaabadaeafb0b1b3b4b5b6b7b8b9bcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdced0d1d2d3d4d5d7d8d9dbdcdddedfe0e1e2e3e4e5e8e9eaebeff0f1f2f4f6f7f8f9fafcfdfeff,51:00010203040508#090a0c0d0e0f1011131415161718191a1b1c1d1e1f2022232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e42474a4c4e4f5052535758595b5d5e5f606163646667696a6f727a7e7f838486878a8b8e8f90919394989a9d9e9fa1a3a6a7a8a9aaadaeb4b8b9babebfc1c2c3c5c8cacdced0d2d3d4d5d6d7d8d9dadcdedfe2e3e5e6e7e8e9eaeceef1f2f4f7fe,52:0405090b0c0f101314151c1e1f2122232526272a2c2f313234353c3e4445464748494b4e4f5253555758#595a5b5d5f6062636466686b6c6d6e7071737475767778797a7b7c7e808384858687898a8b8c8d8e8f91929495969798999a9ca4a5a6a7aeafb0b4b5b6b7b8b9babbbcbdc0c1c2c4c5c6c8cacccdcecfd1d3d4d5d7d9dadbdcdddee0e1e2e3e5e6e7e8e9eaebecedeeeff1f2f3f4f5f6f7f8fbfcfd,53:0102030407090a0b0c0e11121314181b1c1e1f2224252728292b2c2d2f3031323334353637383c3d404244464b4c4d505458595b5d65686a6c6d7276797b7c7d7e80818387888a8e8f#90919293949697999b9c9ea0a1a4a7aaabacadafb0b1b2b3b4b5b7b8b9babcbdbec0c3c4c5c6c7cecfd0d2d3d5dadcdddee1e2e7f4fafeff,54:000205070b1418191a1c2224252a303336373a3d3f4142444547494c4d4e4f515a5d5e5f6061636567696a6b6c6d6e6f7074797a7e7f8183858788898a8d919397989c9e9fa0a1a2a5aeb0b2b5b6b7b9babcbec3c5cacbd6d8dbe0e1e2e3e4ebeceff0f1f4f5f6f7f8f9fbfe,55:0002030405080a0b0c0d0e121315161718191a1c1d1e1f212526#28292b2d3234353638393a3b3d40424547484b4c4d4e4f515253545758595a5b5d5e5f60626368696b6f7071727374797a7d7f85868c8d8e9092939596979a9b9ea0a1a2a3a4a5a6a8a9aaabacadaeafb0b2b4b6b8babcbfc0c1c2c3c6c7c8cacbcecfd0d5d7d8d9dadbdee0e2e7e9edeef0f1f4f6f8f9fafbfcff,56:0203040506070a0b0d1011121314151617191a1c1d202122252628292a2b2e2f30333537383a3c3d3e404142434445464748494a4b4f5051525355565a5b5d5e5f6061#636566676d6e6f70727374757778797a7d7e7f80818283848788898a8b8c8d9091929495969798999a9b9c9d9e9fa0a1a2a4a5a6a7a8a9aaabacadaeb0b1b2b3b4b5b6b8b9babbbdbebfc0c1c2c3c4c5c6c7c8c9cbcccdcecfd0d1d2d3d5d6d8d9dce3e5e6e7e8e9eaeceeeff2f3f6f7f8fbfc,57:00010205070b0c0d0e0f101112131415161718191a1b1d1e202122242526272b313234353637383c3d3f414344454648494b52535455565859626365676c6e707172747578797a7d7e7f80#818788898a8d8e8f90919495969798999a9c9d9e9fa5a8aaacafb0b1b3b5b6b7b9babbbcbdbebfc0c1c4c5c6c7c8c9cacccdd0d1d3d6d7dbdcdee1e2e3e5e6e7e8e9eaebeceef0f1f2f3f5f6f7fbfcfeff,58:0103040508090a0c0e0f101213141617181a1b1c1d1f222325262728292b2c2d2e2f31323334363738393a3b3c3d3e3f4041424345464748494a4b4e4f505253555657595a5b5c5d5f6061626364666768696a6d6e6f707172737475767778797a7b7c7d7f82848687888a8b8c#8d8e8f909194959697989b9c9da0a1a2a3a4a5a6a7aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbdbebfc0c2c3c4c6c7c8c9cacbcccdcecfd0d2d3d4d6d7d8d9dadbdcdddedfe0e1e2e3e5e6e7e8e9eaedeff1f2f4f5f7f8fafbfcfdfeff,59:000103050608090a0b0c0e1011121317181b1d1e2021222326282c30323335363b3d3e3f404345464a4c4d505253595b5c5d5e5f616364666768696a6b6c6d6e6f70717275777a7b7c7e7f8085898b8c8e8f90919495989a9b9c9d9fa0a1a2a6#a7acadb0b1b3b4b5b6b7b8babcbdbfc0c1c2c3c4c5c7c8c9cccdcecfd5d6d9dbdedfe0e1e2e4e6e7e9eaebedeeeff0f1f2f3f4f5f6f7f8fafcfdfe,5a:00020a0b0d0e0f101214151617191a1b1d1e2122242627282a2b2c2d2e2f3033353738393a3b3d3e3f414243444547484b4c4d4e4f5051525354565758595b5c5d5e5f60616364656668696b6c6d6e6f7071727378797b7c7d7e808182838485868788898a8b8c8d8e8f9091939495969798999c9d9e9fa0a1a2a3a4a5a6a7a8a9abac#adaeafb0b1b4b6b7b9babbbcbdbfc0c3c4c5c6c7c8cacbcdcecfd0d1d3d5d7d9dadbdddedfe2e4e5e7e8eaecedeeeff0f2f3f4f5f6f7f8f9fafbfcfdfeff,5b:0001020304050607080a0b0c0d0e0f10111213141518191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303133353638393a3b3c3d3e3f4142434445464748494a4b4c4d4e4f52565e606167686b6d6e6f7274767778797b7c7e7f82868a8d8e90919294969fa7a8a9acadaeafb1b2b7babbbcc0c1c3c8c9cacbcdcecf#d1d4d5d6d7d8d9dadbdce0e2e3e6e7e9eaebecedeff1f2f3f4f5f6f7fdfe,5c:0002030507080b0c0d0e10121317191b1e1f2021232628292a2b2d2e2f303233353637434446474c4d5253545657585a5b5c5d5f62646768696a6b6c6d70727374757677787b7c7d7e808384858687898a8b8e8f9293959d9e9fa0a1a4a5a6a7a8aaaeafb0b2b4b6b9babbbcbec0c2c3c5c6c7c8c9cacccdcecfd0d1d3d4d5d6d7d8dadbdcdddedfe0e2e3e7e9ebeceeeff1f2f3f4f5f6f7f8f9fafcfdfeff,5d:00#01040508090a0b0c0d0f10111213151718191a1c1d1f2021222325282a2b2c2f3031323335363738393a3b3c3f4041424344454648494d4e4f5051525354555657595a5c5e5f6061626364656667686a6d6e7071727375767778797a7b7c7d7e7f8081838485868788898a8b8c8d8e8f9091929394959697989a9b9c9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b8b9babbbcbdbebfc0c1c2c3c4c6c7c8c9cacbcccecfd0d1d2d3d4d5d6d7d8d9dadcdfe0e3e4eaeced#f0f5f6f8f9fafbfcff,5e:000407090a0b0d0e1213171e1f20212223242528292a2b2c2f303233343536393a3e3f404143464748494a4b4d4e4f50515253565758595a5c5d5f60636465666768696a6b6c6d6e6f70717577797e8182838588898c8d8e92989b9da1a2a3a4a8a9aaabacaeafb0b1b2b4babbbcbdbfc0c1c2c3c4c5c6c7c8cbcccdcecfd0d4d5d7d8d9dadcdddedfe0e1e2e3e4e5e6e7e9ebecedeeeff0f1f2f3f5f8f9fbfcfd,5f:050607090c0d0e10121416191a1c1d1e21222324#282b2c2e30323334353637383b3d3e3f4142434445464748494a4b4c4d4e4f5154595a5b5c5e5f60636567686b6e6f72747576787a7d7e7f83868d8e8f919394969a9b9d9e9fa0a2a3a4a5a6a7a9abacafb0b1b2b3b4b6b8b9babbbebfc0c1c2c7c8cacbced3d4d5dadbdcdedfe2e3e5e6e8e9eceff0f2f3f4f6f7f9fafc,60:0708090b0c10111317181a1e1f2223242c2d2e3031323334363738393a3d3e404445464748494a4c4e4f5153545657585b5c5e5f606165666e71727475777e80#8182858687888a8b8e8f909193959798999c9ea1a2a4a5a7a9aaaeb0b3b5b6b7b9babdbebfc0c1c2c3c4c7c8c9cccdcecfd0d2d3d4d6d7d9dbdee1e2e3e4e5eaf1f2f5f7f8fbfcfdfeff,61:02030405070a0b0c1011121314161718191b1c1d1e21222528292a2c2d2e2f303132333435363738393a3b3c3d3e4041424344454647494b4d4f50525354565758595a5b5c5e5f606163646566696a6b6c6d6e6f717273747678797a7b7c7d7e7f808182838485868788898a8c8d8f9091929395#969798999a9b9c9e9fa0a1a2a3a4a5a6aaabadaeafb0b1b2b3b4b5b6b8b9babbbcbdbfc0c1c3c4c5c6c7c9cccdcecfd0d3d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e7e8e9eaebecedeeeff0f1f2f3f4f6f7f8f9fafbfcfdfe,62:00010203040507091314191c1d1e2023262728292b2d2f303132353638393a3b3c424445464a4f50555657595a5c5d5e5f6061626465687172747577787a7b7d818283858687888b8c8d8e8f9094999c9d9ea3a6a7a9aaadaeafb0b2b3b4b6b7b8babec0c1#c3cbcfd1d5dddee0e1e4eaebf0f2f5f8f9fafb,63:00030405060a0b0c0d0f10121314151718191c2627292c2d2e30313334353637383b3c3e3f40414447484a51525354565758595a5b5c5d60646566686a6b6c6f707273747578797c7d7e7f81838485868b8d9193949597999a9b9c9d9e9fa1a4a6abafb1b2b5b6b9bbbdbfc0c1c2c3c5c7c8cacbccd1d3d4d5d7d8d9dadbdcdddfe2e4e5e6e7e8ebeceeeff0f1f3f5f7f9fafbfcfe,64:0304060708090a0d0e111215161718191a1d1f222324#252728292b2e2f3031323335363738393b3c3e404243494b4c4d4e4f505153555657595a5b5c5d5f60616263646566686a6b6c6e6f70717273747576777b7c7d7e7f8081838688898a8b8c8d8e8f90939497989a9b9c9d9fa0a1a2a3a5a6a7a8aaabafb1b2b3b4b6b9bbbdbebfc1c3c4c6c7c8c9cacbcccfd1d3d4d5d6d9dadbdcdddfe0e1e3e5e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,65:01020304050607080a0b0c0d0e0f10111314151617191a1b1c1d1e1f2021#222324262728292a2c2d30313233373a3c3d404142434446474a4b4d4e5052535457585a5c5f606164656768696a6d6e6f7173757678797a7b7c7d7e7f8081828384858688898a8d8e8f92949596989a9d9ea0a2a3a6a8aaacaeb1b2b3b4b5b6b7b8babbbebfc0c2c7c8c9cacdd0d1d3d4d5d8d9dadbdcdddedfe1e3e4eaebf2f3f4f5f8f9fbfcfdfeff,66:0104050708090b0d1011121617181a1b1c1e2122232426292a2b2c2e3032333738393a3b3d3f40424445464748494a4d4e505158#595b5c5d5e6062636567696a6b6c6d7172737578797b7c7d7f808183858688898a8b8d8e8f909293949598999a9b9c9e9fa0a1a2a3a4a5a6a9aaabacadafb0b1b2b3b5b6b7b8babbbcbdbfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8dadedfe0e1e2e3e4e5e7e8eaebecedeeeff1f5f6f8fafbfd,67:010203040506070c0e0f1112131618191a1c1e20212223242527292e303233363738393b3c3e3f414445474a4b4d5254555758595a5b5d62636466676b6c6e717476#78797a7b7d8082838586888a8c8d8e8f9192939496999b9fa0a1a4a6a9acaeb1b2b4b9babbbcbdbebfc0c2c5c6c7c8c9cacbcccdced5d6d7dbdfe1e3e4e6e7e8eaebedeef2f5f6f7f8f9fafbfcfe,68:01020304060d1012141518191a1b1c1e1f20222324252627282b2c2d2e2f30313435363a3b3f474b4d4f52565758595a5b5c5d5e5f6a6c6d6e6f707172737578797a7b7c7d7e7f8082848788898a8b8c8d8e90919294959698999a9b9c9d9e9fa0a1a3a4a5a9aaabacaeb1b2b4b6b7b8#b9babbbcbdbebfc1c3c4c5c6c7c8cacccecfd0d1d3d4d6d7d9dbdcdddedfe1e2e4e5e6e7e8e9eaebecedeff2f3f4f6f7f8fbfdfeff,69:00020304060708090a0c0f11131415161718191a1b1c1d1e21222325262728292a2b2c2e2f313233353637383a3b3c3e4041434445464748494a4b4c4d4e4f50515253555658595b5c5f616264656768696a6c6d6f7072737475767a7b7d7e7f8183858a8b8c8e8f909192939697999a9d9e9fa0a1a2a3a4a5a6a9aaacaeafb0b2b3b5b6b8b9babcbd#bebfc0c2c3c4c5c6c7c8c9cbcdcfd1d2d3d5d6d7d8d9dadcdddee1e2e3e4e5e6e7e8e9eaebeceeeff0f1f3f4f5f6f7f8f9fafbfcfe,6a:000102030405060708090b0c0d0e0f10111213141516191a1b1c1d1e20222324252627292b2c2d2e30323334363738393a3b3c3f40414243454648494a4b4c4d4e4f515253545556575a5c5d5e5f60626364666768696a6b6c6d6e6f70727374757677787a7b7d7e7f81828385868788898a8b8c8d8f929394959698999a9b9c9d9e9fa1a2a3a4a5a6#a7a8aaadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,6b:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f252628292a2b2c2d2e2f303133343536383b3c3d3f4041424445484a4b4d4e4f5051525354555657585a5b5c5d5e5f606168696b6c6d6e6f7071727374757677787a7d7e7f808588#8c8e8f909194959798999c9d9e9fa0a2a3a4a5a6a7a8a9abacadaeafb0b1b2b6b8b9babbbcbdbec0c3c4c6c7c8c9caccced0d1d8dadcdddedfe0e2e3e4e5e6e7e8e9ecedeef0f1f2f4f6f7f8fafbfcfeff,6c:000102030408090a0b0c0e12171c1d1e2023252b2c2d31333637393a3b3c3e3f434445484b4c4d4e4f5152535658595a62636566676b6c6d6e6f71737577787a7b7c7f8084878a8b8d8e9192959697989a9c9d9ea0a2a8acafb0b4b5b6b7bac0c1c2c3c6c7c8cbcdcecfd1d2d8#d9dadcdddfe4e6e7e9ecedf2f4f9ff,6d:000203050608090a0d0f101113141516181c1d1f20212223242628292c2d2f30343637383a3f404244494c50555657585b5d5f6162646567686b6c6d707172737576797a7b7d7e7f8081838486878a8b8d8f9092969798999a9ca2a5acadb0b1b3b4b6b7b9babbbcbdbec1c2c3c8c9cacdcecfd0d2d3d4d5d7dadbdcdfe2e3e5e7e8e9eaedeff0f2f4f5f6f8fafdfeff,6e:0001020304060708090b0f12131518191b1c1e1f222627282a2c2e30313335#3637393b3c3d3e3f40414245464748494a4b4c4f5051525557595a5c5d5e606162636465666768696a6c6d6f707172737475767778797a7b7c7d8081828487888a8b8c8d8e91929394959697999a9b9d9ea0a1a3a4a6a8a9abacadaeb0b3b5b8b9bcbebfc0c3c4c5c6c8c9cacccdced0d2d6d8d9dbdcdde3e7eaebecedeeeff0f1f2f3f5f6f7f8fafbfcfdfeff,6f:000103040507080a0b0c0d0e101112161718191a1b1c1d1e1f212223252627282c2e303234353738393a3b3c3d3f404142#43444548494a4c4e4f5051525354555657595a5b5d5f60616364656768696a6b6c6f707173757677797b7d7e7f808182838586878a8b8f909192939495969798999a9b9d9e9fa0a2a3a4a5a6a8a9aaabacadaeafb0b1b2b4b5b7b8babbbcbdbebfc1c3c4c5c6c7c8cacbcccdcecfd0d3d4d5d6d7d8d9dadbdcdddfe2e3e4e5e6e7e8e9eaebecedf0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,70:000102030405060708090a0b0c0d0e0f1012131415161718191c1d1e1f2021222425262728292a#2b2c2d2e2f30313233343637383a3b3c3d3e3f404142434445464748494a4b4d4e505152535455565758595a5b5c5d5f606162636465666768696a6e7172737477797a7b7d818283848687888b8c8d8f90919397989a9b9e9fa0a1a2a3a4a5a6a7a8a9aab0b2b4b5b6babebfc4c5c6c7c9cbcccdcecfd0d1d2d3d4d5d6d7dadcdddee0e1e2e3e5eaeef0f1f2f3f4f5f6f8fafbfcfeff,71:0001020304050607080b0c0d0e0f111214171b1c1d1e1f2021222324252728292a2b2c2d2e323334#353738393a3b3c3d3e3f4041424344464748494b4d4f505152535455565758595a5b5d5f6061626365696a6b6c6d6f707174757677797b7c7e7f8081828385868788898b8c8d8e909192939596979a9b9c9d9ea1a2a3a4a5a6a7a9aaabadaeafb0b1b2b4b6b7b8babbbcbdbebfc0c1c2c4c5c6c7c8c9cacbcccdcfd0d1d2d3d6d7d8d9dadbdcdddedfe1e2e3e4e6e8e9eaebecedeff0f1f2f3f4f5f6f7f8fafbfcfdfeff,72:0001020304050708090a0b0c0d0e0f101112131415161718191a#1b1c1e1f2021222324252627292b2d2e2f3233343a3c3e40414243444546494a4b4e4f505153545557585a5c5e60636465686a6b6c6d707173747677787b7c7d828385868788898c8e9091939495969798999a9b9c9d9ea0a1a2a3a4a5a6a7a8a9aaabaeb1b2b3b5babbbcbdbebfc0c5c6c7c9cacbcccfd1d3d4d5d6d8dadb#95$,30:000102,00b702:c9c7,00a830:0305,2014ff5e20:162618191c1d,30:141508090a0b0c0d0e0f16171011,00:b1d7f7,22:362728110f2a2908371aa52520,231222:992b2e614c483d1d606e6f64651e3534,26:4240,00b020:3233,2103ff0400a4ff:e0e1,203000a7211626:0605,25:cbcfcec7c6a1a0b3b2,203b21:92909193,30:13#95$,21:70717273747576777879#4$,24:88898a8b8c8d8e8f909192939495969798999a9b7475767778797a7b7c7d7e7f808182838485868760616263646566676869##,32:20212223242526272829##,21:606162636465666768696a6b#97$,ff:010203e505060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5de3#95$,30:4142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293#106$a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6#103$,03:9192939495969798999a9b9c9d9e9fa0a1a3a4a5a6a7a8a9#6$b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c3c4c5c6c7c8c9#5$,fe:3536393a3f403d3e41424344##3b3c373831#3334#104$,04:10111213141501161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f#13$30313233343551363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f#11$,02:cacbd9,20:13152535,21:050996979899,22:151f23526667bf,25:505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071727381828384858687#88898a8b8c8d8e8f939495bcbde2e3e4e5,2609229530:121d1e#9$,010100e101ce00e0011300e9011b00e8012b00ed01d000ec014d00f301d200f2016b00fa01d400f901:d6d8dadc,00:fcea,0251e7c701:4448,e7c802:61#2$,31:05060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223242526272829#19$,30:212223242526272829,32a333:8e8f9c9d9ea1c4ced1d2d5,fe30ff:e2e4#,212132:31#,20:10#1$,30:fc9b9cfdfe069d9e,fe:494a4b4c4d4e4f50515254555657595a5b5c5d5e5f6061#626364656668696a6b,e7:e7e8e9eaebecedeeeff0f1f2f3,30:07#11$,25:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b#13$,72:dcdddfe2e3e4e5e6e7eaebf5f6f9fdfeff,73:00020405060708090b0c0d0f1011121418191a1f2023242627282d2f30323335363a3b3c3d404142434445464748#494a4b4c4e4f515354555658595a5b5c5d5e5f6162636465666768696a6b6e7071#92$72737475767778797a7b7c7d7f808182838586888a8c8d8f90929394959798999a9c9d9ea0a1a3a4a5a6a7a8aaacadb1b4b5b6b8b9bcbdbebfc1c3c4c5c6c7#cbccced2d3d4d5d6d7d8dadbdcdddfe1e2e3e4e6e8eaebeceeeff0f1f3f4f5f6f7#92$f8f9fafbfcfdfeff,74:0001020407080b0c0d0e1112131415161718191c1d1e1f2021232427292b2d2f31323738393a3b3d3e3f4042434445464748494a4b4c4d#4e4f505152535456585d606162636465666768696a6b6c6e6f717273747578797a#92$7b7c7d7f8284858688898a8c8d8f9192939495969798999a9b9d9fa0a1a2a3a4a5a6aaabacadaeafb0b1b2b3b4b5b6b7b8b9bbbcbdbebfc0c1c2c3c4c5c6c7#c8c9cacbcccdcecfd0d1d3d4d5d6d7d8d9dadbdddfe1e5e7e8e9eaebecedf0f1f2#92$f3f5f8f9fafbfcfdfe,75:0001020305060708090a0b0c0e1012141516171b1d1e202122232426272a2e3436393c3d3f414243444647494a4d5051525355565758#5d5e5f60616263646768696b6c6d6e6f7071737576777a7b7c7d7e808182848587#92$88898a8c8d8e909395989b9c9ea2a6a7a8a9aaadb6b7babbbfc0c1c6cbcccecfd0d1d3d7d9dadcdddfe0e1e5e9ecedeeeff2f3f5f6f7f8fafbfdfe,76:02040607#08090b0d0e0f11121314161a1c1d1e212327282c2e2f31323637393a3b3d414244#92$45464748494a4b4e4f50515253555758595a5b5d5f6061626465666768696a6c6d6e7071727374757677797a7c7f80818385898a8c8d8f9092949597989a9b#9c9d9e9fa0a1a2a3a5a6a7a8a9aaabacadafb0b3b5b6b7b8b9babbbcbdbec0c1c3,554a963f57c3632854ce550954c076:914c,853c77ee827e788d72319698978d6c285b894ffa630966975cb880fa684880ae660276ce51f9655671ac7ff1888450b2596561ca6fb382ad634c625253ed54277b06516b75a45df462d48dcb9776628a8019575d97387f627238767d67cf767e64464f708d2562dc7a17659173ed642c6273822c9881677f724862:6ecc,4f3474e3534a529e7eca90a65e2e6886699c81807ed168d278c5868c9551508d8c2482de80de53058912526576:c4c7c9cbccd3d5d9dadcdddee0e1e2e3e4e6e7e8e9eaebecedf0f3f5f6f7fafbfdff,77:00020305060a0c0e0f1011121314151617181b1c1d1e21232425272a2b#2c2e3031323334393b3d3e3f4244454648494a4b4c4d4e4f52535455565758595c,858496f94fdd582199715b9d62:b1a5,66b48c799c8d7206676f789160b253:5117,8f8880cc8d1d94a1500d72c8590760eb711988ab595482ef672c7b285d297ef7752d6cf58e668ff8903c9f3b6bd491197b145f7c78a784d6853d6b:d5d9d6,5e:0187,75f995ed655d5f:0ac5,8f9f58c181c2907f965b97ad8fb97f168d2c62414fbf53:d85e,8f:a8a9ab,904d68075f6a819888689cd6618b522b762a5f6c658c6fd26ee85bbe644851:75b0,67c44e1979c9997c70b377:5d5e5f606467696a6d6e6f7071727374757677787a7b7c818283868788898a8b8f90939495969798999a9b9c9d9ea1a3a4a6a8abadaeafb1b2b4b6b7b8b9ba#bcbec0c1c2c3c4c5c6c7c8c9cacbcccecfd0d1d2d3d4d5d6d8d9dadddedfe0e1e4,75c55e7673bb83e064ad62e894b56ce2535a52c3640f94c27b944f2f5e1b823681:168a,6e246cca9a736355535c54fa886557e04e0d5e036b657c3f90e8601664e6731c88c16750624d8d22776c8e2991c75f6983dc8521991053c286956b8b60:ede8,707f82:cd31,4ed36ca785cf64cd7cd969fd66f9834953957b564fa7518c6d4b5c428e6d63d253c983:2c36,67e578b4643d5bdf5c945dee8be762c667f48c7a640063ba8749998b8c177f2094f24ea7961098a4660c731677:e6e8eaeff0f1f2f4f5f7f9fafbfc,78:0304050607080a0b0e0f101315191b1e20212224282a2b2e2f31323335363d3f414243444648494a4b4d4f51535458595a#5b5c5e5f606162636465666768696f7071727374757678797a7b7d7e7f80818283,573a5c1d5e38957f507f80a05382655e7545553150218d856284949e671d56326f6e5de2543570928f66626f64a463a35f7b6f8890f481e38fb05c1866685ff16c8996488d81886c649179f057ce6a59621054484e587a0b60e96f848bda627f901e9a8b79e4540375f4630153196c608fdf5f1b9a70803b9f7f4f885c3a8d647fc565a570bd51:45b2,866b5d075ba062bd916c75748e0c7a2061017b794ec77ef877854e1181ed521d51fa6a7153a88e87950496cf6ec19664695a78:848586888a8b8f9092949596999d9ea0a2a4a6a8a9aaabacadaeafb5b6b7b8babbbcbdbfc0c2c3c4c6c7c8cccdcecfd1d2d3d6d7d8dadbdcdddedfe0e1e2e3#e4e5e6e7e9eaebedeeeff0f1f3f5f6f8f9fbfcfdfeff,79:00020304060708090a0b0c,784050a877d7641089e6590463e35ddd7a7f693d4f20823955984e3275ae7a975e:628a,95ef521b5439708a6376952457826625693f918755076df37eaf882262337ef075b5832878c196cc8f9e614874f78bcd6b64523a8d506b21806a847156f153064e:ce1b,51d17c97918b7c074fc38e7f7be17a9c64675d1450ac810676017cb96dec7fe067515b:58f8,78cb64:ae13,63:aa2b,9519642d8fbe7b5476296253592754466b7950a362345e266b864ee38d37888b5f85902e79:0d0e0f1011121415161718191a1b1c1d1f2021222325262728292a2b2c2d2e2f3031323335363738393d3f42434445474a4b4c4d4e4f505152545558596163#6466696a6b6c6e70717273747576797b7c7d7e7f8283868788898b8c8d8e909192,6020803d62c54e39535590f863b880c665e66c2e4f4660ee6de18bde5f3986cb5f536321515a83616863520063638e4850125c9b79775bfc52307a3b60bc905376d75f:b797,76848e6c706f767b7b4977aa51f3909358244f4e6ef48fea654c7b1b72c46da47fdf5ae162b55e95573084827b2c5e1d5f1f90127f1498a063826ec7789870b95178975b57ab75354f4375385e9760e659606dc06bbf788953fc96d551cb52016389540a94938c038dcc7239789f87768fed8c0d53e079:939495969798999b9c9d9e9fa0a1a2a3a4a5a6a8a9aaabacadaeafb0b1b2b4b5b6b7b8bcbfc2c4c5c7c8cacccecfd0d3d4d6d7d9dadbdcdddee0e1e2e5e8ea#eceef1f2f3f4f5f6f7f9fafcfeff,7a:0104050708090a0c0f10111213151618191b1c,4e0176ef53ee948998769f0e952d5b9a8ba24e:221c,51ac846361c252a8680b4f97606b51bb6d1e515c6296659796618c46901775d890fd77636bd272:8aec,8bfb583577798d4c675c9540809a5ea66e2159927aef77ed953b6bb565ad7f0e58065151961f5bf958a954288e726566987f56e4949d76fe9041638754c659:1a3a,579b8eb267358dfa8235524160f0581586fe5ce89e454fc4989d8bb95a2560765384627c904f9102997f6069800c513f80335c1499756d314e8c7a:1d1f21222425262728292a2b2c2d2e2f303132343536383a3e4041424344454748494a4b4c4d4e4f50525354555658595a5b5c5d5e5f606162636465666768#696a6b6c6d6e6f717273757b7c7d7e828587898a8b8c8e8f909394999a9b9ea1a2,8d3053d17f5a7b4f4f104e4f96006cd573d085e95e06756a7ffb6a0a77fe94927e4151e170e653cd8fd483038d2972af996d6cdb574a82b365b980aa623f963259a84eff8bbf7eba653e83f2975e556198de80a5532a8bfd542080ba5e9f6cb88d3982ac915a54296c1b52067eb7575f711a6c7e7c89594b4efd5fff61247caa4e305c0167ab87025cf0950b98ce75af70fd902251af7f1d8bbd594951e44f5b5426592b657780a45b7562:76c2,8f905e456c1f7b264f:0fd8,670d7a:a3a4a7a9aaabaeafb0b1b2b4b5b6b7b8b9babbbcbdbec0c1c2c3c4c5c6c7c8c9cacccdcecfd0d1d2d3d4d5d7d8dadbdcdde1e2e4e7e8e9eaebeceef0f1f2f3#f4f5f6f7f8fbfcfe,7b:0001020507090c0d0e1012131617181a1c1d1f21222327292d,6d:6eaa,798f88b15f17752b629a8f854fef91dc65a781:2f51,5e9c81508d74526f89868d4b590d50854ed8961c723681798d1f5bcc8ba3964459877f1a549056:760e,8be565396982949976d66e895e72751867:46d1,7aff809d8d76611f79c665628d635188521a94a27f38809b7eb25c976e2f67607bd9768b9ad8818f7f947cd5641e95507a3f54:4ae5,6b4c640162089e3d80f3759952729769845b683c86e496:0194,94ec4e2a54047ed968398ddf801566f45e9a7fb97b:2f303234353637393b3d3f404142434446484a4d4e535557595c5e5f61636465666768696a6b6c6d6f70737476787a7c7d7f81828384868788898a8b8c8e8f#9192939698999a9b9e9fa0a3a4a5aeafb0b2b3b5b6b7b9babbbcbdbebfc0c2c3c4,57c2803f68975de5653b529f606d9f9a4f9b8eac516c5bab5f135de96c5e62f18d21517194a952fe6c9f82df72d757a267848d2d591f8f9c83c754957b8d4f306cbd5b6459d19f1353e486ca9aa88c3780a16545987e56fa96c7522e74dc52505be1630289024e5662d0602a68fa51735b9851a089c27ba199867f5060ef704c8d2f51495e7f901b747089c4572d78455f529f9f95fa8f689b3c8be17678684267dc8d:ea35,523d8f8a6eda68cd950590ed56fd679c88f98fc754c87b:c5c8c9cacbcdcecfd0d2d4d5d6d7d8dbdcdedfe0e2e3e4e7e8e9ebecedeff0f2f3f4f5f6f8f9fafbfdff,7c:0001020304050608090a0d0e101112131415171819#1a1b1c1d1e20212223242528292b2c2d2e2f3031323334353637393a3b3c3d3e42,9ab85b696d776c264ea55bb39a87916361a890af97e9542b6db55bd251fd558a7f:55f0,64bc634d65f161be608d710a6c:5749,592f676d822a58d5568e8c6a6beb90dd597d801753f76d695475559d83:77cf,683879be548c4f55540876d28c8996026cb36db88d6b89109e648d3a563f9ed175d55f8872e0606854fc4ea86a2a886160528f7054c470d886799e3f6d2a5b8f5f187ea255894faf7334543c539a501954:0e7c,4e4e5ffd745a58f6846b80e1877472d07cca6e567c:434445464748494a4b4c4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717275767778797a7e7f8081828384858687#888a8b8c8d8e8f90939496999a9ba0a1a3a6a7a8a9abacadafb0b4b5b6b7b8babb,5f27864e552c62a44e926caa623782b154d7534e733e6ed1753b521253168bdd69d05f8a60006dee574f6b2273af68538fd87f13636260a3552475ea8c6271156da35ba65e7b8352614c9ec478fa87577c27768751f060f6714c66435e4c604d8c0e707063258f895fbd606286d456de6bc160946167534960e066668d3f79fd4f1a70e96c478b:b3f2,7ed88364660f5a5a9b426d:51f7,8c416d3b4f19706b83b7621660d1970d8d27797851fb57:3efa,673a75787a3d79ef7b957c:bfc0c2c3c4c6c9cbcecfd0d1d2d3d4d8dadbdddee1e2e3e4e5e6e7e9eaebecedeef0f1f2f3f4f5f6f7f9fafcfdfeff,7d:000102030405060708090b0c0d0e0f10#1112131415161718191a1b1c1d1e1f212324252628292a2c2d2e30313233343536,808c99658ff96fc08ba59e2159ec7ee97f095409678168d88f917c4d96c653ca602575be6c7253735ac97ea7632451e0810a5df184df628051805b634f0e796d524260b86d4e5b:c4c2,8b:a1b0,65e25fcc964559937e:e7aa,560967b759394f735bb652a0835a988a8d3e753294be50477a3c4ef767b69a7e5ac16b7c76d1575a5c167b3a95f4714e517c80a9827059787f04832768c067ec78:b177,62e363617b804fed526a51cf835069db92748d:f531,89c1952e7bad4ef67d:3738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6f70717273747576#78797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798,506582305251996f6e:1085,6da75efa50f559dc5c066d466c5f7586848b686859568bb253209171964d854969127901712680f64ea490ca6d479a845a0756bc640594f077eb4fa5811a72e189d2997a7f347ede527f655991758f:7f83,53eb7a9663:eda5,768679f888579636622a52ab8282685467706377776b7aed6d017ed389e359d0621285c982a5754c501f4ecb75a58beb5c4a5dfe7b4b65a491d14eca6d25895f7d2795264ec58c288fdb9773664b79818fd170ec6d787d:999a9b9c9d9e9fa0a1a2a3a4a5a7a8a9aaabacadafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9#dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fa,5c3d52b283465162830e775b66769cb84eac60ca7c:beb3,7ecf4e958b66666f988897595883656c955c5f8475c997567a:dfde,51c070af7a9863ea7a767ea0739697ed4e4570784e5d915253a965:51e7,81fc8205548e5c31759a97a062d872d975bd5c459a7983ca5c40548077e94e3e6cae805a62d2636e5de851778ddd8e1e952f4ff153e560e770ac526763509e435a1f5026773753777ee26485652b628963985014723589c951b38bc07edd574783cc94a7519b541b5cfb7d:fbfcfdfeff,7e:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536373839#3a3c3d3e3f40424344454648494a4b4c4d4e4f505152535455565758595a5b5c5d,4fca7ae36d5a90e19a8f55805496536154af5f0063e9697751ef6168520a582a52d8574e780d770b5eb761777ce062:5b97,4ea27095800362f770e49760577782db67ef68f578d5989779d158f354b353ef6e34514b523b5ba28bfe80af554357a660735751542d7a7a60505b5463a762a053e362635bc767af54ed7a9f82e691775e9388e4593857ae630e8de880ef57577b774fa95feb5bbd6b3e53217b5072c2684677:ff36,65f751b54e8f76d45cbf7aa58475594e9b4150807e:5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081838485868788898a8b8c8d8e8f909192939495969798999a9c9d9e#aeb4bbbcd6e4ecf9,7f:0a101e37393b3c3d3e3f404143464748494a4b4c4d4e4f5253,998861276e8357646606634656f062:ec69,5ed39614578362c955878721814a8fa3556683b167658d5684dd5a6a680f62e67bee961151706f9c8c3063fd89c861d27f0670c26ee57405699472fc5eca90ce67176d6a635e52b3726280014f6c59e5916a70d96d9d52d24e5096f7956d857e78ca7d2f5121579264c2808b7c7b6cea68f1695e51b7539868a872819ece7bf172f879bb6f137406674e91cc9ca4793c83:8954,540f68174e3d538952b1783e5386522950884f:8bd0,7f:56595b5c5d5e6063646566676b6c6d6f7073757677787a7b7c7d7f8082838485868788898b8d8f9091929395969798999b9ca0a2a3a5a6a8a9aaabacadaeb1#b3b4b5b6b7babbbec0c2c3c4c6c7c8c9cbcdcfd0d1d2d3d6d7d9dadbdcdddee2e3,75e27acb7c926ca596b6529b748354e94fe9805483b28fde95705ec9601c6d9f5e18655b813894fe604b70bc7ec37cae51c968817cb1826f4e248f8691cf667e4eae8c0564a9804a50da759771ce5be58fbd6f664e86648295635ed66599521788c270c852a3730e7433679778f797164e3490bb9cde6dcb51db8d41541d62ce73b283f196f69f8494c34f367f9a51cc707596755cad988653e64ee46e9c740969b4786b998f7559521876246d4167f3516d9f99804b54997b3c7abf7f:e4e7e8eaebecedeff2f4f5f6f7f8f9fafdfeff,80:020708090a0e0f11131a1b1d1e1f2123242b2c2d2e2f303234393a3c3e404144454748494e4f505153555657#595b5c5d5e5f6061626364656667686b6c6d6e6f7072737475767778797a7b7c7d,9686578462e29647697c5a0464027bd36f0f964b82a6536298855e90708963b35364864f9c819e93788c97328d:ef42,9e7f6f5e79845f559646622e9a74541594dd4fa365c55c:6561,7f1586516c2f5f8b73876ee47eff5ce6631b5b6a6ee653754e7163a0756562a18f6e4f264ed16ca67eb68bba841d87ba7f57903b95237ba99aa188f8843d6d1b9a867edc59889ebb739b780186829a:6c82,561b541757cb4e709ea653568fc881097792999286ee6ee1851366fc61626f2b80:7e818285888a8d8e8f909192949597999ea3a6a7a8acb0b3b5b6b8b9bbc5c7c8c9cacbcfd0d1d2d3d4d5d8dfe0e2e3e6eef5f7f9fbfeff,81:000103040507080b#0c1517191b1c1d1f202122232425262728292a2b2d2e3033343537393a3b3c3d3f,8c298292832b76f26c135fd983bd732b8305951a6bdb77db94c6536f830251925e3d8c8c8d384e4873ab679a68859176970971646ca177095a9295416bcf7f8e66275bd059b95a9a95:e8f7,4eec84:0c99,6aac76df9530731b68a65b5f772f919a97617cdc8ff78c1c5f257c7379d889c56ccc871c5bc65e4268c977207ef551:954d,52c95a297f05976282d763cf778485d079d26e3a5e9959998511706d6c1162bf76bf654f60af95fd660e879f9e2394ed54:0d7d,8c2c647881:40414243444547494d4e4f525657585b5c5d5e5f6162636466686a6b6c6f727375767778818384858687898b8c8d8e90929394959697999a9e9fa0a1a2a4a5#a7a9abacadaeafb0b1b2b4b5b6b7b8b9bcbdbebfc4c5c7c8c9cbcdcecfd0d1d2d3,647986116a21819c78e864699b5462b9672b83ab58a89ed86cab6f205bde964c8c0b725f67d062c772614ea959c66bcd589366ae5e5552df6155672876ee776672677a4662ff54:ea50,94a090a35a1c7eb36c164e435976801059485357753796be56ca63208111607c95f96dd65462998151855ae980fd59ae9713502a6ce55c3c62df4f60533f817b90066eba852b62c85e7478be64b5637b5ff55a18917f9e1f5c3f634f80425b7d556e95:4a4d,6d8560a867e072de51dd5b8181:d4d5d6d7d8d9dadbdcdddedfe0e1e2e4e5e6e8e9ebeeeff0f1f2f5f6f7f8f9fafdff,82:030708090a0b0e0f111315161718191a1d2024252627292e323a3c3d3f#404142434546484a4c4d4e5051525354555657595b5c5d5e606162636465666769,62e76cde725b626d94ae7ebd81136d53519c5f04597452aa6012597366968650759f632a61e67cef8bfa54e66b279e256bb485d5545550766ca4556a8db4722c5e156015743662cd6392724c5f986e436d3e65006f5876d878d076fc7554522453db4e535e9e65c180:2ad6,629b5486522870ae888d8dd16ce1547880da57f988f48d54966a914d4f696c9b55b776c6783062a870f96f8e5f6d84ec68da787c7bf781a8670b9e4f636778b0576f7812973962:79ab,528874356bd782:6a6b6c6d71757677787b7c808183858687898c90939495969a9b9ea0a2a3a7b2b5b6babbbcbfc0c2c3c5c6c9d0d6d9dadde2e7e8e9eaecedeef0f2f3f5f6f8#fafcfdfeff,83:000a0b0d1012131618191d1e1f20212223242526292a2e3032373b3d,5564813e75b276ae533975de50fb5c418b6c7bc7504f72479a9798d86f0274e27968648777a562fc98918d2b54c180584e52576a82f9840d5e7351ed74f68bc45c4f57616cfc98875a4678349b448feb7c955256625194fa4ec68386846183e984b257d467345703666e6d668c3166dd7011671f6b3a6816621a59bb4e0351c46f0667d26c8f517668cb59476b6775665d0e81109f5065d779:4841,9a918d775c824e5e4f01542f5951780c56686c148fc45f036c:7de3,8bab639083:3e3f41424445484a4b4c4d4e5355565758595d6270717273747576797a7e7f808182838487888a8b8c8d8f909194959697999a9d9fa1a2a3a4a5a6a7acadae#afb5bbbebfc2c3c4c6c8c9cbcdced0d1d2d3d5d7d9dadbdee2e3e4e6e7e8ebeced,60706d3d7275626694:8ec5,53438fc17b7e4edf8c264e7e9ed494:b1b3,524d6f5c90636d458c3458115d4c6b:2049,67aa545b81547f8c589985375f3a62a26a47953965726084686577a74e544fa85de7979864ac7fd85ced4fcf7a8d520783044e14602f7a8394a64fb54eb279e6743452e482b964d279bd5bdd6c8197528f7b6c22503e537f6e0564ce66746c3060c598778bf75e86743c7a7779cb4e1890b174036c4256da914b6cc58d8b533a86c666f28eaf5c489a716e2083:eeeff3f4f5f6f7fafbfcfeff,84:0002050708090a10121314151617191a1b1e1f20212223292a2b2c2d2e2f30323334353637393a3b3e3f404142434445474849#4a4b4c4d4e4f505253545556585d5e5f606264656667686a6e6f70727477797b7c,53d65a369f8b8da353bb570898a76743919b6cc9516875ca62f372ac52:389d,7f3a7094763853749e4a69b7786e96c088d97fa471:36c3,518967d374e458e4651856b78ba9997662707ed560f970ed58ec4e:c1ba,5fcd97e74efb8ba45203598a7eab62544ecd65e5620e833884c98363878d71946eb65bb97ed2519763c967d480898339881551125b7a59828fb14e736c5d516589258f6f962e854a745e95:10f0,6da682e55f3164926d128428816e9cc3585e8d5b4e0953c184:7d7e7f8081838485868a8d8f90919293949596989a9b9d9e9fa0a2a3a4a5a6a7a8a9aaabacadaeb0b1b3b5b6b7bbbcbec0c2c3c5c6c7c8cbcccecfd2d4d5d7#d8d9dadbdcdee1e2e4e7e8e9eaebedeeeff1f2f3f4f5f6f7f8f9fafbfdfe,85:000102,4f1e6563685155d34e2764149a9a626b5ac2745f82726da968ee50e7838e7802674052396c997eb150bb5565715e7b5b665273ca82eb67495c715220717d886b95ea965564c58d6181b355846c5562477f2e58924f2455468d4f664c4e0a5c1a88f368a2634e7a0d70e7828d52fa97f65c1154e890b57ecd59628d4a86c782:0c0d,8d6664445c0461516d89793e8bbe78377533547b4f388eab6df15a207ec5795e6c885ba15a76751a80be614e6e1758f075:1f25,727253477ef385:030405060708090a0b0d0e0f101214151618191b1c1d1e2022232425262728292a2d2e2f303132333435363e3f404142444546474b4c4d4e4f505152535455#57585a5b5c5d5f60616263656667696a6b6c6d6e6f707173757677787c7d7f8081,770176db526980dc57235e08593172ee65bd6e7f8bd75c388671534177f362fe65f64ec098df86805b9e8bc653f277e24f7f5c4e9a7659cb5f0f793a58eb4e1667ff4e8b62ed8a93901d52bf662f55dc566c90024ed54f8d91ca99706c0f5e0260435ba489c68bd56536624b99965b:88ff,6388552e53d77626517d852c67a268b36b8a62928f9353d482126dd1758f4e668d4e5b70719f85af66:91d9,7f7287009ecd9f205c5e672f8ff06811675f620d7ad658855eb665706f3185:82838688898a8b8c8d8e909192939495969798999a9d9e9fa0a1a2a3a5a6a7a9abacadb1b2b3b4b5b6b8babbbcbdbebfc0c2c3c4c5c6c7c8cacbcccdced1d2#d4d6d7d8d9dadbdddedfe0e1e2e3e5e6e7e8eaebecedeeeff0f1f2f3f4f5f6f7f8,60555237800d6454887075295e05681362f4971c53cc723d8c016c3477617a0e542e77ac987a821c8bf47855671470c165af64955636601d79c153f84e1d6b7b80865bfa55e356db4f:3a3c,99725df3677e80386002988290015b8b8b:bcf5,641c825864de55fd82cf91654fd77d20901f7c9f50f358516eaf5bbf8bc980839178849c7b97867d96:8b8f,7ee59ad3788e5c817a57904296a7795f5b59635f7b0b84d168ad55067f2974107d2295016240584c4ed65b835979585485:f9fafcfdfe,86:0001020304060708090a0b0c0d0e0f10121314151718191a1b1c1d1e1f20212223242526282a2b2c2d2e2f3031323334353637393a3b3d3e3f40#4142434445464748494a4b4c525355565758595b5c5d5f6061636465666768696a,736d631e8e:4b0f,80ce82d462ac53f06cf0915e592a60016c70574d644a8d2a762b6ee9575b6a8075f06f6d8c:2d08,57666bef889278b363a253f970ad6c645858642a580268e0819b55107cd650188eba6dcc8d9f70eb638f6d9b6ed47ee68404684390036dd896768ba85957727985e4817e75bc8a8a68af52548e22951163d098988e44557c4f5366ff568f60d56d9552435c4959296dfb586b75:301c,606c82148146631167618fe2773a8d:f334,94c15e165385542c70c386:6d6f7072737475767778838485868788898e8f90919294969798999a9b9e9fa0a1a2a5a6abadaeb2b3b7b8b9bbbcbdbebfc1c2c3c5c8cccdd2d3d5d6d7dadc#dde0e1e2e3e5e6e7e8eaebeceff5f6f7fafbfcfdff,87:010405060b0c0e0f10111416,6c405ef7505c4ead5ead633a8247901a6850916e77b3540c94dc5f647ae5687663457b527edf75db507762955934900f51f879c37a8156fe5f9290146d825c60571f541051546e4d56e263a89893817f8715892a9000541e5c6f81c062:d658,81319e3596409a:6e7c,692d59a562d3553e631654c786d96d3c5a0374e6889c6b6a59168c4c5f2f6e7e73a9987d4e3870f75b8c7897633d665a769660cb5b9b5a494e0781556c6a738b4ea167897f515f8065fa671b5fd859845a0187:191b1d1f20242627282a2b2c2d2f303233353638393a3c3d404142434445464a4b4d4f505152545556585a5b5c5d5e5f6162666768696a6b6c6d6f71727375#7778797a7f8081848687898a8c8e8f90919294959698999a9b9c9d9ea0a1a2a3a4,5dcd5fae537197e68fdd684556f4552f60df4e3a6f4d7ef482c7840e59d44f:1f2a,5c3e7eac672a851a5473754f80c355829b4f4f4d6e2d8c135c096170536b761f6e29868a658795fb7eb9543b7a337d0a95ee55e17fc174ee631d87176da17a9d621165a1536763e16c835deb545c94a84e4c6c618bec5c4b65e0829c68a754:3e34,6b:cb66,4e9463425348821e4f:0dae,575e620a96fe6664726952:ffa1,609f8bef661471996790897f785277fd6670563b54389521727a87:a5a6a7a9aaaeb0b1b2b4b6b7b8b9bbbcbebfc1c2c3c4c5c7c8c9cccdcecfd0d4d5d6d7d8d9dadcdddedfe1e2e3e4e6e7e8e9ebecedeff0f1f2f3f4f5f6f7f8#fafbfcfdff,88:0001020405060708090b0c0d0e0f101112141718191a1c1d1e1f2023,7a00606f5e0c6089819d591560dc718470ef6eaa6c5072806a8488ad5e2d4e605ab3559c94e36d177cfb9699620f7ec6778e867e5323971e8f9666875ce14fa072ed4e0b53a6590f54136380952851484ed99c9c7ea454b88d248854823795f26d8e5f265acc663e966973:b02e,53bf817a99857fa15baa96:7750,7ebf76f853a2957699997bb189446e584e617fd479658be660f354cd4eab98795df76a6150cf54118c618427785d9704524a54ee56a395006d885bb56dc6665388:2425262728292a2b2c2d2e2f30313334353637383a3b3d3e3f414243464748494a4b4e4f505152535556585a5b5c5d5e5f6066676a6d6f717374757678797a#7b7c80838687898a8c8e8f90919394959798999a9b9d9e9fa0a1a3a5a6a7a8a9aa,5c0f5b5d6821809655787b11654869544e9b6b47874e978b534f631f643a90aa659c80c18c10519968b0537887f961c86c:c4fb,8c225c5185aa82af950c6b238f9b65b05f:fbc3,4fe18845661f8165732960fa51745211578b5f6290a2884c91925e78674f602759d351:44f6,80f853086c7996c4718a4f:11ee,7f9e673d55c5950879c088967ee3589f620c9700865a5618987b5f908bb884c4915753d965ed5e8f755c60647d6e5a7f7e:eaed,8f6955a75ba360ac65cb738488:acaeafb0b2b3b4b5b6b8b9babbbdbebfc0c3c4c7c8cacbcccdcfd0d1d3d6d7dadbdcdddee0e1e6e7e9eaebecedeeeff2f5f6f7fafbfdff,89:0001030405060708#090b0c0d0e0f1114151617181c1d1e1f20222324262728292c2d2e2f3132333537,9009766377297eda9774859b5b667a7496ea884052cb718f5faa65ec8be25bfb9a6f5de16b896c5b8b:adaf,900a8fc5538b62bc9e:262d,54404e2b82bd7259869c5d1688596daf96c554d14e9a8bb6710954bd960970df6df976d04e25781487125ca95ef68a00989c960e708e6cbf594463a9773c884d6f148273583071d5538c781a96c155015f6671305bb48c1a9a8c6b83592e9e2f79e76768626c4f6f75a17f8a6d0b96336c274ef075d2517b68376f3e908081705996747689:38393a3b3c3d3e3f40424345464748494a4b4c4d4e4f505152535455565758595a5b5c5d6061626364656768696a6b6c6d6e6f707172737475767778797a7c#7d7e808284858788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1,64475c2790657a918c2359da54ac8200836f898180006930564e8036723791ce51b64e5f987563964e1a53f666f3814b591c6db24e0058f9533b63d694f14f:9d0a,886398905937905779fb4eea80f075916c825b9c59e85f5d69058681501a5df24e5977e34ee5827a6291661390915c794ebf5f7981c69038808475ab4ea688d4610f6bc55fc64e4976ca6ea28b:e3ae,8c0a8bd15f027f:fccc,7ece83:356b,56e06bb797f3963459fb541f94f66deb5bc5996e5c395f15969089:a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c3cdd3d4d5d7d8d9dbdddfe0e1e2e4e7e8e9eaecedeef0f1f2f4f5f6f7f8f9fa#fbfcfdfeff,8a:01020304050608090a0b0c0d0e0f101112131415161718191a1b1c1d,537082f16a315a749e705e947f2883b984:2425,836787478fce8d6276c85f719896786c662054df62e54f6381c375c85eb896cd8e0a86f9548f6cf36d8c6c38607f52c775285e7d4f1860a05fe75c24753190ae94c072b96cb96e389149670953:cbf3,4f5191c98bf153c85e7c8fc26de44e8e76c26986865e611a82064f:59de,903e9c7c61096e:1d14,96854e885a3196e84e0e5c7f79b95b878bed7fbd738957df828b90c15401904755bb5cea5fa161086b3272f180b28a:891e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3f4041424344454647494a4b4c4d4e4f505152535455565758595a5b5c5d5e#5f606162636465666768696a6b6c6d6e6f7071727374757677787a7b7c7d7e7f80,6d745bd388d598848c6b9a6d9e336e0a51:a443,57a38881539f63f48f9556ed54585706733f6e907f188fdc82d1613f6028966266f07ea68d:8ac3,94a55cb37ca4670860a6960580184e9190e75300966851418fd08574915d665597f55b55531d78386742683d54c9707e5bb08f7d518d572854b1651266828d:5e43,810f846c906d7cdf51ff85fb67a365e96fa186a48e81566a90207682707671e58d2362e952196cfd8d3c600e589e618e66fe8d60624e55b36e23672d8f678a:81828384858687888b8c8d8e8f9091929495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2#c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3,94e195f87728680569a8548b4e4d70b88bc86458658b5b857a84503a5be877bb6be18a797c986cbe76cf65a98f975d2d5c5586386808536062187ad96e5b7efd6a1f7ae05f706f335f20638c6da867564e085e108d264ed780c07634969c62db662d627e6cbc8d7571677f695146808753ec906e629854f286f08f998005951785178fd96d5973cd659f771f7504782781fb8d1e94884fa6679575b98bca9707632f9547963584b8632377415f8172f04e896014657462ef6b63653f8a:e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,8b:0001020304050608090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223#24252728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445,5e2775c790d18bc1829d679d652f5431871877e580a281026c414e4b7ec7804c76f4690d6b966267503c4f84574063076b628dbe53ea65e87eb85fd763:1ab7,81:f3f4,7f6e5e1c5cd95236667a79e97a1a8d28709975d46ede6cbb7a924e2d76c55fe0949f88777ec879cd80bf91cd4ef24f17821f54685dde6d328bcc7ca58f7480985e1a549276b15b99663c9aa473e0682a86db6731732a8b:f8db,90107af970db716e62c477a956314e3b845767f152a986c08d2e94f87b518b:464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364656768696a6b6d6e6f707172737475767778797a7b7c7d7e7f80818283848586#8788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9facb1bbc7d0ea,8c:091e,4f4f6ce8795d9a7b6293722a62fd4e1378168f6c64b08d5a7bc668695e8488c55986649e58ee72b6690e95258ffd8d5857607f008c0651c6634962d95353684c74228301914c55447740707c6d4a517954a88d4459ff6ecb6dc45b5c7d2b4ed47c7d6ed35b5081ea6e0d5b579b0368d58e2a5b977efc603b7eb590b98d70594f63cd79df8db3535265cf79568bc5963b7ec494bb7e825634918967007f6a5c0a907566285de64f5067de505a4f5c57505e:a7#3$,8c:38393a3b3c3d3e3f4042434445484a4b4d4e4f5051525354565758595b5c5d5e5f60636465666768696c6d6e6f707172747576777b7c7d7e7f808183848687#888b8d8e8f90919293959697999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacad,4e:8d0c,51404e105eff53454e:15981e,9b325b6c56694e2879ba4e3f53154e47592d723b536e6c1056df80e499976bd3777e9f174e:369f,9f104e:5c6993,82885b5b556c560f4ec453:8d9da3a5ae,97658d5d53:1af5262e3e,8d5c53:6663,52:02080e2d333f404c5e615c,84af52:7d82819093,51827f544e:bbc3c9c2e8e1ebde,4f1b4ef34f:2264,4ef54f:2527092b5e67,65384f:5a5d,8c:aeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebec#edeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,8d:000102030405060708090a0b0c0d,4f:5f57323d76749189838f7e7baa7cac94e6e8eac5dae3dcd1dff8,50:294c,4ff350:2c0f2e2d,4ffe50:1c0c25287e4355484e6c7ba5a7a9bad6,510650:edece6ee,51:070b,4edd6c3d4f:5865ce,9fa06c467c74516e5dfd9ec999985181591452f9530d8a07531051eb591951554ea051564eb388:6ea4,4eb5811488d279805b3488037fb851:abb1bdbc,8d:0e0f101112131415161718191a1b1c205152575f6568696a6c6e6f717278797a7b7c7d7e7f808283868788898c8d8e8f90929395969798999a9b9c9d9ea0a1#a2a4a5a6a7a8a9aaabacadaeafb0b2b6b7b9bbbdc0c1c2c5c7c8c9cacdd0d2d3d4,51:c796a2a5,8b:a0a6a7aab4b5b7c2c3cbcfced2d3d4d6d8d9dcdfe0e4e8e9eef0f3f6f9fcff,8c:000204070c0f1112141516191b181d1f202125272a2b2e2f32333536,53:697a,96:1d2221312a3d3c4249545f676c7274888d97b0,90:979b9d99aca1b4b3b6ba,8d:d5d8d9dce0e1e2e5e6e7e9edeef0f1f2f4f6fcfeff,8e:00010203040607080b0d0e1011121315161718191a1b1c202124252627282b2d303233343637383b3c3e#3f4345464c4d4e4f505354555657585a5b5c5d5e5f60616263646567686a6b6e71,90:b8b0cfc5bed0c4c7d3e6e2dcd7dbebeffe,91:04221e23312f394346,520d594252:a2acadbe,54ff52:d0d6f0,53df71ee77cd5ef451:f5fc,9b2f53b65f01755a5def57:4ca9a1,58:7ebcc5d1,57:292c2a33392e2f5c3b4269856b867c7b686d7673ada48cb2cfa7b493a0d5d8dad9d2b8f4eff8e4dd,8e:73757778797a7b7d7e808283848688898a8b8c8d8e91929395969798999a9b9d9fa0a1a2a3a4a5a6a7a8a9aaadaeb0b1b3b4b5b6b7b8b9bbbcbdbebfc0c1c2#c3c4c5c6c7c8c9cacbcccdcfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4,58:0b0d,57:fded,58:001e194420656c81899a80,99a89f1961ff82:797d7f8f8aa8848e919799abb8beb0c8cae398b7aecbccc1a9b4a1aa9fc4cea4e1,830982:f7e4,83:0f07,82:dcf4d2d8,830c82:fbd3,83:111a061415,82:e0d5,83:1c515b5c08923c34319b5e2f4f47435f4017602d3a336665,8e:e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,8f:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223#2425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344,83:681b696c6a6d6eb078b3b4a0aa939c857cb6a97db87b989ea8babcc1,840183:e5d8,580784:180b,83:ddfdd6,84:1c381106,83:d4df,84:0f03,83:f8f9eac5c0,842683:f0e1,84:5c515a597387887a89783c4669768c8e316dc1cdd0e6bdd3cabfbae0a1b9b497e5e3,850c750d853884f085:391f3a,8f:45464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364656a808c929da0a1a2a4a5a6a7aaacadaeafb2b3b4b5b7b8babbbcbfc0c3c6#c9cacbcccdcfd2d6d7dae0e1e3e7eceff1f2f4f5f6fafbfcfeff,90:07080c0e131518,85:563b,84:fffc,85:594868645e7a,77a285:43727ba4a8878f79ae9c85b9b7b0d3c1dcff,86:270529163c,5efe5f0859:3c41,803759:555a58,530f5c:22252c34,62:4c6a9fbbcadad7ee,632262f663:394b43adf6717a8eb46dac8a69aebcf2f8e0ffc4dece,645263:c6be,64:45410b1b200c26215e846d96,90:191c2324252728292a2b2c303132333437393a3d3f4043454648494a4b4c4e545556595a5c5d5e5f6061646667696a6b6c6f70717273767778797a7b7c7e81#84858687898a8c8d8e8f90929496989a9c9e9fa0a4a5a7a8a9abadb2b7bcbdbfc0,64:7ab7b899bac0d0d7e4e2,65:09252e,5f:0bd2,75195f1153:5ff1fde9e8fb,54:1216064b5253545643215759233282947771649a9b8476669dd0adc2b4d2a7a6d3d472a3d5bbbfccd9dadca9aaa4ddcfde,551b54e7552054fd551454f355:22230f11272a678fb5496d41553f503c,90:c2c3c6c8c9cbcccdd2d4d5d6d8d9dadedfe0e3e4e5e9eaeceef0f1f2f3f5f6f7f9fafbfcff,91:00010305060708090a0b0c0d0e0f1011121314151617181a1b1c#1d1f20212425262728292a2b2c2d2e30323334353637383a3b3c3d3e3f40414244,55:375675767733305c8bd283b1b988819f7ed6917bdfbdbe9499eaf7c9,561f55:d1ebecd4e6ddc4efe5f2f3cccde8f5e4,8f9456:1e080c012423,55fe56:00272d5839572c4d62595c4c548664716b7b7c8593afd4d7dde1f5ebf9ff,57:040a091c,5e:0f191411313b3c,91:454748515354555658595b5c5f606667686b6d737a7b7c808182838486888a8e8f939495969798999c9d9e9fa0a1a4a5a6a7a8a9abacb0b1b2b3b6b7b8b9bb#bcbdbebfc0c1c2c3c4c5c6c8cbd0d2d3d4d5d6d7d8d9dadbdddedfe0e1e2e3e4e5,5e:3744545b5e61,5c:8c7a8d9096889899919a9cb5a2bdacabb1a3c1b7c4d2e4cbe5,5d:020327262e241e061b583e343d6c5b6f5d6b4b4a697482999d,8c735d:b7c5,5f:73778287898c95999ca8adb5bc,88625f6172:adb0b4b7b8c3c1cecdd2e8efe9f2f4f7,730172f3730372fa91:e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,92:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324#25262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445,72fb73:1713210a1e1d152239252c3831504d57606c6f7e,821b592598e759:2402,99:636768696a6b6c74777d8084878a8d9091939495,5e:80918b96a5a0b9b5beb3,8d535e:d2d1dbe8ea,81ba5f:c4c9d6cf,60035fee60045f:e1e4fe,60:0506,5f:eaedf8,60:1935261b0f0d292b0a3f2178797b7a42,92:464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071727375767778797a7b7c7d7e7f808182838485#868788898a8b8c8d8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7,60:6a7d969aad9d83928c9becbbb1ddd8c6dab4,61:20261523,60f461:000e2b4a75ac94a7b7d4f5,5fdd96b395:e9ebf1f3f5f6fcfe,96:030406080a0b0c0d0f12151617191a,4e2c723f62156c:35545c4aa38590948c6869747686a9d0d4adf7f8f1d7b2e0d6faebeeb1d3effe,92:a8a9aaabacadafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8#e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,93:00010203040506070809,6d:39270c43480704190e2b4d2e351a4f525433916f9ea05e93945c607c63,6e1a6d:c7c5de,6e0e6d:bfe0,6e116d:e6ddd9,6e166dab6e0c6dae6e:2b6e4e6bb25f865354322544dfb198e0,6f2d6e:e2a5a7bdbbb7d7b4cf8fc29f,6f:6246472415,6ef96f:2f364b742a0929898d8c78727c7ad1,93:0a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3f40414243444546474849#4a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696b,6f:c9a7b9b6c2e1eedee0ef,70:1a231b39354f5e,5b:80849593a5b8,752f9a9e64345b:e4ee,89305bf08e478b078f:b6d3d5e5eee4e9e6f3e8,90:05040b26110d162135362d2f445152506858625b,66b990:747d8288838b,5f:50575658,5c3b54ab5c:5059,5b715c:6366,7fbc5f:2a292d,82745f3c9b3b5c6e59:81838da9aaa3,93:6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaab#acadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cbcccd,59:97caab9ea4d2b2afd7be,5a:0506,59dd5a0859:e3d8f9,5a:0c09323411231340674a553c6275,80ec5a:aa9b777abeebb2d2d4b8e0e3f1d6e6d8dc,5b:091716323740,5c:151c,5b:5a6573515362,9a:7577787a7f7d808185888a90929396989b9c9d9fa0a2a3a5a7,7e:9fa1a3a5a8a9,93:cecfd0d1d2d3d4d5d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,94:000102030405060708090a0b0c0d#0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e,7e:adb0bec0c1c2c9cbccd0d4d7dbe0e1e8ebeeeff1f2,7f0d7e:f6fafbfe,7f:01020307080b0c0f111217191c1b1f212223242526272a2b2c2d2f3031323335,5e7a757f5ddb753e909573:8e91aea29fcfc2d1b7b3c0c9c8e5d9,987c740a73:e9e7debaf2,74:0f2a5b262528302e2c,94:2f303132333435363738393a3b3c3d3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6c6d6e6f#707172737475767778797a7b7c7d7e7f8081828384919698c7cfd3d4dae6fb,95:1c20,74:1b1a415c575559776d7e9c8e8081878b9ea8a990a7d2ba,97:eaebec,67:4c535e4869a5876a7398a775a89ead8b777cf0,680967d8680a67:e9b0,680c67:d9b5dab3dd,680067:c3b8e2,680e67:c1fd,68:323360614e624464831d55664167403e4a4929b58f7477936bc2,696e68fc69:1f20,68f995:27333d43484b555a606e74757778797a7b7c7d7e808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aa#abacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacb,692468f069:0b0157,68e369:10713960425d846b80987834cc8788ce896663799ba7bbabadd4b1c1cadf95e08dff,6a2f69ed6a:171865,69f26a:443ea0505b358e793d28587c9190a997ab,73:3752,6b:8182878492938d9a9ba1aa,8f:6b6d71727375767877797a7c7e818284878b,95:cccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7ecff,96:0713181b1e20232425262728292b2c2d2f303738393a3e41434a4e4f5152535657#58595a5c5d5e606365666b6d6e6f70717378797a7b7c7d7e7f808182838487898a,8f:8d8e8f989a,8ece62:0b171b1f222125242c,81e774:eff4ff,75:0f1113,65:34eeeff0,66:0a19,677266:031500,708566:f71d34313635,800666:5f54414f56615777848ca79dbedbdce6e9,8d:3233363b3d4045464849474d5559,89:c7cacbcccecfd0d1,72:6e9f5d666f7e7f848b8d8f92,63:0832b0,96:8c8e91929395969a9b9d9e9fa0a1a2a3a4a5a6a8a9aaabacadaeafb1b2b4b5b7b8babbbfc2c3c8cacbd0d1d3d4d6d7d8d9dadbdcdddedfe1e2e3e4e5e6e7eb#ecedeef0f1f2f4f5f8fafbfcfdff,97:0203050a0b0c10111214151718191a1b1d1f20,64:3fd8,80046b:eaf3fdf5f9,6c:0507060d1518191a2129242a32,65:35556b,72:4d525630,8662521680:9f9c93bc,670a80:bdb1abadb4b7e7e8e9eadbc2c4d9cdd7,671080:ddebf1f4ed,81:0d0e,80:f2fc,671581128c5a81:361e2c1832484c5374595a7160697c7d6d67,584d5ab581:888291,6ed581:a3aacc,672681:cabb,97:2122232425262728292b2c2e2f3133343536373a3b3c3d3f404142434445464748494a4b4c4d4e4f5051545557585a5c5d5f63646667686a6b6c6d6e6f7071#72757778797a7b7d7e7f8081828384868788898a8c8e8f9093959697999a9b9c9d,81:c1a6,6b:243739434659,98:d1d2d3d5d9da,6bb35f406bc289f365909f5165:93bcc6c4c3ccced2d6,70:809c969dbbc0b7abb1e8ca,71:1013162f31735c6845724a787a98b3b5a8a0e0d4e7f9,72:1d28,706c71:1866b9,62:3e3d434849,79:3b4046495b5c535a6257606f677a858a9aa7b3,5f:d1d0,97:9e9fa1a2a4a5a6a7a8a9aaacaeb0b1b3b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3#e4e5e8eeeff0f1f2f4f7f8f9fafbfcfdfeff,98:000102030405060708090a0b0c0d0e,60:3c5d5a67415963ab,61:060d5da99dcbd1,620680:807f,6c:93f6,6dfc77:f6f8,78:0009171811,65ab78:2d1c1d393a3b1f3c252c23294e6d56572650474c6a9b939a879ca1a3b2b9a5d4d9c9ecf2,790578f479:13241e34,9f9b9e:f9fbfc,76f177:040d,76f977:07081a22192d263538505147435a68,98:0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d#4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e,77:62657f8d7d808c919fa0b0b5bd,75:3a404e4b485b727983,7f:58615f,8a487f:68747179817e,76:cde5,883294:8586878b8a8c8d8f909497959a9b9ca3a4abaaadacafb0b2b4b6b7b8b9babcbdbfc4c8c9cacbcccdced0d1d2d5d6d7d9d8dbdedfe0e2e4e5e7e8ea,98:6f70717273748b8e929599a3a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcfd0d4d6d7dbdcdde0e1e2e3e4#e5e6e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,99:0001020304050607,94:e9ebeeeff3f4f5f7f9fcfdff,95:03020607090a0d0e0f1213141516181b1d1e1f222a2b292c3132343637383c3e3f4235444546494c4e4f525354565758595b5e5f5d61626465666768696a6b6c6f7172733a,77:e7ec,96c979:d5ede3eb,7a065d477a:03021e14,99:08090a0b0c0e0f1112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2f303132333435363738393a3b3c3d3e3f40414243444546474849#4a4b4c4d4e4f50515253565758595a5b5c5d5e5f60616264667378797b7e828389,7a:393751,9ecf99a57a7076:888e9399a4,74:dee0,752c9e:202228292a2b2c3231363837393a3e414244464748494b4c4e5155575a5b5c5e63666768696a6b6c716d73,75:929496a09daca3b3b4b8c4b1b0c3c2d6cde3e8e6e4ebe7,760375:f1fcff,76:1000050c170a25181519,99:8c8e9a9b9c9d9e9fa0a1a2a3a4a6a7a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8#d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9,76:1b3c2220402d303f35433e334d5e545c566b6f,7fca7a:e6787980868895a6a0aca8adb3,88:6469727d7f82a2c6b7bcc9e2cee3e5f1,891a88:fce8fef0,89:2119131b0a342b3641667b,758b80e576:b2b4,77dc80:1214161c20222526272928310b3543464d526971,898398:788083,99:fafbfcfdfeff,9a:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738#393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253545556575859,98:898c8d8f949a9b9e9fa1a2a5a6,86:4d546c6e7f7a7c7ba88d8bac9da7a3aa93a9b6c4b5ceb0bab1afc9cfb4e9f1f2edf3d0,871386:def4dfd8d1,87:0307,86f887:080a0d09233b1e252e1a3e48343129373f82227d7e7b60704c6e8b53637c64596593afa8d2,9a:5a5b5c5d5e5f606162636465666768696a6b7283898d8e949599a6a9aaabacadaeafb2b3b4b5b9bbbdbebfc3c4c6c7c8c9cacdcecfd0d2d4d5d6d7d9dadbdc#dddee0e2e3e4e5e7e8e9eaeceef0f1f2f3f4f5f6f7f8fafcfdfeff,9b:000102040506,87:c68885ad9783abe5acb5b3cbd3bdd1c0cadbeae0ee,88:1613,87fe88:0a1b21393c,7f:36424445,82107a:fafd,7b:080304150a2b0f47382a192e31202524333e1e585a45754c5d606e7b62727190a6a7b8ac9da885aa9ca2abb4d1c1ccdddae5e6ea,7c0c7b:fefc,7c:0f160b,9b:07090a0b0c0d0e1011121415161718191a1b1c1d1e2021222425262728292a2b2c2d2e3031333435363738393a3d3e3f40464a4b4c4e50525355565758595a#5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b,7c:1f2a26384140,81fe82:010204,81ec884482:2122232d2f282b383b33343e44494b4f5a5f68,88:7e8588d8df,895e7f:9d9fa7afb0b2,7c7c65497c:919d9c9ea2b2bcbdc1c7cccdc8c5d7e8,826e66a87f:bfced5e5e1e6e9eef3,7cf87d:77a6ae,7e:479b,9e:b8b4,8d:73849491b1676d,8c:4749,91:4a504e4f64,9b:7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9ba#bbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadb,91:626170696f7d7e7274798c85908d91a2a3aaadaeafb5b4ba,8c559e7e8d:b8eb,8e:055969,8d:b5bfbcbac4d6d7dadececfdbc6ecf7f8e3f9fbe4,8e098dfd8e:141d1f2c2e232f3a4039353d3149414251524a70767c6f74858f94909c9e,8c:78828a859894,659b89:d6dedadc,9b:dcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,9c:000102030405060708090a0b0c0d0e0f101112131415161718191a#1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b,89:e5ebef,8a3e8b26975396:e9f3ef,97:0601080f0e2a2d303e,9f:808385868788898a8c,9efe9f:0b0d,96:b9bcbdced2,77bf96e092:8eaec8,93:3e6aca8f,94:3e6b,9c:7f8285868788,7a239c:8b8e90919294959a9b9e9fa0a1a2a3a5a6a7a8a9abadaeb0b1b2b3b4b5b6b7babbbcbdc4c5c6c7cacb3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a#7b7d7e808384898a8c8f93969798999daaacafb9bebfc0c1c2c8c9d1d2dadbe0e1cccdcecfd0d3d4d5d7d8d9dcdddfe2,97:7c85919294afaba3b2b4,9a:b1b0b7,9e589a:b6babcc1c0c5c2cbccd1,9b:45434749484d51,98e899:0d2e5554,9a:dfe1e6efebfbedf9,9b:080f131f23,9e:bdbe,7e3b9e:8287888b92,93d69e:9d9fdbdcdde0dfe2e9e7e5eaef,9f:222c2f39373d3e44,9c:e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,9d:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021#22232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142#92$434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081#82838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2#92$a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1#e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff,9e:000102#92$030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e24272e30343b3c404d5052535456595d5f606162656e6f727475767778797a7b7c7d80#8183848586898a8c8d8e8f90919495969798999a9b9c9ea0a1a2a3a4a5a7a8a9aa#92$abacadaeafb0b1b2b3b5b6b7b9babcbfc0c1c2c3c5c6c7c8cacbccd0d2d3d5d6d7d9dadee1e3e4e6e8ebecedeef0f1f2f3f4f5f6f7f8fafdff,9f:000102030405#060708090a0c0f1112141516181a1b1c1d1e1f21232425262728292a2b2d2e3031#92$3233343536383a3c3f4041424345464748494a4b4c4d4e4f52535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778#797a7b7c7d7e81828d8e8f9091929394959697989c9d9ea1a2a3a4a5,f9:2c7995e7f1#92$,fa:0c0d0e0f111314181f20212324272829,e8:15161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243#4445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364");
  135. let index = 0;
  136. this.#data = dataText.match(/..../g);
  137. for (let i = 0x81; i <= 0xfe; i++) {
  138. for (let j = 0x40; j <= 0xfe; j++) {
  139. this.#U2Ghash[this.#data[index++]] = ("%" +
  140. i.toString(16) +
  141. "%" +
  142. j.toString(16)).toUpperCase();
  143. }
  144. }
  145. for (let key in this.#U2Ghash) {
  146. this.#G2Uhash[this.#U2Ghash[key]] = key;
  147. }
  148. }
  149. handleText(text) {
  150. text = text
  151. .replace(/#(\d+)\$/g, function (a, b) {
  152. return Array(+b + 3).join("#");
  153. })
  154. .replace(/#/g, "####")
  155. .replace(/(\w\w):([\w#]+)(?:,|$)/g, function (a, hd, dt) {
  156. return dt.replace(/../g, function (a) {
  157. if (a != "##") {
  158. return hd + a;
  159. }
  160. else {
  161. return a;
  162. }
  163. });
  164. });
  165. return text;
  166. }
  167. isAscii(unicode) {
  168. return unicode <= 0x007f && unicode >= 0x0000;
  169. }
  170. /**
  171. * 编码
  172. * @param str
  173. */
  174. encode(str) {
  175. let that = this;
  176. return [...str].reduce((result, val, i) => {
  177. return result + toGBK(val);
  178. }, "");
  179. function toGBK(val) {
  180. let result = "";
  181. for (let i = 0; i < val.length; i++) {
  182. const codePoint = val.codePointAt(i);
  183. const code = String.fromCodePoint(codePoint);
  184. let key = codePoint.toString(16);
  185. key.length != 4 && (key = ("000" + key).match(/....$/)?.[0]);
  186. /* Add up i by code.length */
  187. i += code.length - 1;
  188. /* If code is in ascii range */
  189. if (that.isAscii(codePoint)) {
  190. result += encodeURIComponent(code);
  191. continue;
  192. }
  193. /* If Got encoded string from U2Ghash */
  194. if (that.#U2Ghash[key]) {
  195. result += that.#U2Ghash[key];
  196. continue;
  197. }
  198. /*
  199. If 2 or more char combines to one visible code,
  200. or just this code is not in GBK
  201. */
  202. result += toGBK(`&#${codePoint};`);
  203. }
  204. return result;
  205. }
  206. }
  207. /**
  208. * 解码
  209. * @param str
  210. */
  211. decode(str) {
  212. var GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
  213. var UTFMatcher = /%[0-9A-F]{2}/;
  214. // @ts-ignore
  215. var utf = true;
  216. let that = this;
  217. while (utf) {
  218. let gbkMatch = str.match(GBKMatcher);
  219. let utfMatch = str.match(UTFMatcher);
  220. utf = Boolean(utfMatch);
  221. if (gbkMatch && gbkMatch in that.#G2Uhash) {
  222. str = str.replace(gbkMatch, String.fromCharCode(("0x" + that.#G2Uhash[gbkMatch])));
  223. }
  224. else {
  225. // @ts-ignore
  226. str = str.replace(utfMatch, decodeURIComponent(utfMatch));
  227. }
  228. }
  229. return str;
  230. }
  231. }
  232.  
  233. class UtilsGMCookie {
  234. windowApi = {
  235. window: window,
  236. document: document,
  237. };
  238. constructor(windowApiOption) {
  239. if (windowApiOption) {
  240. this.windowApi = Object.assign({}, windowApiOption);
  241. }
  242. }
  243. /**
  244. * 获取单个cookie
  245. * @param cookieName cookie名
  246. */
  247. get(cookieName) {
  248. if (typeof cookieName !== "string") {
  249. throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
  250. }
  251. let cookies = this.windowApi.document.cookie.split(";");
  252. let findValue = void 0;
  253. for (const cookieItem of cookies) {
  254. let item = cookieItem.trim();
  255. let itemSplit = item.split("=");
  256. let itemName = itemSplit[0];
  257. itemSplit.splice(0, 1);
  258. let itemValue = decodeURIComponent(itemSplit.join(""));
  259. if (itemName === cookieName) {
  260. findValue = {
  261. domain: this.windowApi.window.location.hostname,
  262. expirationDate: null,
  263. hostOnly: true,
  264. httpOnly: false,
  265. name: cookieName,
  266. path: "/",
  267. sameSite: "unspecified",
  268. secure: true,
  269. session: false,
  270. value: itemValue,
  271. };
  272. break;
  273. }
  274. }
  275. return findValue;
  276. }
  277. /**
  278. * 获取多组Cookie
  279. * @param paramDetails 配置
  280. * @param callback 获取操作后的回调
  281. * + cookies object[]
  282. * + error string|undefined
  283. **/
  284. list(paramDetails, callback) {
  285. if (paramDetails == null) {
  286. throw new Error("Utils.GMCookie.list 参数不能为空");
  287. }
  288. let resultData = [];
  289. try {
  290. let details = {
  291. url: this.windowApi.window.location.href,
  292. domain: this.windowApi.window.location.hostname,
  293. name: "",
  294. path: "/",
  295. };
  296. details = utils.assign(details, paramDetails);
  297. let cookies = this.windowApi.document.cookie.split(";");
  298. cookies.forEach((item) => {
  299. item = item.trim();
  300. let itemSplit = item.split("=");
  301. let itemName = itemSplit[0];
  302. itemSplit.splice(0, 1);
  303. let itemValue = decodeURIComponent(itemSplit.join(""));
  304. let nameRegexp = details.name instanceof RegExp
  305. ? details.name
  306. : new RegExp("^" + details.name, "g");
  307. if (itemName.match(nameRegexp)) {
  308. resultData.push({
  309. domain: this.windowApi.window.location.hostname,
  310. expirationDate: null,
  311. hostOnly: true,
  312. httpOnly: false,
  313. name: itemName,
  314. path: "/",
  315. sameSite: "unspecified",
  316. secure: true,
  317. session: false,
  318. value: itemValue,
  319. });
  320. }
  321. });
  322. if (typeof callback === "function") {
  323. callback(resultData);
  324. }
  325. }
  326. catch (error) {
  327. if (typeof callback === "function") {
  328. callback(resultData, error);
  329. }
  330. }
  331. }
  332. /**
  333. * 获取多组Cookie
  334. * @param paramDetails 配置
  335. **/
  336. getList(paramDetails) {
  337. if (paramDetails == null) {
  338. throw new Error("Utils.GMCookie.list 参数不能为空");
  339. }
  340. let resultData = [];
  341. let details = {
  342. url: this.windowApi.window.location.href,
  343. domain: this.windowApi.window.location.hostname,
  344. name: "",
  345. path: "/",
  346. };
  347. details = utils.assign(details, paramDetails);
  348. let cookies = this.windowApi.document.cookie.split(";");
  349. cookies.forEach((item) => {
  350. item = item.trim();
  351. let itemSplit = item.split("=");
  352. let itemName = itemSplit[0];
  353. itemSplit.splice(0, 1);
  354. let itemValue = decodeURIComponent(itemSplit.join(""));
  355. let nameRegexp = details.name instanceof RegExp
  356. ? details.name
  357. : new RegExp("^" + details.name, "g");
  358. if (itemName.match(nameRegexp)) {
  359. resultData.push({
  360. domain: this.windowApi.window.location.hostname,
  361. expirationDate: null,
  362. hostOnly: true,
  363. httpOnly: false,
  364. name: itemName,
  365. path: "/",
  366. sameSite: "unspecified",
  367. secure: true,
  368. session: false,
  369. value: itemValue,
  370. });
  371. }
  372. });
  373. return resultData;
  374. }
  375. /**
  376. * 设置Cookie
  377. * @param paramDetails 配置
  378. * @param callback 设置操作后的回调(成功/失败)
  379. */
  380. set(paramDetails, callback = (error) => { }) {
  381. try {
  382. let details = {
  383. url: this.windowApi.window.location.href,
  384. name: "",
  385. value: "",
  386. domain: this.windowApi.window.location.hostname,
  387. path: "/",
  388. secure: true,
  389. httpOnly: false,
  390. /**
  391. * Expires in 30 days
  392. */
  393. expirationDate: Math.floor(Date.now()) + 60 * 60 * 24 * 30,
  394. };
  395. details = utils.assign(details, paramDetails);
  396. let life = details.expirationDate
  397. ? details.expirationDate
  398. : Math.floor(Date.now()) + 60 * 60 * 24 * 30;
  399. let cookieStr = details.name +
  400. "=" +
  401. decodeURIComponent(details.value) +
  402. ";expires=" +
  403. new Date(life).toGMTString() +
  404. "; path=/";
  405. this.windowApi.document.cookie = cookieStr;
  406. callback();
  407. }
  408. catch (error) {
  409. callback(error);
  410. }
  411. }
  412. /**
  413. * 删除Cookie
  414. * @param paramDetails 配置
  415. * @param callback 删除操作后的回调(成功/失败)
  416. */
  417. delete(paramDetails, callback = (error) => { }) {
  418. try {
  419. let details = {
  420. url: this.windowApi.window.location.href,
  421. name: "",
  422. // @ts-ignore
  423. firstPartyDomain: "",
  424. };
  425. details = utils.assign(details, paramDetails);
  426. let cookieStr = details.name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
  427. this.windowApi.document.cookie = cookieStr;
  428. callback();
  429. }
  430. catch (error) {
  431. callback(error);
  432. }
  433. }
  434. }
  435.  
  436. // @name ajaxHooker
  437. // @author cxxjackie
  438. // @version 1.4.3
  439. // @updateLog 修复特殊情况下有部分请求头丢失的问题。
  440. // @updateLog xhr事件增加currentTarget劫持。
  441. // @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
  442.  
  443. const AjaxHooker = function () {
  444. return (function () {
  445. const version = "1.4.3";
  446. const hookInst = {
  447. hookFns: [],
  448. filters: [],
  449. };
  450. const win = window.unsafeWindow || document.defaultView || window;
  451. let winAh = win.__ajaxHooker;
  452. const resProto = win.Response.prototype;
  453. const xhrResponses = ["response", "responseText", "responseXML"];
  454. const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
  455. const fetchInitProps = [
  456. "method",
  457. "headers",
  458. "body",
  459. "mode",
  460. "credentials",
  461. "cache",
  462. "redirect",
  463. "referrer",
  464. "referrerPolicy",
  465. "integrity",
  466. "keepalive",
  467. "signal",
  468. "priority",
  469. ];
  470. const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
  471. const getType = {}.toString.call.bind({}.toString);
  472. const getDescriptor = Object.getOwnPropertyDescriptor.bind(Object);
  473. const emptyFn = () => {};
  474. const errorFn = (e) => console.error(e);
  475. function isThenable(obj) {
  476. return (
  477. obj &&
  478. ["object", "function"].includes(typeof obj) &&
  479. typeof obj.then === "function"
  480. );
  481. }
  482. function catchError(fn, ...args) {
  483. try {
  484. const result = fn(...args);
  485. if (isThenable(result)) return result.then(null, errorFn);
  486. return result;
  487. } catch (err) {
  488. console.error(err);
  489. }
  490. }
  491. function defineProp(obj, prop, getter, setter) {
  492. Object.defineProperty(obj, prop, {
  493. configurable: true,
  494. enumerable: true,
  495. get: getter,
  496. set: setter,
  497. });
  498. }
  499. function readonly(obj, prop, value = obj[prop]) {
  500. defineProp(obj, prop, () => value, emptyFn);
  501. }
  502. function writable(obj, prop, value = obj[prop]) {
  503. Object.defineProperty(obj, prop, {
  504. configurable: true,
  505. enumerable: true,
  506. writable: true,
  507. value: value,
  508. });
  509. }
  510. function parseHeaders(obj) {
  511. const headers = {};
  512. switch (getType(obj)) {
  513. case "[object String]":
  514. for (const line of obj.trim().split(/[\r\n]+/)) {
  515. const [header, value] = line.split(/\s*:\s*/);
  516. if (!header) break;
  517. const lheader = header.toLowerCase();
  518. headers[lheader] =
  519. lheader in headers ? `${headers[lheader]}, ${value}` : value;
  520. }
  521. break;
  522. case "[object Headers]":
  523. for (const [key, val] of obj) {
  524. headers[key] = val;
  525. }
  526. break;
  527. case "[object Object]":
  528. return { ...obj };
  529. }
  530. return headers;
  531. }
  532. function stopImmediatePropagation() {
  533. this.ajaxHooker_isStopped = true;
  534. }
  535. class SyncThenable {
  536. then(fn) {
  537. fn && fn();
  538. return new SyncThenable();
  539. }
  540. }
  541. class AHRequest {
  542. constructor(request) {
  543. this.request = request;
  544. this.requestClone = { ...this.request };
  545. }
  546. shouldFilter(filters) {
  547. const { type, url, method, async } = this.request;
  548. return (
  549. filters.length &&
  550. !filters.find((obj) => {
  551. switch (true) {
  552. case obj.type && obj.type !== type:
  553. case getType(obj.url) === "[object String]" &&
  554. !url.includes(obj.url):
  555. case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
  556. case obj.method &&
  557. obj.method.toUpperCase() !== method.toUpperCase():
  558. case "async" in obj && obj.async !== async:
  559. return false;
  560. }
  561. return true;
  562. })
  563. );
  564. }
  565. waitForRequestKeys() {
  566. const requestKeys = ["url", "method", "abort", "headers", "data"];
  567. if (!this.request.async) {
  568. win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
  569. if (this.shouldFilter(filters)) return;
  570. hookFns.forEach((fn) => {
  571. if (getType(fn) === "[object Function]")
  572. catchError(fn, this.request);
  573. });
  574. requestKeys.forEach((key) => {
  575. if (isThenable(this.request[key]))
  576. this.request[key] = this.requestClone[key];
  577. });
  578. });
  579. return new SyncThenable();
  580. }
  581. const promises = [];
  582. win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
  583. if (this.shouldFilter(filters)) return;
  584. promises.push(
  585. Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
  586. () =>
  587. Promise.all(
  588. requestKeys.map((key) =>
  589. Promise.resolve(this.request[key]).then(
  590. (val) => (this.request[key] = val),
  591. () => (this.request[key] = this.requestClone[key])
  592. )
  593. )
  594. )
  595. )
  596. );
  597. });
  598. return Promise.all(promises);
  599. }
  600. waitForResponseKeys(response) {
  601. const responseKeys =
  602. this.request.type === "xhr" ? xhrResponses : fetchResponses;
  603. if (!this.request.async) {
  604. if (getType(this.request.response) === "[object Function]") {
  605. catchError(this.request.response, response);
  606. responseKeys.forEach((key) => {
  607. if (
  608. "get" in getDescriptor(response, key) ||
  609. isThenable(response[key])
  610. ) {
  611. delete response[key];
  612. }
  613. });
  614. }
  615. return new SyncThenable();
  616. }
  617. return Promise.resolve(
  618. catchError(this.request.response, response)
  619. ).then(() =>
  620. Promise.all(
  621. responseKeys.map((key) => {
  622. const descriptor = getDescriptor(response, key);
  623. if (descriptor && "value" in descriptor) {
  624. return Promise.resolve(descriptor.value).then(
  625. (val) => (response[key] = val),
  626. () => delete response[key]
  627. );
  628. } else {
  629. delete response[key];
  630. }
  631. })
  632. )
  633. );
  634. }
  635. }
  636. const proxyHandler = {
  637. get(target, prop) {
  638. const descriptor = getDescriptor(target, prop);
  639. if (
  640. descriptor &&
  641. !descriptor.configurable &&
  642. !descriptor.writable &&
  643. !descriptor.get
  644. )
  645. return target[prop];
  646. const ah = target.__ajaxHooker;
  647. if (ah && ah.proxyProps) {
  648. if (prop in ah.proxyProps) {
  649. const pDescriptor = ah.proxyProps[prop];
  650. if ("get" in pDescriptor) return pDescriptor.get();
  651. if (typeof pDescriptor.value === "function")
  652. return pDescriptor.value.bind(ah);
  653. return pDescriptor.value;
  654. }
  655. if (typeof target[prop] === "function")
  656. return target[prop].bind(target);
  657. }
  658. return target[prop];
  659. },
  660. set(target, prop, value) {
  661. const descriptor = getDescriptor(target, prop);
  662. if (
  663. descriptor &&
  664. !descriptor.configurable &&
  665. !descriptor.writable &&
  666. !descriptor.set
  667. )
  668. return true;
  669. const ah = target.__ajaxHooker;
  670. if (ah && ah.proxyProps && prop in ah.proxyProps) {
  671. const pDescriptor = ah.proxyProps[prop];
  672. pDescriptor.set
  673. ? pDescriptor.set(value)
  674. : (pDescriptor.value = value);
  675. } else {
  676. target[prop] = value;
  677. }
  678. return true;
  679. },
  680. };
  681. class XhrHooker {
  682. constructor(xhr) {
  683. const ah = this;
  684. Object.assign(ah, {
  685. originalXhr: xhr,
  686. proxyXhr: new Proxy(xhr, proxyHandler),
  687. resThenable: new SyncThenable(),
  688. proxyProps: {},
  689. proxyEvents: {},
  690. });
  691. xhr.addEventListener("readystatechange", (e) => {
  692. if (
  693. ah.proxyXhr.readyState === 4 &&
  694. ah.request &&
  695. typeof ah.request.response === "function"
  696. ) {
  697. const response = {
  698. finalUrl: ah.proxyXhr.responseURL,
  699. status: ah.proxyXhr.status,
  700. responseHeaders: parseHeaders(
  701. ah.proxyXhr.getAllResponseHeaders()
  702. ),
  703. };
  704. const tempValues = {};
  705. for (const key of xhrResponses) {
  706. try {
  707. tempValues[key] = ah.originalXhr[key];
  708. } catch (err) {}
  709. defineProp(
  710. response,
  711. key,
  712. () => {
  713. return (response[key] = tempValues[key]);
  714. },
  715. (val) => {
  716. delete response[key];
  717. response[key] = val;
  718. }
  719. );
  720. }
  721. ah.resThenable = new AHRequest(ah.request)
  722. .waitForResponseKeys(response)
  723. .then(() => {
  724. for (const key of xhrResponses) {
  725. ah.proxyProps[key] = {
  726. get: () => {
  727. if (!(key in response)) response[key] = tempValues[key];
  728. return response[key];
  729. },
  730. };
  731. }
  732. });
  733. }
  734. ah.dispatchEvent(e);
  735. });
  736. xhr.addEventListener("load", (e) => ah.dispatchEvent(e));
  737. xhr.addEventListener("loadend", (e) => ah.dispatchEvent(e));
  738. for (const evt of xhrAsyncEvents) {
  739. const onEvt = "on" + evt;
  740. ah.proxyProps[onEvt] = {
  741. get: () => ah.proxyEvents[onEvt] || null,
  742. set: (val) => ah.addEvent(onEvt, val),
  743. };
  744. }
  745. for (const method of [
  746. "setRequestHeader",
  747. "addEventListener",
  748. "removeEventListener",
  749. "open",
  750. "send",
  751. ]) {
  752. ah.proxyProps[method] = { value: ah[method] };
  753. }
  754. }
  755. toJSON() {} // Converting circular structure to JSON
  756. addEvent(type, event) {
  757. if (type.startsWith("on")) {
  758. this.proxyEvents[type] = typeof event === "function" ? event : null;
  759. } else {
  760. if (typeof event === "object" && event !== null)
  761. event = event.handleEvent;
  762. if (typeof event !== "function") return;
  763. this.proxyEvents[type] = this.proxyEvents[type] || new Set();
  764. this.proxyEvents[type].add(event);
  765. }
  766. }
  767. removeEvent(type, event) {
  768. if (type.startsWith("on")) {
  769. this.proxyEvents[type] = null;
  770. } else {
  771. if (typeof event === "object" && event !== null)
  772. event = event.handleEvent;
  773. this.proxyEvents[type] && this.proxyEvents[type].delete(event);
  774. }
  775. }
  776. dispatchEvent(e) {
  777. e.stopImmediatePropagation = stopImmediatePropagation;
  778. defineProp(e, "target", () => this.proxyXhr);
  779. defineProp(e, "currentTarget", () => this.proxyXhr);
  780. this.proxyEvents[e.type] &&
  781. this.proxyEvents[e.type].forEach((fn) => {
  782. this.resThenable.then(
  783. () => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e)
  784. );
  785. });
  786. if (e.ajaxHooker_isStopped) return;
  787. const onEvent = this.proxyEvents["on" + e.type];
  788. onEvent && this.resThenable.then(onEvent.bind(this.proxyXhr, e));
  789. }
  790. setRequestHeader(header, value) {
  791. this.originalXhr.setRequestHeader(header, value);
  792. if (!this.request) return;
  793. const headers = this.request.headers;
  794. headers[header] =
  795. header in headers ? `${headers[header]}, ${value}` : value;
  796. }
  797. addEventListener(...args) {
  798. if (xhrAsyncEvents.includes(args[0])) {
  799. this.addEvent(args[0], args[1]);
  800. } else {
  801. this.originalXhr.addEventListener(...args);
  802. }
  803. }
  804. removeEventListener(...args) {
  805. if (xhrAsyncEvents.includes(args[0])) {
  806. this.removeEvent(args[0], args[1]);
  807. } else {
  808. this.originalXhr.removeEventListener(...args);
  809. }
  810. }
  811. open(method, url, async = true, ...args) {
  812. this.request = {
  813. type: "xhr",
  814. url: url.toString(),
  815. method: method.toUpperCase(),
  816. abort: false,
  817. headers: {},
  818. data: null,
  819. response: null,
  820. async: !!async,
  821. };
  822. this.openArgs = args;
  823. this.resThenable = new SyncThenable();
  824. [
  825. "responseURL",
  826. "readyState",
  827. "status",
  828. "statusText",
  829. ...xhrResponses,
  830. ].forEach((key) => {
  831. delete this.proxyProps[key];
  832. });
  833. return this.originalXhr.open(method, url, async, ...args);
  834. }
  835. send(data) {
  836. const ah = this;
  837. const xhr = ah.originalXhr;
  838. const request = ah.request;
  839. if (!request) return xhr.send(data);
  840. request.data = data;
  841. new AHRequest(request).waitForRequestKeys().then(() => {
  842. if (request.abort) {
  843. if (typeof request.response === "function") {
  844. Object.assign(ah.proxyProps, {
  845. responseURL: { value: request.url },
  846. readyState: { value: 4 },
  847. status: { value: 200 },
  848. statusText: { value: "OK" },
  849. });
  850. xhrAsyncEvents.forEach((evt) =>
  851. xhr.dispatchEvent(new Event(evt))
  852. );
  853. }
  854. } else {
  855. xhr.open(
  856. request.method,
  857. request.url,
  858. request.async,
  859. ...ah.openArgs
  860. );
  861. for (const header in request.headers) {
  862. xhr.setRequestHeader(header, request.headers[header]);
  863. }
  864. xhr.send(request.data);
  865. }
  866. });
  867. }
  868. }
  869. function fakeXHR() {
  870. const xhr = new winAh.realXHR();
  871. if ("__ajaxHooker" in xhr)
  872. console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
  873. xhr.__ajaxHooker = new XhrHooker(xhr);
  874. return xhr.__ajaxHooker.proxyXhr;
  875. }
  876. fakeXHR.prototype = win.XMLHttpRequest.prototype;
  877. Object.keys(win.XMLHttpRequest).forEach(
  878. (key) => (fakeXHR[key] = win.XMLHttpRequest[key])
  879. );
  880. function fakeFetch(url, options = {}) {
  881. if (!url) return winAh.realFetch.call(win, url, options);
  882. return new Promise(async (resolve, reject) => {
  883. const init = {};
  884. if (getType(url) === "[object Request]") {
  885. for (const prop of fetchInitProps) init[prop] = url[prop];
  886. if (url.body) init.body = await url.arrayBuffer();
  887. url = url.url;
  888. }
  889. url = url.toString();
  890. Object.assign(init, options);
  891. init.method = init.method || "GET";
  892. init.headers = init.headers || {};
  893. const request = {
  894. type: "fetch",
  895. url: url,
  896. method: init.method.toUpperCase(),
  897. abort: false,
  898. headers: parseHeaders(init.headers),
  899. data: init.body,
  900. response: null,
  901. async: true,
  902. };
  903. const req = new AHRequest(request);
  904. await req.waitForRequestKeys();
  905. if (request.abort) {
  906. if (typeof request.response === "function") {
  907. const response = {
  908. finalUrl: request.url,
  909. status: 200,
  910. responseHeaders: {},
  911. };
  912. await req.waitForResponseKeys(response);
  913. const key = fetchResponses.find((k) => k in response);
  914. let val = response[key];
  915. if (key === "json" && typeof val === "object") {
  916. val = catchError(JSON.stringify.bind(JSON), val);
  917. }
  918. const res = new Response(val, {
  919. status: 200,
  920. statusText: "OK",
  921. });
  922. defineProp(res, "type", () => "basic");
  923. defineProp(res, "url", () => request.url);
  924. resolve(res);
  925. } else {
  926. reject(new DOMException("aborted", "AbortError"));
  927. }
  928. return;
  929. }
  930. init.method = request.method;
  931. init.headers = request.headers;
  932. init.body = request.data;
  933. winAh.realFetch.call(win, request.url, init).then((res) => {
  934. if (typeof request.response === "function") {
  935. const response = {
  936. finalUrl: res.url,
  937. status: res.status,
  938. responseHeaders: parseHeaders(res.headers),
  939. };
  940. fetchResponses.forEach(
  941. (key) =>
  942. (res[key] = function () {
  943. if (key in response) return Promise.resolve(response[key]);
  944. return resProto[key].call(this).then((val) => {
  945. response[key] = val;
  946. return req
  947. .waitForResponseKeys(response)
  948. .then(() => (key in response ? response[key] : val));
  949. });
  950. })
  951. );
  952. }
  953. resolve(res);
  954. }, reject);
  955. });
  956. }
  957. function fakeFetchClone() {
  958. const descriptors = Object.getOwnPropertyDescriptors(this);
  959. const res = winAh.realFetchClone.call(this);
  960. Object.defineProperties(res, descriptors);
  961. return res;
  962. }
  963. winAh = win.__ajaxHooker = winAh || {
  964. version,
  965. fakeXHR,
  966. fakeFetch,
  967. fakeFetchClone,
  968. realXHR: win.XMLHttpRequest,
  969. realFetch: win.fetch,
  970. realFetchClone: resProto.clone,
  971. hookInsts: new Set(),
  972. };
  973. if (winAh.version !== version)
  974. console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
  975. win.XMLHttpRequest = winAh.fakeXHR;
  976. win.fetch = winAh.fakeFetch;
  977. resProto.clone = winAh.fakeFetchClone;
  978. winAh.hookInsts.add(hookInst);
  979. return {
  980. hook: (fn) => hookInst.hookFns.push(fn),
  981. filter: (arr) => {
  982. if (Array.isArray(arr)) hookInst.filters = arr;
  983. },
  984. protect: () => {
  985. readonly(win, "XMLHttpRequest", winAh.fakeXHR);
  986. readonly(win, "fetch", winAh.fakeFetch);
  987. readonly(resProto, "clone", winAh.fakeFetchClone);
  988. },
  989. unhook: () => {
  990. winAh.hookInsts.delete(hookInst);
  991. if (!winAh.hookInsts.size) {
  992. writable(win, "XMLHttpRequest", winAh.realXHR);
  993. writable(win, "fetch", winAh.realFetch);
  994. writable(resProto, "clone", winAh.realFetchClone);
  995. delete win.__ajaxHooker;
  996. }
  997. },
  998. };
  999. })();
  1000. };
  1001.  
  1002. class GMMenu {
  1003. GM_Api = {
  1004. /**
  1005. * 获取存储的数据
  1006. */
  1007. getValue: null,
  1008. /**
  1009. * 设置数据到存储
  1010. */
  1011. setValue: null,
  1012. /**
  1013. * 注册(不可用)菜单
  1014. */
  1015. registerMenuCommand: null,
  1016. /**
  1017. * 卸载菜单
  1018. */
  1019. unregisterMenuCommand: null,
  1020. };
  1021. MenuHandle = {
  1022. context: this,
  1023. $data: {
  1024. /**
  1025. * 菜单数据
  1026. */
  1027. data: [],
  1028. /**
  1029. * 本地存储的键名
  1030. */
  1031. key: "GM_Menu_Local_Map",
  1032. },
  1033. $default: {
  1034. /** 自动刷新网页,默认为true */
  1035. autoReload: true,
  1036. /**
  1037. * 菜单isStoreValue的默认值
  1038. */
  1039. isStoreValue: true,
  1040. },
  1041. $emoji: {
  1042. /**
  1043. * 菜单enable为true的emoji
  1044. */
  1045. success: "✅",
  1046. /**
  1047. * 菜单enable为false的emoji
  1048. */
  1049. error: "❌",
  1050. },
  1051. /**
  1052. * 初始化数据
  1053. */
  1054. init() {
  1055. for (let index = 0; index < this.$data.data.length; index++) {
  1056. let menuOption = this.$data.data[index]["data"];
  1057. menuOption.enable = Boolean(this.getLocalMenuData(menuOption.key, menuOption.enable));
  1058. if (typeof menuOption.showText !== "function") {
  1059. menuOption.showText = (menuText, menuEnable) => {
  1060. if (menuEnable) {
  1061. return this.$emoji.success + " " + menuText;
  1062. }
  1063. else {
  1064. return this.$emoji.error + " " + menuText;
  1065. }
  1066. };
  1067. }
  1068. }
  1069. },
  1070. /**
  1071. * 注册(不可用)油猴菜单
  1072. * @param menuOptions 如果存在,使用它
  1073. */
  1074. register(menuOptions) {
  1075. let that = this;
  1076. if (menuOptions == null) {
  1077. throw new TypeError("register菜单数据不能为空");
  1078. }
  1079. if (!Array.isArray(menuOptions)) {
  1080. menuOptions = [menuOptions];
  1081. }
  1082. for (let index = 0; index < menuOptions.length; index++) {
  1083. let cloneMenuOptionData = utils.deepClone(menuOptions[index].data);
  1084. const { showText, clickCallBack } = this.handleMenuData(cloneMenuOptionData);
  1085. let menuId = that.context.GM_Api.registerMenuCommand(showText, clickCallBack);
  1086. menuOptions[index].id = menuId;
  1087. cloneMenuOptionData.deleteMenu = function () {
  1088. that.context.GM_Api.unregisterMenuCommand(menuId);
  1089. };
  1090. Reflect.deleteProperty(menuOptions[index], "handleData");
  1091. menuOptions[index].handleData = cloneMenuOptionData;
  1092. }
  1093. },
  1094. /**
  1095. * 获取本地存储菜单键值
  1096. * @param {string} key 键
  1097. */
  1098. getLocalMenuData(key, defaultValue) {
  1099. let localData = this.context.GM_Api.getValue(this.$data.key, {});
  1100. if (key in localData) {
  1101. return localData[key];
  1102. }
  1103. else {
  1104. return defaultValue;
  1105. }
  1106. },
  1107. /**
  1108. * 设置本地存储菜单键值
  1109. * @param key 键
  1110. * @param value 值
  1111. */
  1112. setLocalMenuData(key, value) {
  1113. let localData = this.context.GM_Api.getValue(this.$data.key, {});
  1114. localData[key] = value;
  1115. this.context.GM_Api.setValue(this.$data.key, localData);
  1116. },
  1117. /**
  1118. * 处理初始化配置
  1119. * @param menuOption
  1120. */
  1121. handleInitDetail(menuOption) {
  1122. menuOption.enable = Boolean(this.getLocalMenuData(menuOption.key, menuOption.enable));
  1123. if (typeof menuOption.showText !== "function") {
  1124. menuOption.showText = (menuText, menuEnable) => {
  1125. if (menuEnable) {
  1126. return this.$emoji.success + " " + menuText;
  1127. }
  1128. else {
  1129. return this.$emoji.error + " " + menuText;
  1130. }
  1131. };
  1132. }
  1133. return menuOption;
  1134. },
  1135. /**
  1136. * 对菜单数据进行处理
  1137. * @param menuOption
  1138. */
  1139. handleMenuData(menuOption) {
  1140. let that = this;
  1141. let menuLocalDataItemKey = menuOption.key;
  1142. /* 菜单默认开启的状态 */
  1143. let defaultEnable = Boolean(this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable));
  1144. /** 油猴菜单上显示的文本 */
  1145. let showText = menuOption.showText(menuOption.text, defaultEnable);
  1146. // @ts-ignore
  1147. ({
  1148. /**
  1149. * 菜单的id
  1150. */
  1151. id: menuOption.id,
  1152. /**
  1153. * 点击菜单项后是否应关闭弹出菜单
  1154. */
  1155. autoClose: menuOption.autoClose,
  1156. /**
  1157. * 菜单项的可选访问键
  1158. */
  1159. accessKey: menuOption.accessKey,
  1160. /**
  1161. * 菜单项的鼠标悬浮上的工具提示
  1162. */
  1163. title: menuOption.title,
  1164. });
  1165. /* 点击菜单后触发callback后的网页是否刷新 */
  1166. menuOption.autoReload =
  1167. typeof menuOption.autoReload !== "boolean"
  1168. ? this.$default.autoReload
  1169. : menuOption.autoReload;
  1170. /* 点击菜单后触发callback后的网页是否存储值 */
  1171. menuOption.isStoreValue =
  1172. typeof menuOption.isStoreValue !== "boolean"
  1173. ? this.$default.isStoreValue
  1174. : menuOption.isStoreValue;
  1175. /**
  1176. * 用户点击菜单后的回调函数
  1177. * @param event
  1178. */
  1179. function clickCallBack(event) {
  1180. let localEnable = Boolean(that.getLocalMenuData(menuLocalDataItemKey, defaultEnable));
  1181. if (menuOption.isStoreValue) {
  1182. that.setLocalMenuData(menuLocalDataItemKey, !localEnable);
  1183. }
  1184. if (typeof menuOption.callback === "function") {
  1185. menuOption.callback({
  1186. key: menuLocalDataItemKey,
  1187. enable: !localEnable,
  1188. oldEnable: localEnable,
  1189. event: event,
  1190. storeValue(value) {
  1191. that.setLocalMenuData(menuLocalDataItemKey, value);
  1192. },
  1193. });
  1194. }
  1195. /* 不刷新网页就刷新菜单 */
  1196. if (menuOption.autoReload) {
  1197. window.location.reload();
  1198. }
  1199. else {
  1200. that.context.update();
  1201. }
  1202. }
  1203. return {
  1204. showText,
  1205. clickCallBack,
  1206. };
  1207. },
  1208. /**
  1209. * 获取目标菜单配置数据
  1210. * @param menuKey 菜单-键key
  1211. */
  1212. getMenuData(menuKey) {
  1213. return this.$data.data.find((item) => item.data.key === menuKey);
  1214. },
  1215. /**
  1216. * 获取目标菜单配置
  1217. * @param menuKey 菜单-键key
  1218. */
  1219. getMenuOption(menuKey) {
  1220. return this.$data.data.find((item) => item.data.key === menuKey)?.data;
  1221. },
  1222. /**
  1223. * 获取目标菜单处理后的配置
  1224. * @param menuKey 菜单-键key
  1225. */
  1226. getMenuHandledOption(menuKey) {
  1227. return this.$data.data.find((item) => item.handleData.key === menuKey)
  1228. ?.handleData;
  1229. },
  1230. };
  1231. constructor(details) {
  1232. this.GM_Api.getValue = details.GM_getValue;
  1233. this.GM_Api.setValue = details.GM_setValue;
  1234. this.GM_Api.registerMenuCommand = details.GM_registerMenuCommand;
  1235. this.GM_Api.unregisterMenuCommand = details.GM_unregisterMenuCommand;
  1236. this.MenuHandle.$default.autoReload =
  1237. typeof details.autoReload === "boolean" ? details.autoReload : true;
  1238. for (const keyName of Object.keys(this.GM_Api)) {
  1239. if (typeof this.GM_Api[keyName] !== "function") {
  1240. throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
  1241. }
  1242. }
  1243. this.add(details?.data || []);
  1244. }
  1245. /**
  1246. * 新增菜单数据
  1247. * @param menuOption
  1248. */
  1249. __add(menuOption) {
  1250. if (Array.isArray(menuOption)) {
  1251. for (let index = 0; index < menuOption.length; index++) {
  1252. const option = menuOption[index];
  1253. this.MenuHandle.$data.data.push({
  1254. data: option,
  1255. id: void 0,
  1256. });
  1257. }
  1258. }
  1259. else {
  1260. this.MenuHandle.$data.data.push({
  1261. data: menuOption,
  1262. id: void 0,
  1263. });
  1264. }
  1265. }
  1266. /**
  1267. * 新增菜单数据
  1268. *
  1269. * 自动调用.update()
  1270. * @param menuOption
  1271. */
  1272. add(menuOption) {
  1273. this.__add(menuOption);
  1274. this.update();
  1275. }
  1276. /**
  1277. * 更新菜单数据
  1278. *
  1279. * 实现方式:先取消注册(不可用)所有已注册(不可用)的菜单、再依次注册(不可用)所有菜单项
  1280. *
  1281. * 如果菜单不存在,新增菜单项
  1282. *
  1283. * 如果菜单已存在,新菜单项覆盖旧的菜单项
  1284. * @param options 数据
  1285. */
  1286. update(options) {
  1287. let menuOptionList = [];
  1288. if (Array.isArray(options)) {
  1289. menuOptionList = [...menuOptionList, ...options];
  1290. }
  1291. else if (options != null) {
  1292. menuOptionList = [...menuOptionList, options];
  1293. }
  1294. menuOptionList.forEach((menuOption) => {
  1295. let oldMenuOption = this.MenuHandle.getMenuOption(menuOption.key);
  1296. if (oldMenuOption) {
  1297. // 覆盖
  1298. Object.assign(oldMenuOption, menuOption);
  1299. }
  1300. else {
  1301. this.__add(menuOption);
  1302. }
  1303. });
  1304. this.MenuHandle.$data.data.forEach((value) => {
  1305. if (value.handleData) {
  1306. value.handleData.deleteMenu();
  1307. }
  1308. });
  1309. this.MenuHandle.init();
  1310. this.MenuHandle.register(this.MenuHandle.$data.data);
  1311. }
  1312. /**
  1313. * 卸载菜单
  1314. * @param menuId 已注册(不可用)的菜单id
  1315. */
  1316. delete(menuId) {
  1317. this.GM_Api.unregisterMenuCommand(menuId);
  1318. }
  1319. /**
  1320. * 根据键值获取enable值
  1321. * @param menuKey 菜单-键key
  1322. * @deprecated
  1323. */
  1324. get(menuKey) {
  1325. return this.getEnable(menuKey);
  1326. }
  1327. /**
  1328. * 根据键值获取enable值
  1329. * @param menuKey 菜单-键key
  1330. */
  1331. getEnable(menuKey) {
  1332. return this.MenuHandle.getMenuHandledOption(menuKey).enable;
  1333. }
  1334. /**
  1335. * 根据键值获取text值
  1336. * @param menuKey 菜单-键key
  1337. */
  1338. getText(menuKey) {
  1339. return this.MenuHandle.getMenuHandledOption(menuKey).text;
  1340. }
  1341. /**
  1342. * 根据键值获取showText函数的值
  1343. * @param menuKey 菜单-键key
  1344. */
  1345. getShowTextValue(menuKey) {
  1346. return this.MenuHandle.getMenuHandledOption(menuKey).showText(this.getText(menuKey), this.getEnable(menuKey));
  1347. }
  1348. /**
  1349. * 获取当前已注册(不可用)菜单的id
  1350. * @param menuKey
  1351. */
  1352. getMenuId(menuKey) {
  1353. let result = null;
  1354. for (let index = 0; index < this.MenuHandle.$data.data.length; index++) {
  1355. const optionData = this.MenuHandle.$data.data[index];
  1356. if (optionData.handleData.key === menuKey) {
  1357. result = optionData.id;
  1358. break;
  1359. }
  1360. }
  1361. return result;
  1362. }
  1363. /**
  1364. * 根据键值获取accessKey值
  1365. * @param menuKey 菜单-键key
  1366. */
  1367. getAccessKey(menuKey) {
  1368. return this.MenuHandle.getMenuHandledOption(menuKey)?.accessKey;
  1369. }
  1370. /**
  1371. * 根据键值获取autoClose值
  1372. * @param menuKey 菜单-键key
  1373. */
  1374. getAutoClose(menuKey) {
  1375. return this.MenuHandle.getMenuHandledOption(menuKey)?.autoClose;
  1376. }
  1377. /**
  1378. * 根据键值获取autoReload值
  1379. * @param menuKey 菜单-键key
  1380. */
  1381. getAutoReload(menuKey) {
  1382. return this.MenuHandle.getMenuHandledOption(menuKey)?.autoReload;
  1383. }
  1384. /**
  1385. * 根据键值获取callback函数
  1386. * @param menuKey 菜单-键key
  1387. */
  1388. getCallBack(menuKey) {
  1389. return this.MenuHandle.getMenuHandledOption(menuKey)?.callback;
  1390. }
  1391. /**
  1392. * 获取当enable为true时默认显示在菜单中前面的emoji图标
  1393. */
  1394. getEnableTrueEmoji() {
  1395. return this.MenuHandle.$emoji.success;
  1396. }
  1397. /**
  1398. * 获取当enable为false时默认显示在菜单中前面的emoji图标
  1399. */
  1400. getEnableFalseEmoji() {
  1401. return this.MenuHandle.$emoji.error;
  1402. }
  1403. /**
  1404. * 获取本地存储的菜单外部的键名
  1405. * @param keyName
  1406. */
  1407. getLocalStorageKeyName() {
  1408. return this.MenuHandle.$data.key;
  1409. }
  1410. /**
  1411. * 设置菜单的值
  1412. * @param menuKey 菜单-键key
  1413. * @param value 需要设置的值
  1414. */
  1415. setValue(menuKey, value) {
  1416. this.MenuHandle.setLocalMenuData(menuKey, value);
  1417. }
  1418. /**
  1419. * 设置菜单的值
  1420. * @param menuKey 菜单-键key
  1421. * @param value 需要设置的值
  1422. */
  1423. setEnable(menuKey, value) {
  1424. this.setValue(menuKey, Boolean(value));
  1425. }
  1426. /**
  1427. * 设置当enable为true时默认显示在菜单中前面的emoji图标
  1428. * @param emojiString
  1429. */
  1430. setEnableTrueEmoji(emojiString) {
  1431. if (typeof emojiString !== "string") {
  1432. throw new Error("参数emojiString必须是string类型");
  1433. }
  1434. this.MenuHandle.$emoji.success = emojiString;
  1435. }
  1436. /**
  1437. * 设置当enable为false时默认显示在菜单中前面的emoji图标
  1438. * @param emojiString
  1439. */
  1440. setEnableFalseEmoji(emojiString) {
  1441. if (typeof emojiString !== "string") {
  1442. throw new Error("参数emojiString必须是string类型");
  1443. }
  1444. this.MenuHandle.$emoji.error = emojiString;
  1445. }
  1446. /**
  1447. * 设置本地存储的菜单外部的键名
  1448. * @param keyName
  1449. */
  1450. setLocalStorageKeyName(keyName) {
  1451. if (typeof keyName !== "string") {
  1452. throw new Error("参数keyName必须是string类型");
  1453. }
  1454. this.MenuHandle.$data.key = keyName;
  1455. }
  1456. }
  1457.  
  1458. class Hooks {
  1459. /**
  1460. * 在Function原型上添加自定义方法.hook和.unhook
  1461. */
  1462. initEnv() {
  1463. Function.prototype.hook = function (realFunc, hookFunc, context) {
  1464. let _context = null; //函数上下文
  1465. let _funcName = null; //函数名
  1466. _context = context || window;
  1467. _funcName = getFuncName(this);
  1468. _context["realFunc_" + _funcName] = this;
  1469. if (_context[_funcName].prototype &&
  1470. _context[_funcName].prototype.isHooked) {
  1471. console.log("Already has been hooked,unhook first");
  1472. return false;
  1473. }
  1474. function getFuncName(fn) {
  1475. // 获取函数名
  1476. let strFunc = fn.toString();
  1477. let _regex = /function\s+(\w+)\s*\(/;
  1478. let patten = strFunc.match(_regex);
  1479. if (patten) {
  1480. return patten[1];
  1481. }
  1482. return "";
  1483. }
  1484. try {
  1485. eval("_context[_funcName] = function " +
  1486. _funcName +
  1487. "(){\n" +
  1488. "let args = Array.prototype.slice.call(arguments,0);\n" +
  1489. "let obj = this;\n" +
  1490. "hookFunc.apply(obj,args);\n" +
  1491. "return _context['realFunc_" +
  1492. _funcName +
  1493. "'].apply(obj,args);\n" +
  1494. "};");
  1495. _context[_funcName].prototype.isHooked = true;
  1496. return true;
  1497. }
  1498. catch (e) {
  1499. console.log("Hook failed,check the params.");
  1500. return false;
  1501. }
  1502. };
  1503. Function.prototype.unhook = function (realFunc, funcName, context) {
  1504. let _context = null;
  1505. let _funcName = null;
  1506. _context = context || window;
  1507. _funcName = funcName;
  1508. if (!_context[_funcName].prototype.isHooked) {
  1509. console.log("No function is hooked on");
  1510. return false;
  1511. }
  1512. _context[_funcName] = _context["realFunc" + _funcName];
  1513. Reflect.deleteProperty(_context, "realFunc_" + _funcName);
  1514. return true;
  1515. };
  1516. }
  1517. /**
  1518. * 删除在Function原型上添加的自定义方法.hook和.unhook
  1519. */
  1520. cleanEnv() {
  1521. if (Function.prototype.hasOwnProperty("hook")) {
  1522. Reflect.deleteProperty(Function.prototype, "hook");
  1523. }
  1524. if (Function.prototype.hasOwnProperty("unhook")) {
  1525. Reflect.deleteProperty(Function.prototype, "unhook");
  1526. }
  1527. return true;
  1528. }
  1529. }
  1530.  
  1531. /**
  1532. * 生成uuid
  1533. */
  1534. const GenerateUUID = function () {
  1535. if (typeof window?.crypto?.randomUUID === "function") {
  1536. return window.crypto.randomUUID();
  1537. }
  1538. else {
  1539. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
  1540. var randomValue = (Math.random() * 16) | 0, randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
  1541. return randomCharValue.toString(16);
  1542. });
  1543. }
  1544. };
  1545.  
  1546. class Httpx {
  1547. GM_Api = {
  1548. xmlHttpRequest: null,
  1549. };
  1550. HttpxRequestHook = {
  1551. /**
  1552. * @private
  1553. */
  1554. $config: {
  1555. configList: [],
  1556. },
  1557. /**
  1558. * 发送请求前的回调
  1559. * 如果返回false则阻止本次返回
  1560. * @param details 当前的请求配置
  1561. * @private
  1562. */
  1563. async beforeRequestCallBack(details) {
  1564. if (typeof details.allowInterceptConfig === "boolean") {
  1565. if (!details.allowInterceptConfig) {
  1566. // 不允许拦截
  1567. return details;
  1568. }
  1569. }
  1570. else {
  1571. if (details.allowInterceptConfig != null) {
  1572. // 配置存在
  1573. // 细分处理是否拦截
  1574. if (typeof details.allowInterceptConfig.beforeRequest === "boolean" &&
  1575. !details.allowInterceptConfig.beforeRequest) {
  1576. // 设置了禁止拦截
  1577. return details;
  1578. }
  1579. }
  1580. }
  1581. for (let index = 0; index < this.$config.configList.length; index++) {
  1582. let item = this.$config.configList[index];
  1583. if (typeof item.fn === "function") {
  1584. let result = await item.fn(details);
  1585. if (result == null) {
  1586. return;
  1587. }
  1588. }
  1589. }
  1590. return details;
  1591. },
  1592. /**
  1593. * 添加请求前的回调处理配置
  1594. */
  1595. add(fn) {
  1596. if (typeof fn === "function") {
  1597. let uuid = GenerateUUID();
  1598. this.$config.configList.push({
  1599. id: uuid,
  1600. fn: fn,
  1601. });
  1602. return uuid;
  1603. }
  1604. else {
  1605. console.warn("[Httpx-HttpxRequestHook.addBeforeRequestCallBack] fn is not a function");
  1606. }
  1607. },
  1608. /**
  1609. * 删除请求前的回调处理配置
  1610. * @param id
  1611. */
  1612. delete(id) {
  1613. if (typeof id === "string") {
  1614. let findIndex = this.$config.configList.findIndex((item) => item.id === id);
  1615. if (findIndex !== -1) {
  1616. this.$config.configList.splice(findIndex, 1);
  1617. return true;
  1618. }
  1619. }
  1620. return false;
  1621. },
  1622. /**
  1623. * 清空设置的请求前的回调处理配置
  1624. */
  1625. clearAll() {
  1626. this.$config.configList = [];
  1627. },
  1628. };
  1629. HttpxResponseHook = {
  1630. /**
  1631. * @private
  1632. */
  1633. $config: {
  1634. configList: [],
  1635. },
  1636. /**
  1637. * 成功的回调
  1638. * @param response 响应
  1639. * @param details 请求的配置
  1640. */
  1641. async successResponseCallBack(response, details) {
  1642. if (typeof details.allowInterceptConfig === "boolean") {
  1643. if (!details.allowInterceptConfig) {
  1644. // 不允许拦截
  1645. return details;
  1646. }
  1647. }
  1648. else {
  1649. if (details.allowInterceptConfig != null) {
  1650. // 配置存在
  1651. // 细分处理是否拦截
  1652. if (typeof details.allowInterceptConfig.afterResponseSuccess ===
  1653. "boolean" &&
  1654. !details.allowInterceptConfig.afterResponseSuccess) {
  1655. // 设置了禁止拦截
  1656. return details;
  1657. }
  1658. }
  1659. }
  1660. for (let index = 0; index < this.$config.configList.length; index++) {
  1661. let item = this.$config.configList[index];
  1662. if (typeof item.successFn === "function") {
  1663. let result = await item.successFn(response, details);
  1664. if (result == null) {
  1665. return;
  1666. }
  1667. }
  1668. }
  1669. return response;
  1670. },
  1671. /**
  1672. * 失败的回调
  1673. * @param data 配置
  1674. * @returns
  1675. * 返回null|undefined就是拦截掉了
  1676. */
  1677. async errorResponseCallBack(data) {
  1678. if (typeof data.details.allowInterceptConfig === "boolean") {
  1679. if (!data.details.allowInterceptConfig) {
  1680. // 不允许拦截
  1681. return data;
  1682. }
  1683. }
  1684. else {
  1685. if (data.details.allowInterceptConfig != null) {
  1686. // 配置存在
  1687. // 细分处理是否拦截
  1688. if (typeof data.details.allowInterceptConfig.afterResponseError ===
  1689. "boolean" &&
  1690. !data.details.allowInterceptConfig.afterResponseError) {
  1691. // 设置了禁止拦截
  1692. return data;
  1693. }
  1694. }
  1695. }
  1696. for (let index = 0; index < this.$config.configList.length; index++) {
  1697. let item = this.$config.configList[index];
  1698. if (typeof item.errorFn === "function") {
  1699. let result = await item.errorFn(data);
  1700. if (result == null) {
  1701. return;
  1702. }
  1703. }
  1704. }
  1705. return data;
  1706. },
  1707. /**
  1708. * 添加请求前的回调处理配置
  1709. */
  1710. add(successFn, errorFn) {
  1711. let id = GenerateUUID();
  1712. this.$config.configList.push({
  1713. id: id,
  1714. successFn: successFn,
  1715. errorFn: errorFn,
  1716. });
  1717. return id;
  1718. },
  1719. /**
  1720. * 删除请求前的回调处理配置
  1721. * @param id
  1722. */
  1723. delete(id) {
  1724. if (typeof id === "string") {
  1725. let findIndex = this.$config.configList.findIndex((item) => item.id === id);
  1726. if (findIndex !== -1) {
  1727. this.$config.configList.splice(findIndex, 1);
  1728. return true;
  1729. }
  1730. }
  1731. return false;
  1732. },
  1733. /**
  1734. * 清空设置的请求前的回调处理配置
  1735. */
  1736. clearAll() {
  1737. this.$config.configList = [];
  1738. },
  1739. };
  1740. HttpxRequestOption = {
  1741. context: this,
  1742. /**
  1743. * 根据传入的参数处理获取details配置
  1744. */
  1745. handleBeforeRequestOption(...args) {
  1746. let option = {};
  1747. if (typeof args[0] === "string") {
  1748. /* 传入的是url,details? */
  1749. let url = args[0];
  1750. option.url = url;
  1751. if (typeof args[1] === "object") {
  1752. /* 处理第二个参数details */
  1753. let details = args[1];
  1754. option = details;
  1755. option.url = url;
  1756. }
  1757. }
  1758. else {
  1759. /* 传入的是details */
  1760. option = args[0];
  1761. }
  1762. return option;
  1763. },
  1764. /**
  1765. * 获取请求配置
  1766. * @param method 当前请求方法,默认get
  1767. * @param userRequestOption 用户的请求配置
  1768. * @param resolve promise回调
  1769. * @param reject 抛出错误回调
  1770. */
  1771. getRequestOption(method, userRequestOption, resolve, reject) {
  1772. let that = this;
  1773. let requestOption = {
  1774. url: userRequestOption.url || this.context.#defaultDetails.url,
  1775. method: (method || "GET").toString().toUpperCase(),
  1776. timeout: userRequestOption.timeout || this.context.#defaultDetails.timeout,
  1777. responseType: userRequestOption.responseType ||
  1778. this.context.#defaultDetails.responseType,
  1779. /* 对象使用深拷贝 */
  1780. headers: utils.deepClone(this.context.#defaultDetails.headers),
  1781. data: userRequestOption.data || this.context.#defaultDetails.data,
  1782. redirect: userRequestOption.redirect || this.context.#defaultDetails.redirect,
  1783. cookie: userRequestOption.cookie || this.context.#defaultDetails.cookie,
  1784. cookiePartition: userRequestOption.cookiePartition ||
  1785. this.context.#defaultDetails.cookiePartition,
  1786. binary: userRequestOption.binary || this.context.#defaultDetails.binary,
  1787. nocache: userRequestOption.nocache || this.context.#defaultDetails.nocache,
  1788. revalidate: userRequestOption.revalidate ||
  1789. this.context.#defaultDetails.revalidate,
  1790. /* 对象使用深拷贝 */
  1791. context: utils.deepClone(userRequestOption.context || this.context.#defaultDetails.context),
  1792. overrideMimeType: userRequestOption.overrideMimeType ||
  1793. this.context.#defaultDetails.overrideMimeType,
  1794. anonymous: userRequestOption.anonymous || this.context.#defaultDetails.anonymous,
  1795. fetch: userRequestOption.fetch || this.context.#defaultDetails.fetch,
  1796. /* 对象使用深拷贝 */
  1797. fetchInit: utils.deepClone(this.context.#defaultDetails.fetchInit),
  1798. allowInterceptConfig: {
  1799. beforeRequest: this.context.#defaultDetails
  1800. .allowInterceptConfig.beforeRequest,
  1801. afterResponseSuccess: this.context.#defaultDetails
  1802. .allowInterceptConfig.afterResponseSuccess,
  1803. afterResponseError: this.context.#defaultDetails
  1804. .allowInterceptConfig.afterResponseError,
  1805. },
  1806. user: userRequestOption.user || this.context.#defaultDetails.user,
  1807. password: userRequestOption.password || this.context.#defaultDetails.password,
  1808. onabort(...args) {
  1809. that.context.HttpxCallBack.onAbort(userRequestOption, resolve, reject, args);
  1810. },
  1811. onerror(...args) {
  1812. that.context.HttpxCallBack.onError(userRequestOption, resolve, reject, args);
  1813. },
  1814. onloadstart(...args) {
  1815. that.context.HttpxCallBack.onLoadStart(userRequestOption, args);
  1816. },
  1817. onprogress(...args) {
  1818. that.context.HttpxCallBack.onProgress(userRequestOption, args);
  1819. },
  1820. onreadystatechange(...args) {
  1821. that.context.HttpxCallBack.onReadyStateChange(userRequestOption, args);
  1822. },
  1823. ontimeout(...args) {
  1824. that.context.HttpxCallBack.onTimeout(userRequestOption, resolve, reject, args);
  1825. },
  1826. onload(...args) {
  1827. that.context.HttpxCallBack.onLoad(userRequestOption, resolve, reject, args);
  1828. },
  1829. };
  1830. // 补全allowInterceptConfig参数
  1831. if (typeof userRequestOption.allowInterceptConfig === "boolean") {
  1832. Object.keys(requestOption.allowInterceptConfig).forEach((keyName) => {
  1833. Reflect.set(requestOption.allowInterceptConfig, keyName, userRequestOption.allowInterceptConfig);
  1834. });
  1835. }
  1836. else {
  1837. if (typeof userRequestOption.allowInterceptConfig === "object" &&
  1838. userRequestOption.allowInterceptConfig != null) {
  1839. Object.keys(userRequestOption.allowInterceptConfig).forEach((keyName) => {
  1840. let value = Reflect.get(userRequestOption.allowInterceptConfig, keyName);
  1841. if (typeof value === "boolean" &&
  1842. Reflect.has(requestOption.allowInterceptConfig, keyName)) {
  1843. Reflect.set(requestOption.allowInterceptConfig, keyName, value);
  1844. }
  1845. });
  1846. }
  1847. }
  1848. if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
  1849. // GM函数不存在,强制使用fetch
  1850. requestOption.fetch = true;
  1851. }
  1852. if (typeof requestOption.headers === "object") {
  1853. if (typeof userRequestOption.headers === "object") {
  1854. Object.keys(userRequestOption.headers).forEach((keyName, index) => {
  1855. if (keyName in requestOption.headers &&
  1856. userRequestOption.headers?.[keyName] == null) {
  1857. /* 在默认的header中存在,且设置它新的值为空,那么就是默认的值 */
  1858. Reflect.deleteProperty(requestOption.headers, keyName);
  1859. }
  1860. else {
  1861. requestOption.headers[keyName] =
  1862. userRequestOption?.headers?.[keyName];
  1863. }
  1864. });
  1865. }
  1866. }
  1867. else {
  1868. /* 默认的headers不是对象,那么就直接使用新的 */
  1869. Reflect.set(requestOption, "headers", userRequestOption.headers);
  1870. }
  1871. if (typeof requestOption.fetchInit === "object") {
  1872. /* 使用assign替换且添加 */
  1873. if (typeof userRequestOption.fetchInit === "object") {
  1874. Object.keys(userRequestOption.fetchInit).forEach((keyName, index) => {
  1875. if (keyName in requestOption.fetchInit &&
  1876. userRequestOption.fetchInit[keyName] == null) {
  1877. /* 在默认的fetchInit中存在,且设置它新的值为空,那么就是默认的值 */
  1878. Reflect.deleteProperty(requestOption.fetchInit, keyName);
  1879. }
  1880. else {
  1881. Reflect.set(requestOption.fetchInit, keyName, Reflect.get(userRequestOption.fetchInit, keyName));
  1882. }
  1883. });
  1884. }
  1885. }
  1886. else {
  1887. Reflect.set(requestOption, "fetchInit", userRequestOption.fetchInit);
  1888. }
  1889. // 处理新的cookiePartition
  1890. if (typeof requestOption.cookiePartition === "object" &&
  1891. requestOption.cookiePartition != null) {
  1892. if (Reflect.has(requestOption.cookiePartition, "topLevelSite") &&
  1893. typeof requestOption.cookiePartition.topLevelSite !== "string") {
  1894. // topLevelSite必须是字符串
  1895. Reflect.deleteProperty(requestOption.cookiePartition, "topLevelSite");
  1896. }
  1897. }
  1898. /* 完善请求的url */
  1899. try {
  1900. new URL(requestOption.url);
  1901. }
  1902. catch (error) {
  1903. if (requestOption.url.startsWith("//")) {
  1904. // 补充https:
  1905. requestOption.url = globalThis.location.protocol + requestOption.url;
  1906. }
  1907. else if (requestOption.url.startsWith("/")) {
  1908. // 补充origin
  1909. requestOption.url = globalThis.location.origin + requestOption.url;
  1910. }
  1911. else {
  1912. // 补充origin+/
  1913. requestOption.url =
  1914. globalThis.location.origin + "/" + requestOption.url;
  1915. }
  1916. }
  1917. if (requestOption.fetchInit && !requestOption.fetch) {
  1918. // 清空fetchInit
  1919. Reflect.deleteProperty(requestOption, "fetchInit");
  1920. }
  1921. // 转换data类型
  1922. try {
  1923. /** 是否对数据进行处理 */
  1924. let processData = userRequestOption.processData ?? true;
  1925. if (requestOption.data != null && processData) {
  1926. let method = requestOption.method;
  1927. if (method === "GET" || method === "HEAD") {
  1928. // GET类型,data如果有,那么需要转为searchParams
  1929. let urlObj = new URL(requestOption.url);
  1930. let urlSearch = "";
  1931. if (typeof requestOption.data === "string") {
  1932. urlSearch = requestOption.data;
  1933. }
  1934. else if (typeof requestOption.data === "object") {
  1935. // URLSearchParams参数可以转普通的string:string,包括FormData
  1936. // @ts-ignore
  1937. let searchParams = new URLSearchParams(requestOption.data);
  1938. urlSearch = searchParams.toString();
  1939. }
  1940. if (urlSearch != "") {
  1941. if (urlObj.search === "") {
  1942. // url没有search参数,直接覆盖
  1943. urlObj.search = urlSearch;
  1944. }
  1945. else {
  1946. // 有search参数
  1947. if (urlObj.search.endsWith("&")) {
  1948. // xxx=xxx&
  1949. urlObj.search = urlObj.search + urlSearch;
  1950. }
  1951. else {
  1952. // xxx=xxx&xxx=
  1953. urlObj.search = urlObj.search + "&" + urlSearch;
  1954. }
  1955. }
  1956. }
  1957. requestOption.url = urlObj.toString();
  1958. }
  1959. else if (method === "POST" && requestOption.headers != null) {
  1960. // POST类型,data如果是FormData,那么需要转为string
  1961. let headersKeyList = Object.keys(requestOption.headers);
  1962. let ContentTypeIndex = headersKeyList.findIndex((headerKey) => {
  1963. return (headerKey.trim().toLowerCase() === "content-type" &&
  1964. typeof requestOption.headers[headerKey] === "string");
  1965. });
  1966. if (ContentTypeIndex !== -1) {
  1967. let ContentTypeKey = headersKeyList[ContentTypeIndex];
  1968. let ContentType = requestOption.headers[ContentTypeKey];
  1969. // 设置了Content-Type
  1970. if (ContentType.includes("application/json")) {
  1971. // application/json
  1972. if (requestOption.data instanceof FormData) {
  1973. const entries = {};
  1974. requestOption.data.forEach((value, key) => {
  1975. entries[key] = value;
  1976. });
  1977. requestOption.data = JSON.stringify(entries);
  1978. }
  1979. else if (typeof requestOption.data === "object") {
  1980. requestOption.data = JSON.stringify(requestOption.data);
  1981. }
  1982. }
  1983. else if (ContentType.includes("application/x-www-form-urlencoded")) {
  1984. // application/x-www-form-urlencoded
  1985. if (typeof requestOption.data === "object") {
  1986. requestOption.data = new URLSearchParams(
  1987. // @ts-ignore
  1988. requestOption.data).toString();
  1989. }
  1990. }
  1991. else if (ContentType.includes("multipart/form-data")) {
  1992. // multipart/form-data
  1993. if (requestOption.data instanceof FormData) {
  1994. Reflect.deleteProperty(requestOption.headers, ContentTypeKey);
  1995. }
  1996. }
  1997. }
  1998. }
  1999. }
  2000. }
  2001. catch (error) {
  2002. console.warn("Httpx ==> 转换data参数错误", error);
  2003. }
  2004. return requestOption;
  2005. },
  2006. /**
  2007. * 处理发送请求的配置,去除值为undefined、空function的值
  2008. * @param option
  2009. */
  2010. removeRequestNullOption(option) {
  2011. Object.keys(option).forEach((keyName) => {
  2012. if (option[keyName] == null ||
  2013. (option[keyName] instanceof Function &&
  2014. utils.isNull(option[keyName]))) {
  2015. Reflect.deleteProperty(option, keyName);
  2016. return;
  2017. }
  2018. });
  2019. if (utils.isNull(option.url)) {
  2020. throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
  2021. }
  2022. return option;
  2023. },
  2024. /**
  2025. * 处理fetch的配置
  2026. * @param option
  2027. */
  2028. handleFetchOption(option) {
  2029. /**
  2030. * fetch的请求配置
  2031. **/
  2032. let fetchRequestOption = {};
  2033. if ((option.method === "GET" || option.method === "HEAD") &&
  2034. option.data != null) {
  2035. /* GET 或 HEAD 方法的请求不能包含 body 信息 */
  2036. Reflect.deleteProperty(option, "data");
  2037. }
  2038. /* 中止信号控制器 */
  2039. let abortController = new AbortController();
  2040. let signal = abortController.signal;
  2041. signal.onabort = () => {
  2042. option.onabort({
  2043. isFetch: true,
  2044. responseText: "",
  2045. response: null,
  2046. readyState: 4,
  2047. responseHeaders: "",
  2048. status: 0,
  2049. statusText: "",
  2050. error: "aborted",
  2051. });
  2052. };
  2053. // 设置请求
  2054. fetchRequestOption.method = option.method ?? "GET";
  2055. // 设置请求头
  2056. fetchRequestOption.headers = option.headers;
  2057. // 设置请求体
  2058. fetchRequestOption.body = option.data;
  2059. // 设置跨域
  2060. fetchRequestOption.mode = "cors";
  2061. // 设置包含
  2062. fetchRequestOption.credentials = "include";
  2063. // 设置不缓存
  2064. fetchRequestOption.cache = "no-cache";
  2065. // 设置始终重定向
  2066. fetchRequestOption.redirect = "follow";
  2067. // 设置referer跨域
  2068. fetchRequestOption.referrerPolicy = "origin-when-cross-origin";
  2069. // 设置信号中断
  2070. fetchRequestOption.signal = signal;
  2071. Object.assign(fetchRequestOption, option.fetchInit || {});
  2072. return {
  2073. fetchOption: option,
  2074. fetchRequestOption: fetchRequestOption,
  2075. abortController: abortController,
  2076. };
  2077. },
  2078. };
  2079. HttpxCallBack = {
  2080. context: this,
  2081. /**
  2082. * onabort请求被取消-触发
  2083. * @param details 配置
  2084. * @param resolve 回调
  2085. * @param reject 抛出错误
  2086. * @param argsResult 返回的参数列表
  2087. */
  2088. async onAbort(details, resolve, reject, argsResult) {
  2089. // console.log(argsResult);
  2090. if ("onabort" in details) {
  2091. details.onabort.apply(this, argsResult);
  2092. }
  2093. else if ("onabort" in this.context.#defaultDetails) {
  2094. this.context.#defaultDetails.onabort.apply(this, argsResult);
  2095. }
  2096. let response = argsResult;
  2097. if (response.length) {
  2098. response = response[0];
  2099. }
  2100. if ((await this.context.HttpxResponseHook.errorResponseCallBack({
  2101. type: "onabort",
  2102. error: new TypeError("request canceled"),
  2103. response: null,
  2104. details: details,
  2105. })) == null) {
  2106. // reject(new TypeError("response is intercept with onabort"));
  2107. return;
  2108. }
  2109. resolve({
  2110. data: response,
  2111. details: details,
  2112. msg: "请求被取消",
  2113. status: false,
  2114. statusCode: -1,
  2115. type: "onabort",
  2116. });
  2117. },
  2118. /**
  2119. * onerror请求异常-触发
  2120. * @param details 配置
  2121. * @param resolve 回调
  2122. * @param reject 抛出错误
  2123. * @param argsResult 返回的参数列表
  2124. */
  2125. async onError(details, resolve, reject, argsResult) {
  2126. // console.log(argsResult);
  2127. if ("onerror" in details) {
  2128. details.onerror.apply(this, argsResult);
  2129. }
  2130. else if ("onerror" in this.context.#defaultDetails) {
  2131. this.context.#defaultDetails.onerror.apply(this, argsResult);
  2132. }
  2133. let response = argsResult;
  2134. if (response.length) {
  2135. response = response[0];
  2136. }
  2137. if ((await this.context.HttpxResponseHook.errorResponseCallBack({
  2138. type: "onerror",
  2139. error: new TypeError("request error"),
  2140. response: response,
  2141. details: details,
  2142. })) == null) {
  2143. // reject(new TypeError("response is intercept with onerror"));
  2144. return;
  2145. }
  2146. resolve({
  2147. data: response,
  2148. details: details,
  2149. msg: "请求异常",
  2150. status: false,
  2151. statusCode: response["status"],
  2152. type: "onerror",
  2153. });
  2154. },
  2155. /**
  2156. * ontimeout请求超时-触发
  2157. * @param details 配置
  2158. * @param resolve 回调
  2159. * @param reject 抛出错误
  2160. * @param argsResult 返回的参数列表
  2161. */
  2162. async onTimeout(details, resolve, reject, argsResult) {
  2163. // console.log(argsResult);
  2164. if ("ontimeout" in details) {
  2165. details.ontimeout.apply(this, argsResult);
  2166. }
  2167. else if ("ontimeout" in this.context.#defaultDetails) {
  2168. this.context.#defaultDetails.ontimeout.apply(this, argsResult);
  2169. }
  2170. let response = argsResult;
  2171. if (response.length) {
  2172. response = response[0];
  2173. }
  2174. if ((await this.context.HttpxResponseHook.errorResponseCallBack({
  2175. type: "ontimeout",
  2176. error: new TypeError("request timeout"),
  2177. response: (argsResult || [null])[0],
  2178. details: details,
  2179. })) == null) {
  2180. // reject(new TypeError("response is intercept with ontimeout"));
  2181. return;
  2182. }
  2183. resolve({
  2184. data: response,
  2185. details: details,
  2186. msg: "请求超时",
  2187. status: false,
  2188. statusCode: 0,
  2189. type: "ontimeout",
  2190. });
  2191. },
  2192. /**
  2193. * onloadstart请求开始-触发
  2194. * @param details 配置
  2195. * @param argsResult 返回的参数列表
  2196. */
  2197. onLoadStart(details, argsResult) {
  2198. // console.log(argsResult);
  2199. if ("onloadstart" in details) {
  2200. details.onloadstart.apply(this, argsResult);
  2201. }
  2202. else if ("onloadstart" in this.context.#defaultDetails) {
  2203. this.context.#defaultDetails.onloadstart.apply(this, argsResult);
  2204. }
  2205. },
  2206. /**
  2207. * onload加载完毕-触发
  2208. * @param details 请求的配置
  2209. * @param resolve 回调
  2210. * @param reject 抛出错误
  2211. * @param argsResult 返回的参数列表
  2212. */
  2213. async onLoad(details, resolve, reject, argsResult) {
  2214. // console.log(argsResult);
  2215. /* X浏览器会因为设置了responseType导致不返回responseText */
  2216. let originResponse = argsResult[0];
  2217. /* responseText为空,response不为空的情况 */
  2218. if (utils.isNull(originResponse["responseText"]) &&
  2219. utils.isNotNull(originResponse["response"])) {
  2220. if (typeof originResponse["response"] === "object") {
  2221. utils.tryCatch().run(() => {
  2222. originResponse["responseText"] = JSON.stringify(originResponse["response"]);
  2223. });
  2224. }
  2225. else {
  2226. originResponse["responseText"] = originResponse["response"];
  2227. }
  2228. }
  2229. /* response为空,responseText不为空的情况 */
  2230. if (originResponse["response"] == null &&
  2231. typeof originResponse["responseText"] === "string" &&
  2232. originResponse["responseText"].trim() !== "") {
  2233. /** 原始的请求text */
  2234. let httpxResponseText = originResponse.responseText;
  2235. // 自定义个新的response
  2236. let httpxResponse = httpxResponseText;
  2237. if (details.responseType === "json") {
  2238. httpxResponse = utils.toJSON(httpxResponseText);
  2239. }
  2240. else if (details.responseType === "document") {
  2241. let parser = new DOMParser();
  2242. httpxResponse = parser.parseFromString(httpxResponseText, "text/html");
  2243. }
  2244. else if (details.responseType === "arraybuffer") {
  2245. let encoder = new TextEncoder();
  2246. let arrayBuffer = encoder.encode(httpxResponseText);
  2247. httpxResponse = arrayBuffer;
  2248. }
  2249. else if (details.responseType === "blob") {
  2250. let encoder = new TextEncoder();
  2251. let arrayBuffer = encoder.encode(httpxResponseText);
  2252. httpxResponse = new Blob([arrayBuffer]);
  2253. }
  2254. // 尝试覆盖原response
  2255. try {
  2256. let setStatus = Reflect.set(originResponse, "response", httpxResponse);
  2257. if (!setStatus) {
  2258. console.warn("[Httpx-HttpxCallBack.oonLoad] 覆盖原始 response 失败,尝试添加新的httpxResponse");
  2259. try {
  2260. Reflect.set(originResponse, "httpxResponse", httpxResponse);
  2261. }
  2262. catch (error) {
  2263. console.warn("[Httpx-HttpxCallBack.oonLoad] httpxResponse 无法被覆盖");
  2264. }
  2265. }
  2266. }
  2267. catch (error) {
  2268. console.warn("[Httpx-HttpxCallBack.oonLoad] 原始 response 无法被覆盖,尝试添加新的httpxResponse");
  2269. try {
  2270. Reflect.set(originResponse, "httpxResponse", httpxResponse);
  2271. }
  2272. catch (error) {
  2273. console.warn("[Httpx-HttpxCallBack.oonLoad] httpxResponse 无法被覆盖");
  2274. }
  2275. }
  2276. }
  2277. /* Stay扩展中没有finalUrl,对应的是responseURL */
  2278. let originResponseURL = Reflect.get(originResponse, "responseURL");
  2279. if (originResponse["finalUrl"] == null && originResponseURL != null) {
  2280. Reflect.set(originResponse, "finalUrl", originResponseURL);
  2281. }
  2282. /* 状态码2xx都是成功的 */
  2283. if (Math.floor(originResponse.status / 100) === 2) {
  2284. if ((await this.context.HttpxResponseHook.successResponseCallBack(originResponse, details)) == null) {
  2285. // reject(new TypeError("response is intercept with onloada"));
  2286. return;
  2287. }
  2288. resolve({
  2289. data: originResponse,
  2290. details: details,
  2291. msg: "请求成功",
  2292. status: true,
  2293. statusCode: originResponse.status,
  2294. type: "onload",
  2295. });
  2296. }
  2297. else {
  2298. this.context.HttpxCallBack.onError(details, resolve, reject, argsResult);
  2299. }
  2300. },
  2301. /**
  2302. * onprogress上传进度-触发
  2303. * @param details 配置
  2304. * @param argsResult 返回的参数列表
  2305. */
  2306. onProgress(details, argsResult) {
  2307. // console.log(argsResult);
  2308. if ("onprogress" in details) {
  2309. details.onprogress.apply(this, argsResult);
  2310. }
  2311. else if ("onprogress" in this.context.#defaultDetails) {
  2312. this.context.#defaultDetails.onprogress.apply(this, argsResult);
  2313. }
  2314. },
  2315. /**
  2316. * onreadystatechange准备状态改变-触发
  2317. * @param details 配置
  2318. * @param argsResult 返回的参数列表
  2319. */
  2320. onReadyStateChange(details, argsResult) {
  2321. // console.log(argsResult);
  2322. if ("onreadystatechange" in details) {
  2323. details.onreadystatechange.apply(this, argsResult);
  2324. }
  2325. else if ("onreadystatechange" in this.context.#defaultDetails) {
  2326. this.context.#defaultDetails.onreadystatechange.apply(this, argsResult);
  2327. }
  2328. },
  2329. };
  2330. HttpxRequest = {
  2331. context: this,
  2332. /**
  2333. * 发送请求
  2334. * @param details
  2335. */
  2336. async request(details) {
  2337. if (this.context.#LOG_DETAILS) {
  2338. console.log("[Httpx-HttpxRequest.request] 请求前的配置👇", details);
  2339. }
  2340. if (typeof this.context.HttpxRequestHook.beforeRequestCallBack ===
  2341. "function") {
  2342. let hookResult = await this.context.HttpxRequestHook.beforeRequestCallBack(details);
  2343. if (hookResult == null) {
  2344. return;
  2345. }
  2346. }
  2347. if (details.fetch) {
  2348. // 使用fetch请求
  2349. const { fetchOption: fetchOption, fetchRequestOption: fetchRequestOption, abortController, } = this.context.HttpxRequestOption.handleFetchOption(details);
  2350. return this.fetch(fetchOption, fetchRequestOption, abortController);
  2351. }
  2352. else {
  2353. // 使用GM_xmlHttpRequest请求
  2354. return this.xmlHttpRequest(details);
  2355. }
  2356. },
  2357. /**
  2358. * 使用油猴函数GM_xmlhttpRequest发送请求
  2359. * @param details
  2360. */
  2361. xmlHttpRequest(details) {
  2362. return this.context.GM_Api.xmlHttpRequest(details);
  2363. },
  2364. /**
  2365. * 使用fetch发送请求
  2366. * @param option
  2367. * @param fetchRequestOption
  2368. * @param abortController
  2369. */
  2370. fetch(option, fetchRequestOption, abortController) {
  2371. fetch(option.url, fetchRequestOption)
  2372. .then(async (fetchResponse) => {
  2373. /** 自定义的response */
  2374. let httpxResponse = {
  2375. isFetch: true,
  2376. finalUrl: fetchResponse.url,
  2377. readyState: 4,
  2378. // @ts-ignore
  2379. status: fetchResponse.status,
  2380. statusText: fetchResponse.statusText,
  2381. // @ts-ignore
  2382. response: void 0,
  2383. responseFetchHeaders: fetchResponse.headers,
  2384. responseHeaders: "",
  2385. // @ts-ignore
  2386. responseText: void 0,
  2387. responseType: option.responseType,
  2388. responseXML: void 0,
  2389. };
  2390. Object.assign(httpxResponse, option.context || {});
  2391. // 把headers转为字符串
  2392. for (const [key, value] of fetchResponse.headers.entries()) {
  2393. httpxResponse.responseHeaders += `${key}: ${value}\n`;
  2394. }
  2395. /** 请求返回的类型 */
  2396. const fetchResponseType = fetchResponse.headers.get("Content-Type");
  2397. /* 如果需要stream,且获取到的是stream,那直接返回 */
  2398. if (option.responseType === "stream" ||
  2399. (fetchResponse.headers.has("Content-Type") &&
  2400. fetchResponse.headers
  2401. .get("Content-Type")
  2402. .includes("text/event-stream"))) {
  2403. Reflect.set(httpxResponse, "isStream", true);
  2404. Reflect.set(httpxResponse, "response", fetchResponse.body);
  2405. Reflect.deleteProperty(httpxResponse, "responseText");
  2406. Reflect.deleteProperty(httpxResponse, "responseXML");
  2407. option.onload(httpxResponse);
  2408. return;
  2409. }
  2410. /** 响应 */
  2411. let response = "";
  2412. /** 响应字符串 */
  2413. let responseText = "";
  2414. /** 响应xml文档 */
  2415. let responseXML = "";
  2416. /** 先获取二进制数据 */
  2417. let arrayBuffer = await fetchResponse.arrayBuffer();
  2418. /** 数据编码 */
  2419. let encoding = "utf-8";
  2420. if (fetchResponse.headers.has("Content-Type")) {
  2421. let charsetMatched = fetchResponse.headers
  2422. .get("Content-Type")
  2423. ?.match(/charset=(.+)/);
  2424. if (charsetMatched) {
  2425. encoding = charsetMatched[1];
  2426. encoding = encoding.toLowerCase();
  2427. }
  2428. }
  2429. // Failed to construct 'TextDecoder': The encoding label provided ('"UTF-8"') is invalid.
  2430. // 去除引号
  2431. encoding = encoding.replace(/('|")/gi, "");
  2432. // 编码
  2433. let textDecoder = new TextDecoder(encoding);
  2434. responseText = textDecoder.decode(arrayBuffer);
  2435. response = responseText;
  2436. if (option.responseType === "arraybuffer") {
  2437. // response返回格式是二进制流
  2438. response = arrayBuffer;
  2439. }
  2440. else if (option.responseType === "blob") {
  2441. // response返回格式是blob
  2442. response = new Blob([arrayBuffer]);
  2443. }
  2444. else if (option.responseType === "json" ||
  2445. (typeof fetchResponseType === "string" &&
  2446. fetchResponseType.includes("application/json"))) {
  2447. // response返回格式是JSON格式
  2448. response = utils.toJSON(responseText);
  2449. }
  2450. else if (option.responseType === "document" ||
  2451. option.responseType == null) {
  2452. // response返回格式是文档格式
  2453. let parser = new DOMParser();
  2454. response = parser.parseFromString(responseText, "text/html");
  2455. }
  2456. // 转为XML结构
  2457. let parser = new DOMParser();
  2458. responseXML = parser.parseFromString(responseText, "text/xml");
  2459. Reflect.set(httpxResponse, "response", response);
  2460. Reflect.set(httpxResponse, "responseText", responseText);
  2461. Reflect.set(httpxResponse, "responseXML", responseXML);
  2462. // 执行回调
  2463. option.onload(httpxResponse);
  2464. })
  2465. .catch((error) => {
  2466. if (error.name === "AbortError") {
  2467. return;
  2468. }
  2469. option.onerror({
  2470. isFetch: true,
  2471. finalUrl: option.url,
  2472. readyState: 4,
  2473. status: 0,
  2474. statusText: "",
  2475. responseHeaders: "",
  2476. responseText: "",
  2477. error: error,
  2478. });
  2479. });
  2480. option.onloadstart({
  2481. isFetch: true,
  2482. finalUrl: option.url,
  2483. readyState: 1,
  2484. responseHeaders: "",
  2485. responseText: "",
  2486. status: 0,
  2487. statusText: "",
  2488. });
  2489. return {
  2490. abort() {
  2491. abortController.abort();
  2492. },
  2493. };
  2494. },
  2495. };
  2496. /**
  2497. * 默认配置
  2498. */
  2499. #defaultDetails = {
  2500. url: void 0,
  2501. timeout: 5000,
  2502. async: false,
  2503. responseType: void 0,
  2504. headers: void 0,
  2505. data: void 0,
  2506. redirect: void 0,
  2507. cookie: void 0,
  2508. cookiePartition: void 0,
  2509. binary: void 0,
  2510. nocache: void 0,
  2511. revalidate: void 0,
  2512. context: void 0,
  2513. overrideMimeType: void 0,
  2514. anonymous: void 0,
  2515. fetch: void 0,
  2516. fetchInit: void 0,
  2517. allowInterceptConfig: {
  2518. beforeRequest: true,
  2519. afterResponseSuccess: true,
  2520. afterResponseError: true,
  2521. },
  2522. user: void 0,
  2523. password: void 0,
  2524. onabort() { },
  2525. onerror() { },
  2526. ontimeout() { },
  2527. onloadstart() { },
  2528. onreadystatechange() { },
  2529. onprogress() { },
  2530. };
  2531. /**
  2532. * 当前使用请求时,输出请求的配置
  2533. */
  2534. #LOG_DETAILS = false;
  2535. /**
  2536. * 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
  2537. * @param xmlHttpRequest
  2538. */
  2539. constructor(xmlHttpRequest) {
  2540. if (typeof xmlHttpRequest !== "function") {
  2541. console.warn("[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch");
  2542. }
  2543. this.interceptors.request.context = this;
  2544. this.interceptors.response.context = this;
  2545. this.GM_Api.xmlHttpRequest = xmlHttpRequest;
  2546. }
  2547. /**
  2548. * 覆盖当前配置
  2549. * @param details
  2550. */
  2551. config(details = {}) {
  2552. if ("logDetails" in details && typeof details["logDetails"] === "boolean") {
  2553. this.#LOG_DETAILS = details["logDetails"];
  2554. }
  2555. this.#defaultDetails = utils.assign(this.#defaultDetails, details);
  2556. }
  2557. /**
  2558. * 拦截器
  2559. */
  2560. interceptors = {
  2561. /**
  2562. * 请求拦截器
  2563. */
  2564. request: {
  2565. context: null,
  2566. /**
  2567. * 添加拦截器
  2568. * @param fn 设置的请求前回调函数,如果返回配置,则使用返回的配置,如果返回null|undefined,则阻止请求
  2569. */
  2570. use(fn) {
  2571. if (typeof fn !== "function") {
  2572. console.warn("[Httpx-interceptors-request] 请传入拦截器函数");
  2573. return;
  2574. }
  2575. return this.context.HttpxRequestHook.add(fn);
  2576. },
  2577. /**
  2578. * 移除拦截器
  2579. * @param id 通过use返回的id
  2580. */
  2581. eject(id) {
  2582. return this.context.HttpxRequestHook.delete(id);
  2583. },
  2584. /**
  2585. * 移除所有拦截器
  2586. */
  2587. ejectAll() {
  2588. this.context.HttpxRequestHook.clearAll();
  2589. },
  2590. },
  2591. /**
  2592. * 响应拦截器
  2593. */
  2594. response: {
  2595. context: null,
  2596. /**
  2597. * 添加拦截器
  2598. * @param successFn 设置的响应后回调函数,如果返回响应,则使用返回的响应,如果返回null|undefined,则阻止响应
  2599. * + 2xx 范围内的状态码都会触发该函数
  2600. * @param errorFn 设置的响应后回调函数,如果返回响应,则使用返回的响应,如果返回null|undefined,则阻止响应
  2601. * + 超出 2xx 范围的状态码都会触发该函数
  2602. */
  2603. use(successFn, errorFn) {
  2604. if (typeof successFn !== "function" && typeof errorFn !== "function") {
  2605. console.warn("[Httpx-interceptors-response] 必须传入一个拦截器函数");
  2606. return;
  2607. }
  2608. return this.context.HttpxResponseHook.add(successFn, errorFn);
  2609. },
  2610. /**
  2611. * 移除拦截器
  2612. * @param id 通过use返回的id
  2613. */
  2614. eject(id) {
  2615. return this.context.HttpxResponseHook.delete(id);
  2616. },
  2617. /**
  2618. * 移除所有拦截器
  2619. */
  2620. ejectAll() {
  2621. this.context.HttpxResponseHook.clearAll();
  2622. },
  2623. },
  2624. };
  2625. /**
  2626. * 修改xmlHttpRequest
  2627. * @param httpRequest 网络请求函数
  2628. */
  2629. setXMLHttpRequest(httpRequest) {
  2630. this.GM_Api.xmlHttpRequest = httpRequest;
  2631. }
  2632. /**
  2633. * GET 请求
  2634. * @param url 网址
  2635. * @param details 配置
  2636. */
  2637. get(...args // @ts-ignore
  2638. ) {
  2639. let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
  2640. let abortFn = null;
  2641. let promise = new globalThis.Promise(async (resolve, reject) => {
  2642. let requestOption = this.HttpxRequestOption.getRequestOption("GET", userRequestOption, resolve, reject);
  2643. Reflect.deleteProperty(requestOption, "onprogress");
  2644. this.HttpxRequestOption.removeRequestNullOption(requestOption);
  2645. const requestResult = await this.HttpxRequest.request(requestOption);
  2646. if (requestResult != null &&
  2647. typeof requestResult.abort === "function") {
  2648. abortFn = requestResult.abort;
  2649. }
  2650. });
  2651. // @ts-ignore
  2652. promise.abort = () => {
  2653. if (typeof abortFn === "function") {
  2654. abortFn();
  2655. }
  2656. };
  2657. // @ts-ignore
  2658. return promise;
  2659. }
  2660. /**
  2661. * POST 请求
  2662. */
  2663. post(...args // @ts-ignore
  2664. ) {
  2665. let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
  2666. let abortFn = null;
  2667. let promise = new Promise(async (resolve, reject) => {
  2668. let requestOption = this.HttpxRequestOption.getRequestOption("POST", userRequestOption, resolve, reject);
  2669. // @ts-ignore
  2670. requestOption =
  2671. this.HttpxRequestOption.removeRequestNullOption(requestOption);
  2672. const requestResult = await this.HttpxRequest.request(requestOption);
  2673. if (requestResult != null &&
  2674. typeof requestResult.abort === "function") {
  2675. abortFn = requestResult.abort;
  2676. }
  2677. });
  2678. // @ts-ignore
  2679. promise.abort = () => {
  2680. if (typeof abortFn === "function") {
  2681. abortFn();
  2682. }
  2683. };
  2684. // @ts-ignore
  2685. return promise;
  2686. }
  2687. /**
  2688. * HEAD 请求
  2689. */
  2690. head(...args // @ts-ignore
  2691. ) {
  2692. let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
  2693. let abortFn = null;
  2694. let promise = new Promise(async (resolve, reject) => {
  2695. let requestOption = this.HttpxRequestOption.getRequestOption("HEAD", userRequestOption, resolve, reject);
  2696. Reflect.deleteProperty(requestOption, "onprogress");
  2697. // @ts-ignore
  2698. requestOption =
  2699. this.HttpxRequestOption.removeRequestNullOption(requestOption);
  2700. const requestResult = await this.HttpxRequest.request(requestOption);
  2701. if (requestResult != null &&
  2702. typeof requestResult.abort === "function") {
  2703. abortFn = requestResult.abort;
  2704. }
  2705. });
  2706. // @ts-ignore
  2707. promise.abort = () => {
  2708. if (typeof abortFn === "function") {
  2709. abortFn();
  2710. }
  2711. };
  2712. // @ts-ignore
  2713. return promise;
  2714. }
  2715. /**
  2716. * OPTIONS 请求
  2717. */
  2718. options(...args // @ts-ignore
  2719. ) {
  2720. let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
  2721. let abortFn = null;
  2722. let promise = new Promise(async (resolve, reject) => {
  2723. let requestOption = this.HttpxRequestOption.getRequestOption("OPTIONS", userRequestOption, resolve, reject);
  2724. Reflect.deleteProperty(requestOption, "onprogress");
  2725. // @ts-ignore
  2726. requestOption =
  2727. this.HttpxRequestOption.removeRequestNullOption(requestOption);
  2728. const requestResult = await this.HttpxRequest.request(requestOption);
  2729. if (requestResult != null &&
  2730. typeof requestResult.abort === "function") {
  2731. abortFn = requestResult.abort;
  2732. }
  2733. });
  2734. // @ts-ignore
  2735. promise.abort = () => {
  2736. if (typeof abortFn === "function") {
  2737. abortFn();
  2738. }
  2739. };
  2740. // @ts-ignore
  2741. return promise;
  2742. }
  2743. /**
  2744. * DELETE 请求
  2745. */
  2746. delete(...args // @ts-ignore
  2747. ) {
  2748. let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
  2749. let abortFn = null;
  2750. let promise = new Promise(async (resolve, reject) => {
  2751. let requestOption = this.HttpxRequestOption.getRequestOption("DELETE", userRequestOption, resolve, reject);
  2752. Reflect.deleteProperty(requestOption, "onprogress");
  2753. // @ts-ignore
  2754. requestOption =
  2755. this.HttpxRequestOption.removeRequestNullOption(requestOption);
  2756. const requestResult = await this.HttpxRequest.request(requestOption);
  2757. if (requestResult != null &&
  2758. typeof requestResult.abort === "function") {
  2759. abortFn = requestResult.abort;
  2760. }
  2761. });
  2762. // @ts-ignore
  2763. promise.abort = () => {
  2764. if (typeof abortFn === "function") {
  2765. abortFn();
  2766. }
  2767. };
  2768. // @ts-ignore
  2769. return promise;
  2770. }
  2771. /**
  2772. * PUT 请求
  2773. */
  2774. put(...args // @ts-ignore
  2775. ) {
  2776. let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
  2777. let abortFn = null;
  2778. let promise = new Promise(async (resolve, reject) => {
  2779. let requestOption = this.HttpxRequestOption.getRequestOption("PUT", userRequestOption, resolve, reject);
  2780. // @ts-ignore
  2781. requestOption =
  2782. this.HttpxRequestOption.removeRequestNullOption(requestOption);
  2783. const requestResult = await this.HttpxRequest.request(requestOption);
  2784. if (requestResult != null &&
  2785. typeof requestResult.abort === "function") {
  2786. abortFn = requestResult.abort;
  2787. }
  2788. });
  2789. // @ts-ignore
  2790. promise.abort = () => {
  2791. if (typeof abortFn === "function") {
  2792. abortFn();
  2793. }
  2794. };
  2795. // @ts-ignore
  2796. return promise;
  2797. }
  2798. }
  2799.  
  2800. class indexedDB {
  2801. #dbName;
  2802. #storeName;
  2803. #dbVersion;
  2804. /* websql的版本号,由于ios的问题,版本号的写法不一样 */
  2805. // @ts-ignore
  2806. #slqVersion = "1";
  2807. /* 监听IndexDB */
  2808. #indexedDB = window.indexedDB ||
  2809. window.mozIndexedDB ||
  2810. window.webkitIndexedDB ||
  2811. window.msIndexedDB;
  2812. /* 缓存数据库,避免同一个页面重复创建和销毁 */
  2813. #db = {};
  2814. // @ts-ignore
  2815. #store = null;
  2816. /** 状态码 */
  2817. #statusCode = {
  2818. operationSuccess: {
  2819. code: 200,
  2820. msg: "操作成功",
  2821. },
  2822. operationFailed: {
  2823. code: 401,
  2824. msg: "操作失败",
  2825. },
  2826. empty: {
  2827. code: 201,
  2828. msg: "操作成功,但是没有数据",
  2829. },
  2830. openFailed: { code: 91001, msg: "打开数据库失败" },
  2831. saveFailed: { code: 91002, msg: "保存数据失败" },
  2832. getFailed: { code: 91003, msg: "获取数据失败" },
  2833. deleteFailed: { code: 91004, msg: "删除数据失败" },
  2834. deleteAllFailed: { code: 91005, msg: "清空数据库失败" },
  2835. regexpGetFailed: { code: 91006, msg: "正则获取数据失败" },
  2836. };
  2837. /**
  2838. * @param dbName 数据存储名,默认为:default_db
  2839. * @param storeName 表名,默认为:default_form
  2840. * @param dbVersion indexDB的版本号,默认为:1
  2841. */
  2842. constructor(dbName = "default_db", storeName = "default_form", dbVersion = 1) {
  2843. this.#dbName = dbName;
  2844. this.#storeName = storeName;
  2845. this.#dbVersion = dbVersion;
  2846. if (!this.#indexedDB) {
  2847. alert("很抱歉,您的浏览器不支持indexedDB");
  2848. throw new TypeError("很抱歉,您的浏览器不支持indexedDB");
  2849. }
  2850. }
  2851. /**
  2852. * 创建 “表”
  2853. * @param dbName 表名
  2854. */
  2855. createStore(dbName) {
  2856. let txn, store;
  2857. txn = this.#db[dbName].transaction(this.#storeName, "readwrite");
  2858. /* IndexDB的读写权限 */
  2859. store = txn.objectStore(this.#storeName);
  2860. this.#store = store;
  2861. return store;
  2862. }
  2863. /**
  2864. * 打开数据库
  2865. * @param callback 回调
  2866. * @param dbName 数据库名
  2867. */
  2868. open(callback, dbName) {
  2869. let that = this;
  2870. /* 打开数据库 */
  2871. /* 如果支持IndexDB */
  2872. if (!that.#db[dbName]) {
  2873. /* 如果缓存中没有,则进行数据库的创建或打开,提高效率 */
  2874. let request = that.#indexedDB.open(dbName, that.#dbVersion);
  2875. request.onerror = function (event) {
  2876. callback(null, {
  2877. code: that.#statusCode.openFailed.code,
  2878. msg: that.#statusCode.openFailed.msg,
  2879. event: event,
  2880. });
  2881. };
  2882. request.onsuccess = function (event) {
  2883. if (!that.#db[dbName]) {
  2884. let target = event.target;
  2885. that.#db[dbName] = target.result;
  2886. }
  2887. let store = that.createStore(dbName);
  2888. callback(store);
  2889. };
  2890. request.onupgradeneeded = function (event) {
  2891. let target = event.target;
  2892. that.#db[dbName] = target.result;
  2893. let store = that.#db[dbName].createObjectStore(that.#storeName, {
  2894. keyPath: "key",
  2895. });
  2896. store.transaction.oncomplete = function (event) {
  2897. callback(store);
  2898. };
  2899. };
  2900. }
  2901. else {
  2902. /* 如果缓存中已经打开了数据库,就直接使用 */
  2903. let store = this.createStore(dbName);
  2904. callback(store);
  2905. }
  2906. }
  2907. /**
  2908. * 保存数据到数据库
  2909. * @param key 数据key
  2910. * @param value 数据值
  2911. */
  2912. async save(key, value) {
  2913. let that = this;
  2914. return new Promise((resolve) => {
  2915. let dbName = this.#dbName;
  2916. let inData = {
  2917. key: key,
  2918. value: value,
  2919. };
  2920. this.open(function (idbStore) {
  2921. if (idbStore == null) {
  2922. resolve({
  2923. success: false,
  2924. code: that.#statusCode.saveFailed.code,
  2925. msg: that.#statusCode.saveFailed.msg,
  2926. });
  2927. }
  2928. else {
  2929. let request = idbStore.put(inData);
  2930. request.onsuccess = function (event) {
  2931. /* 保存成功有success 字段 */
  2932. resolve({
  2933. success: true,
  2934. code: that.#statusCode.operationSuccess.code,
  2935. msg: that.#statusCode.operationSuccess.msg,
  2936. event: event,
  2937. });
  2938. };
  2939. request.onerror = function (event) {
  2940. resolve({
  2941. success: false,
  2942. code: that.#statusCode.saveFailed.code,
  2943. msg: that.#statusCode.saveFailed.msg,
  2944. event: event,
  2945. });
  2946. };
  2947. }
  2948. }, dbName);
  2949. });
  2950. }
  2951. /**
  2952. * 判断是否存在该数据
  2953. * @param key 数据key
  2954. */
  2955. async has(key) {
  2956. let that = this;
  2957. return new Promise((resolve) => {
  2958. let dbName = this.#dbName;
  2959. this.open(function (idbStore) {
  2960. /* 判断返回的数据中是否有error字段 */
  2961. if (idbStore == null) {
  2962. resolve({
  2963. success: false,
  2964. code: that.#statusCode.getFailed.code,
  2965. msg: that.#statusCode.getFailed.msg,
  2966. });
  2967. }
  2968. else {
  2969. let request = idbStore.get(key);
  2970. request.onsuccess = function (event) {
  2971. /* result 返回的是 {key: string, value: any} */
  2972. /* 键值对存储 */
  2973. resolve({
  2974. success: true,
  2975. code: that.#statusCode.operationSuccess.code,
  2976. msg: that.#statusCode.operationSuccess.msg,
  2977. event: event,
  2978. });
  2979. };
  2980. request.onerror = function (event) {
  2981. resolve({
  2982. success: false,
  2983. code: that.#statusCode.getFailed.code,
  2984. msg: that.#statusCode.getFailed.msg,
  2985. event: event,
  2986. });
  2987. };
  2988. }
  2989. }, dbName);
  2990. });
  2991. }
  2992. /**
  2993. * 根据key获取值
  2994. * @param key 数据key
  2995. */
  2996. async get(key) {
  2997. let that = this;
  2998. return new Promise((resolve) => {
  2999. let dbName = this.#dbName;
  3000. this.open(function (idbStore) {
  3001. /* 判断返回的数据中是否有error字段 */
  3002. if (idbStore == null) {
  3003. resolve({
  3004. success: false,
  3005. code: that.#statusCode.getFailed.code,
  3006. msg: that.#statusCode.getFailed.msg,
  3007. data: void 0,
  3008. });
  3009. }
  3010. else {
  3011. let request = idbStore.get(key);
  3012. request.onsuccess = function (event) {
  3013. let target = event.target;
  3014. let result = target.result;
  3015. /* result 返回的是 {key: string, value: any} */
  3016. /* 键值对存储 */
  3017. let data = result ? result.value : void 0;
  3018. if (data == null) {
  3019. resolve({
  3020. success: true,
  3021. code: that.#statusCode.empty.code,
  3022. msg: that.#statusCode.empty.msg,
  3023. data: data,
  3024. event: event,
  3025. result: result,
  3026. });
  3027. }
  3028. else {
  3029. resolve({
  3030. success: true,
  3031. code: that.#statusCode.operationSuccess.code,
  3032. msg: that.#statusCode.operationSuccess.msg,
  3033. data: data,
  3034. event: event,
  3035. result: result,
  3036. });
  3037. }
  3038. };
  3039. request.onerror = function (event) {
  3040. resolve({
  3041. success: false,
  3042. code: that.#statusCode.getFailed.code,
  3043. msg: that.#statusCode.getFailed.msg,
  3044. data: void 0,
  3045. event: event,
  3046. });
  3047. };
  3048. }
  3049. }, dbName);
  3050. });
  3051. }
  3052. /**
  3053. * 正则获取数据
  3054. * @param key 数据key,可以是正则
  3055. */
  3056. async regexpGet(key) {
  3057. let list = [];
  3058. let that = this;
  3059. return new Promise((resolve) => {
  3060. /* 正则查询 */
  3061. let dbName = that.#dbName;
  3062. this.open(function (idbStore) {
  3063. /* 判断返回的数据中是否有error字段 */
  3064. if (idbStore == null) {
  3065. resolve({
  3066. success: false,
  3067. code: that.#statusCode.regexpGetFailed.code,
  3068. msg: that.#statusCode.regexpGetFailed.msg,
  3069. data: [],
  3070. });
  3071. }
  3072. else {
  3073. let request = idbStore.getAll();
  3074. request.onsuccess = function (event) {
  3075. let target = event.target;
  3076. let result = target.result;
  3077. if (result.length !== 0) {
  3078. result.forEach((dataItem, index) => {
  3079. // 当前项的key
  3080. let __key = dataItem["key"];
  3081. // 当前项的value
  3082. let __value = dataItem["value"];
  3083. if (__key.match(key)) {
  3084. list = list.concat(__value);
  3085. }
  3086. });
  3087. }
  3088. resolve({
  3089. success: true,
  3090. code: that.#statusCode.operationSuccess.code,
  3091. msg: that.#statusCode.operationSuccess.msg,
  3092. data: list,
  3093. event: event,
  3094. });
  3095. };
  3096. request.onerror = function (event) {
  3097. resolve({
  3098. success: false,
  3099. code: that.#statusCode.getFailed.code,
  3100. msg: that.#statusCode.getFailed.msg,
  3101. data: [],
  3102. event: event,
  3103. });
  3104. };
  3105. }
  3106. }, dbName);
  3107. });
  3108. }
  3109. /**
  3110. * 删除数据
  3111. * @param key 数据key
  3112. */
  3113. async delete(key) {
  3114. let that = this;
  3115. return new Promise((resolve) => {
  3116. /* 根据key删除某条数据 */
  3117. let dbName = that.#dbName;
  3118. this.open(function (idbStore) {
  3119. if (idbStore == null) {
  3120. resolve({
  3121. success: false,
  3122. code: that.#statusCode.deleteFailed.code,
  3123. msg: that.#statusCode.deleteFailed.msg,
  3124. });
  3125. }
  3126. else {
  3127. // 删除键
  3128. let request = idbStore.delete(key);
  3129. request.onsuccess = function (event) {
  3130. resolve({
  3131. success: true,
  3132. code: that.#statusCode.operationSuccess.code,
  3133. msg: that.#statusCode.operationSuccess.msg,
  3134. event: event,
  3135. });
  3136. };
  3137. request.onerror = function (event) {
  3138. resolve({
  3139. success: false,
  3140. code: that.#statusCode.deleteFailed.code,
  3141. msg: that.#statusCode.deleteFailed.msg,
  3142. event: event,
  3143. });
  3144. };
  3145. }
  3146. }, dbName);
  3147. });
  3148. }
  3149. /**
  3150. * 删除所有数据
  3151. */
  3152. async deleteAll() {
  3153. let that = this;
  3154. return new Promise((resolve) => {
  3155. /* 清空数据库 */
  3156. let dbName = that.#dbName;
  3157. this.open(function (idbStore) {
  3158. if (idbStore == null) {
  3159. resolve({
  3160. success: false,
  3161. code: that.#statusCode.deleteAllFailed.code,
  3162. msg: that.#statusCode.deleteAllFailed.msg,
  3163. });
  3164. }
  3165. else {
  3166. // 清空
  3167. let operateResult = idbStore.clear();
  3168. operateResult.onsuccess = function (event) {
  3169. resolve({
  3170. success: true,
  3171. code: that.#statusCode.operationSuccess.code,
  3172. msg: that.#statusCode.operationSuccess.msg,
  3173. event: event,
  3174. });
  3175. };
  3176. operateResult.onerror = function (event) {
  3177. resolve({
  3178. success: false,
  3179. code: that.#statusCode.deleteAllFailed.code,
  3180. msg: that.#statusCode.deleteAllFailed.msg,
  3181. event: event,
  3182. });
  3183. };
  3184. }
  3185. }, dbName);
  3186. });
  3187. }
  3188. }
  3189.  
  3190. class LockFunction {
  3191. #flag = false;
  3192. #delayTime = 0;
  3193. #callback;
  3194. #context;
  3195. lock;
  3196. unlock;
  3197. run;
  3198. isLock;
  3199. constructor(callback, context, delayTime) {
  3200. let that = this;
  3201. this.#callback = callback;
  3202. if (typeof context === "number") {
  3203. this.#delayTime = context;
  3204. this.#context = utils;
  3205. }
  3206. else {
  3207. this.#delayTime = delayTime;
  3208. this.#context = context;
  3209. }
  3210. /**
  3211. * 锁
  3212. */
  3213. this.lock = function () {
  3214. that.#flag = true;
  3215. };
  3216. /**
  3217. * 解锁
  3218. */
  3219. this.unlock = function () {
  3220. setTimeout(() => {
  3221. that.#flag = false;
  3222. }, that.#delayTime);
  3223. };
  3224. /**
  3225. * 判断是否被锁
  3226. */
  3227. this.isLock = function () {
  3228. return that.#flag;
  3229. };
  3230. /**
  3231. * 执行
  3232. */
  3233. this.run = async function (...args) {
  3234. if (that.isLock()) {
  3235. return;
  3236. }
  3237. that.lock();
  3238. await that.#callback.apply(that.#context, args);
  3239. that.unlock();
  3240. };
  3241. }
  3242. }
  3243.  
  3244. class Log {
  3245. /** 是否禁用输出的flag */
  3246. #disable = false;
  3247. /** 前面的TAG标志 */
  3248. tag = "Utils.Log";
  3249. /* 使用的console函数 */
  3250. #console = null;
  3251. /* 当前输出的数量 */
  3252. #logCount = 0;
  3253. /* 配置 */
  3254. #details = {
  3255. tag: true,
  3256. successColor: "#0000FF",
  3257. errorColor: "#FF0000",
  3258. infoColor: "0",
  3259. warnColor: "0",
  3260. debug: false,
  3261. autoClearConsole: false,
  3262. logMaxCount: 999,
  3263. };
  3264. /**
  3265. * 颜色配置
  3266. */
  3267. #msgColorDetails = [
  3268. "font-weight: bold; color: cornflowerblue",
  3269. "font-weight: bold; color: cornflowerblue",
  3270. "font-weight: bold; color: darkorange",
  3271. "font-weight: bold; color: cornflowerblue",
  3272. ];
  3273. /**
  3274. * @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
  3275. * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
  3276. */
  3277. constructor(__GM_info, console = window.console) {
  3278. if (typeof __GM_info === "string") {
  3279. this.tag = __GM_info;
  3280. }
  3281. else if (typeof __GM_info === "object" &&
  3282. typeof __GM_info?.script?.name === "string") {
  3283. this.tag = __GM_info.script.name;
  3284. }
  3285. this.#console = console;
  3286. }
  3287. /**
  3288. * 解析Error的堆栈获取实际调用者的函数名及函数所在的位置
  3289. * @param stack
  3290. */
  3291. parseErrorStack(stack) {
  3292. let result = {
  3293. name: "",
  3294. position: "",
  3295. };
  3296. for (let stackString of stack) {
  3297. stackString = stackString.trim();
  3298. let stackFunctionNameMatch = stackString.match(/^at[\s]+(.+?)[\s]+/i);
  3299. let stackFunctionNamePositionMatch = stackString.match(/^at[\s]+.+[\s]+\((.+?)\)/i);
  3300. if (stackFunctionNameMatch == null) {
  3301. continue;
  3302. }
  3303. if (stackFunctionNamePositionMatch == null) {
  3304. continue;
  3305. }
  3306. /* 获取最后一个,因为第一个是包含了at */
  3307. let stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
  3308. let stackFunctionNamePosition = stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
  3309. if (stackFunctionName === "" ||
  3310. stackFunctionName.match(/^(Utils\.|)Log(\.|)|.<anonymous>$|^Function.each|^NodeList.forEach|^k.fn.init.each/g)) {
  3311. continue;
  3312. }
  3313. else {
  3314. result.name = stackFunctionName;
  3315. result.position = stackFunctionNamePosition;
  3316. break;
  3317. }
  3318. }
  3319. if (result.position === "") {
  3320. let lastStackString = stack[stack.length - 1].trim();
  3321. if (lastStackString.startsWith("at chrome-extension://")) {
  3322. let lastStackMatch = lastStackString.match(/^at[\s]+(.+)/);
  3323. if (lastStackMatch) {
  3324. result.position = lastStackMatch[lastStackMatch.length - 1];
  3325. }
  3326. }
  3327. }
  3328. if (result.position === "") {
  3329. result.position = stack[stack.length - 1].trim().replace(/^at[\s]*/g, "");
  3330. }
  3331. return result;
  3332. }
  3333. /**
  3334. * 检测清理控制台
  3335. */
  3336. checkClearConsole() {
  3337. this.#logCount++;
  3338. if (this.#details.autoClearConsole &&
  3339. this.#logCount > this.#details.logMaxCount) {
  3340. this.#console.clear();
  3341. this.#logCount = 0;
  3342. }
  3343. }
  3344. /**
  3345. * 输出内容
  3346. * @param msg 需要输出的内容
  3347. * @param color 颜色
  3348. * @param otherStyle 其它CSS
  3349. */
  3350. printContent(msg, color, otherStyle) {
  3351. this.checkClearConsole();
  3352. otherStyle = otherStyle || "";
  3353. let stackSplit = new Error().stack.split("\n");
  3354. stackSplit.splice(0, 2);
  3355. let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
  3356. let tagName = this.tag;
  3357. let that = this;
  3358. /** tag的html输出格式 */
  3359. let tagNameHTML = `%c[${tagName}%c`;
  3360. /** 调用的函数名的html输出格式 */
  3361. let callerNameHTML = `%c${callerName}%c]%c`;
  3362. callerName.trim() !== "" && (callerNameHTML = "-" + callerNameHTML);
  3363. /**
  3364. * 输出消息到控制台
  3365. * @param message
  3366. */
  3367. function consoleMsg(message) {
  3368. if (typeof message === "string") {
  3369. that.#console.log(`${tagNameHTML}${callerNameHTML} %s`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
  3370. }
  3371. else if (typeof message === "number") {
  3372. that.#console.log(`${tagNameHTML}${callerNameHTML} %d`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
  3373. }
  3374. else if (typeof message === "object") {
  3375. that.#console.log(`${tagNameHTML}${callerNameHTML} %o`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
  3376. }
  3377. else {
  3378. that.#console.log(message);
  3379. }
  3380. }
  3381. if (Array.isArray(msg)) {
  3382. for (let index = 0; index < msg.length; index++) {
  3383. consoleMsg(msg[index]);
  3384. }
  3385. }
  3386. else {
  3387. consoleMsg(msg);
  3388. }
  3389. if (this.#details.debug) {
  3390. /* 如果开启调试模式,输出堆栈位置 */
  3391. this.#console.log(callerPosition);
  3392. }
  3393. }
  3394. /**
  3395. * 控制台-普通输出
  3396. * @param args 需要输出的内容
  3397. * @example
  3398. * log.info("输出信息","输出信息2","输出信息3","输出")
  3399. */
  3400. info(...args) {
  3401. if (this.#disable)
  3402. return;
  3403. this.printContent(args, this.#details.infoColor);
  3404. }
  3405. /**
  3406. * 控制台-警告输出
  3407. * @param args 需要输出的内容
  3408. * @example
  3409. * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
  3410. */
  3411. warn(...args) {
  3412. if (this.#disable)
  3413. return;
  3414. this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
  3415. }
  3416. /**
  3417. * 控制台-错误输出
  3418. * @param args 需要输出的内容
  3419. * @example
  3420. * log.error("输出错误","输出错误2","输出错误3","输出错误4")
  3421. */
  3422. error(...args) {
  3423. if (this.#disable)
  3424. return;
  3425. this.printContent(args, this.#details.errorColor);
  3426. }
  3427. /**
  3428. * 控制台-成功输出
  3429. * @param args 需要输出的内容
  3430. * @example
  3431. * log.success("输出成功")
  3432. */
  3433. success(...args) {
  3434. if (this.#disable)
  3435. return;
  3436. this.printContent(args, this.#details.successColor);
  3437. }
  3438. /**
  3439. * 控制台-输出表格
  3440. * @param msg 需要输出的内容
  3441. * @example
  3442. * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
  3443. */
  3444. table(msg) {
  3445. if (this.#disable)
  3446. return;
  3447. this.checkClearConsole();
  3448. let stack = new Error().stack.split("\n");
  3449. stack.splice(0, 1);
  3450. let errorStackParse = this.parseErrorStack(stack);
  3451. /** 堆栈函数名 */
  3452. let stackFunctionName = errorStackParse.name;
  3453. /** 堆栈位置 */
  3454. let stackFunctionNamePosition = errorStackParse.position;
  3455. let callerName = stackFunctionName;
  3456. this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${this.#details.infoColor};`);
  3457. this.#console.table(msg);
  3458. if (this.#details.debug) {
  3459. this.#console.log(stackFunctionNamePosition);
  3460. }
  3461. }
  3462. /**
  3463. * 配置Log对象的颜色
  3464. * @param paramDetails 配置信息
  3465. */
  3466. config(paramDetails) {
  3467. this.#details = Object.assign(this.#details, paramDetails);
  3468. }
  3469. /** 禁用输出 */
  3470. disable() {
  3471. this.#disable = true;
  3472. }
  3473. /** 恢复输出 */
  3474. recovery() {
  3475. this.#disable = false;
  3476. }
  3477. }
  3478.  
  3479. class Progress {
  3480. #config = {
  3481. /**
  3482. * canvas元素节点
  3483. */
  3484. canvasNode: null,
  3485. /**
  3486. * 绘制角度
  3487. */
  3488. deg: 95,
  3489. /**
  3490. * 进度
  3491. */
  3492. progress: 0,
  3493. /**
  3494. * 绘制的线宽度
  3495. */
  3496. lineWidth: 10,
  3497. /**
  3498. * 绘制的背景颜色
  3499. */
  3500. lineBgColor: "#1e637c",
  3501. /**
  3502. * 绘制的线的颜色
  3503. */
  3504. lineColor: "#25deff",
  3505. /**
  3506. * 绘制的字体颜色
  3507. */
  3508. textColor: "#000000",
  3509. /**
  3510. * 绘制的字体大小(px)
  3511. */
  3512. fontSize: 22,
  3513. /**
  3514. * 绘制的圆的半径
  3515. */
  3516. circleRadius: 50,
  3517. };
  3518. #ctx = null;
  3519. #width = null;
  3520. #height = null;
  3521. /**
  3522. *
  3523. * @param paramConfig 配置信息
  3524. */
  3525. constructor(paramConfig) {
  3526. this.#config = utils.assign(this.#config, paramConfig);
  3527. if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
  3528. throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
  3529. }
  3530. this.init();
  3531. }
  3532. /**
  3533. * 初始化
  3534. */
  3535. init() {
  3536. /* 获取画笔 */
  3537. let ctx = this.#config.canvasNode.getContext("2d");
  3538. if (ctx == null) {
  3539. throw new Error("Utils.Progress 获取画笔失败");
  3540. }
  3541. this.#ctx = ctx;
  3542. /* 元素宽度 */
  3543. this.#width = this.#config.canvasNode.width;
  3544. /* 元素高度 */
  3545. this.#height = this.#config.canvasNode.height;
  3546. /* 清除锯齿 */
  3547. if (window.devicePixelRatio) {
  3548. this.#config.canvasNode.style.width = this.#width + "px";
  3549. this.#config.canvasNode.style.height = this.#height + "px";
  3550. this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
  3551. this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
  3552. this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
  3553. }
  3554. /* 设置线宽 */
  3555. this.#ctx.lineWidth = this.#config.lineWidth;
  3556. }
  3557. /**
  3558. * 绘制
  3559. */
  3560. draw() {
  3561. let degActive = (this.#config.progress * 360) / 100;
  3562. /* 清除画布 */
  3563. this.#ctx.clearRect(0, 0, this.#width, this.#height);
  3564. /* 开始绘制底圆 */
  3565. this.#ctx.beginPath();
  3566. this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, 1, 8);
  3567. this.#ctx.strokeStyle = this.#config.lineBgColor;
  3568. this.#ctx.stroke();
  3569. /* 开始绘制动态圆 */
  3570. this.#ctx.beginPath();
  3571. this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, -Math.PI / 2, (degActive * Math.PI) / 180 - Math.PI / 2);
  3572. this.#ctx.strokeStyle = this.#config.lineColor;
  3573. this.#ctx.stroke();
  3574. /* 获取百分比 */
  3575. let txt = parseInt(this.#config.progress.toString()) + "%";
  3576. this.#ctx.font = this.#config.fontSize + "px SimHei";
  3577. /* 获取文本宽度 */
  3578. let w = this.#ctx.measureText(txt).width;
  3579. let h = this.#config.fontSize / 2;
  3580. this.#ctx.fillStyle = this.#config.textColor;
  3581. this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
  3582. }
  3583. }
  3584.  
  3585. const TryCatch = function (...args) {
  3586. /* 定义变量和函数 */
  3587. let callbackFunction = null;
  3588. let context = null;
  3589. let handleError = (error) => { };
  3590. let defaultDetails = {
  3591. log: true,
  3592. };
  3593. const TryCatchCore = {
  3594. /**
  3595. *
  3596. * @param paramDetails 配置
  3597. * @returns
  3598. */
  3599. config(paramDetails) {
  3600. defaultDetails = utils.assign(defaultDetails, paramDetails);
  3601. return TryCatchCore;
  3602. },
  3603. /**
  3604. * 处理错误
  3605. * @param handler
  3606. */
  3607. error(handler) {
  3608. // @ts-ignore
  3609. handleError = handler;
  3610. return TryCatchCore;
  3611. },
  3612. /**
  3613. * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
  3614. * @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
  3615. * @param __context__ 待执行函数的作用域,用于apply指定
  3616. * @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
  3617. * @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
  3618. */
  3619. run(callback, __context__) {
  3620. callbackFunction = callback;
  3621. context = __context__ || this;
  3622. let result = executeTryCatch(callbackFunction, handleError, context);
  3623. // @ts-ignore
  3624. return result !== void 0 ? result : TryCatchCore;
  3625. },
  3626. };
  3627. /**
  3628. * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
  3629. * @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
  3630. * @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
  3631. * @param funcThis - 待执行函数的作用域,用于apply指定
  3632. * @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
  3633. */
  3634. function executeTryCatch(callback, handleErrorFunc, funcThis) {
  3635. let result = void 0;
  3636. try {
  3637. if (typeof callback === "string") {
  3638. (function () {
  3639. eval(callback);
  3640. }).apply(funcThis, args);
  3641. }
  3642. else {
  3643. result = callback.apply(funcThis, args);
  3644. }
  3645. }
  3646. catch (error) {
  3647. if (defaultDetails.log) {
  3648. callback = callback;
  3649. console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
  3650. console.log(`%c 错误原因:${error}`, "color: #f20000");
  3651. console.trace(callback);
  3652. }
  3653. if (handleErrorFunc) {
  3654. if (typeof handleErrorFunc === "string") {
  3655. result = function () {
  3656. return eval(handleErrorFunc);
  3657. // @ts-ignore
  3658. }.apply(funcThis, [...args, error]);
  3659. }
  3660. else {
  3661. result = handleErrorFunc.apply(funcThis, [...args, error]);
  3662. }
  3663. }
  3664. }
  3665. return result;
  3666. }
  3667. return TryCatchCore;
  3668. };
  3669.  
  3670. class UtilsDictionary {
  3671. items = {};
  3672. constructor(key, value) {
  3673. if (key != null) {
  3674. this.set(key, value);
  3675. }
  3676. }
  3677. /**
  3678. * 检查是否有某一个键
  3679. * @param key 键
  3680. */
  3681. has(key) {
  3682. return Reflect.has(this.items, key);
  3683. }
  3684. /**
  3685. * 检查已有的键中是否以xx开头
  3686. * @param key 需要匹配的键
  3687. */
  3688. startsWith(key) {
  3689. let allKeys = this.keys();
  3690. for (const keyName of allKeys) {
  3691. if (String(keyName).startsWith(String(key))) {
  3692. return true;
  3693. }
  3694. }
  3695. return false;
  3696. }
  3697. /**
  3698. * 获取以xx开头的键的值
  3699. * @param key 需要匹配的键
  3700. */
  3701. getStartsWith(key) {
  3702. let allKeys = this.keys();
  3703. let result = void 0;
  3704. for (const keyName of allKeys) {
  3705. if (String(keyName).startsWith(String(key))) {
  3706. result = this.get(keyName);
  3707. break;
  3708. }
  3709. }
  3710. return result;
  3711. }
  3712. /**
  3713. * 为字典添加某一个值
  3714. * @param key 键
  3715. * @param val 值,默认为""
  3716. */
  3717. set(key, val) {
  3718. if (key === void 0) {
  3719. throw new Error("Utils.Dictionary().set 参数 key 不能为空");
  3720. }
  3721. Reflect.set(this.items, key, val);
  3722. }
  3723. /**
  3724. * 删除某一个键
  3725. * @param key 键
  3726. */
  3727. delete(key) {
  3728. if (this.has(key)) {
  3729. return Reflect.deleteProperty(this.items, key);
  3730. }
  3731. return false;
  3732. }
  3733. /**
  3734. * 获取某个键的值
  3735. * https://github.com/microsoft/TypeScript/issues/9619
  3736. * 微软到现在都没有修复has和get的联动
  3737. * @param key 键
  3738. */
  3739. get(key) {
  3740. return Reflect.get(this.items, key);
  3741. }
  3742. /**
  3743. * 返回字典中的所有值
  3744. */
  3745. values() {
  3746. let resultList = [];
  3747. for (let prop in this.getItems()) {
  3748. if (this.has(prop)) {
  3749. resultList.push(this.get(prop));
  3750. }
  3751. }
  3752. return resultList;
  3753. }
  3754. /**
  3755. * 清空字典
  3756. */
  3757. clear() {
  3758. this.items = null;
  3759. this.items = {};
  3760. }
  3761. /**
  3762. * 获取字典的长度
  3763. */
  3764. size() {
  3765. return Object.keys(this.getItems()).length;
  3766. }
  3767. /**
  3768. * 获取字典所有的键
  3769. */
  3770. keys() {
  3771. return Reflect.ownKeys(this.items);
  3772. }
  3773. /**
  3774. * 返回字典本身
  3775. */
  3776. getItems() {
  3777. // @ts-ignore
  3778. return this.items;
  3779. }
  3780. /**
  3781. * 合并另一个字典
  3782. * @param data 需要合并的字典
  3783. */
  3784. concat(data) {
  3785. this.items = utils.assign(this.items, data.getItems());
  3786. }
  3787. forEach(callbackfn) {
  3788. for (const key in this.getItems()) {
  3789. callbackfn(this.get(key), key, this.getItems());
  3790. }
  3791. }
  3792. /**
  3793. * 获取字典的长度,同this.size
  3794. */
  3795. get length() {
  3796. return this.size();
  3797. }
  3798. /**
  3799. * 迭代器
  3800. */
  3801. get entries() {
  3802. let that = this;
  3803. return function* () {
  3804. let itemKeys = Object.keys(that.getItems());
  3805. for (const keyName of itemKeys) {
  3806. yield [keyName, that.get(keyName)];
  3807. }
  3808. };
  3809. }
  3810. /**
  3811. * 是否可遍历
  3812. */
  3813. get [Symbol.iterator]() {
  3814. let that = this;
  3815. return function () {
  3816. return that.entries();
  3817. };
  3818. }
  3819. }
  3820.  
  3821. class WindowApi {
  3822. /** 默认的配置 */
  3823. defaultApi = {
  3824. document: document,
  3825. window: window,
  3826. globalThis: globalThis,
  3827. self: self,
  3828. top: top,
  3829. };
  3830. /** 使用的配置 */
  3831. api;
  3832. constructor(option) {
  3833. if (option) {
  3834. if (option.globalThis == null) {
  3835. option.globalThis = option.window;
  3836. }
  3837. if (option.self == null) {
  3838. option.self = option.window;
  3839. }
  3840. }
  3841. if (!option) {
  3842. option = Object.assign({}, this.defaultApi);
  3843. }
  3844. // @ts-ignore
  3845. this.api = Object.assign({}, option);
  3846. }
  3847. get document() {
  3848. return this.api.document;
  3849. }
  3850. get window() {
  3851. return this.api.window;
  3852. }
  3853. get globalThis() {
  3854. return this.api.globalThis;
  3855. }
  3856. get self() {
  3857. return this.api.self;
  3858. }
  3859. get top() {
  3860. return this.api.top;
  3861. }
  3862. }
  3863.  
  3864. const VueUtils = {
  3865. /** 标签 */
  3866. ReactiveFlags: {
  3867. IS_REACTIVE: Symbol("isReactive"),
  3868. },
  3869. /**
  3870. * 判断是否是对象
  3871. * @param value
  3872. */
  3873. isObject(value) {
  3874. return typeof value === "object" && value !== null;
  3875. },
  3876. /**
  3877. * 判断是否是函数
  3878. * @param val
  3879. */
  3880. isFunction(val) {
  3881. return typeof val === "function";
  3882. },
  3883. /**
  3884. * 处理对象再次代理,可以直接返回
  3885. * @param value
  3886. */
  3887. isReactive(value) {
  3888. return !!(value && value[VueUtils.ReactiveFlags.IS_REACTIVE]);
  3889. },
  3890. /**
  3891. * 判断是否是数组
  3892. * @param value
  3893. */
  3894. isArray(value) {
  3895. return Array.isArray(value);
  3896. },
  3897. };
  3898. class ReactiveEffect {
  3899. deps = [];
  3900. active = true;
  3901. fn;
  3902. // @ts-ignore
  3903. scheduler;
  3904. constructor(fn, scheduler) {
  3905. this.fn = fn;
  3906. this.scheduler = scheduler;
  3907. }
  3908. run(cb) {
  3909. if (!this.active) {
  3910. this.fn();
  3911. }
  3912. try {
  3913. if (typeof cb === "function") {
  3914. cb(this);
  3915. }
  3916. return this.fn();
  3917. }
  3918. finally {
  3919. if (typeof cb === "function") {
  3920. cb(undefined);
  3921. }
  3922. }
  3923. }
  3924. }
  3925. class RefImpl {
  3926. _value;
  3927. _isRef = true;
  3928. _rawValue;
  3929. _vue;
  3930. constructor(vueIns, rawValue) {
  3931. this._vue = vueIns;
  3932. this._rawValue = rawValue;
  3933. this._value = this._vue.toReactive(rawValue);
  3934. }
  3935. get value() {
  3936. return this._value;
  3937. }
  3938. set value(newValue) {
  3939. if (newValue !== this._rawValue) {
  3940. this._value = this._vue.toReactive(newValue);
  3941. this._rawValue = newValue;
  3942. }
  3943. }
  3944. }
  3945. class ObjectRefImpl {
  3946. object;
  3947. key;
  3948. constructor(object, key) {
  3949. this.object = object;
  3950. this.key = key;
  3951. }
  3952. get value() {
  3953. return this.object[this.key];
  3954. }
  3955. set value(newValue) {
  3956. this.object[this.key] = newValue;
  3957. }
  3958. }
  3959. class Vue {
  3960. reactMap = new WeakMap();
  3961. targetMap = new WeakMap();
  3962. activeEffect = undefined;
  3963. constructor() {
  3964. // 将数据转化成响应式的数据,只能做对象的代理
  3965. }
  3966. /**
  3967. * 生成一个被代理的对象
  3968. * @param target 需要代理的对象
  3969. */
  3970. reactive(target) {
  3971. const that = this;
  3972. if (!(typeof target === "object" && target !== null)) {
  3973. // @ts-ignore
  3974. return;
  3975. }
  3976. if (VueUtils.isReactive(target)) {
  3977. return target;
  3978. }
  3979. let exisProxy = this.reactMap.get(target);
  3980. if (exisProxy) {
  3981. return exisProxy;
  3982. }
  3983. const proxy = new Proxy(target, {
  3984. get(target, key, receiver) {
  3985. if (key === VueUtils.ReactiveFlags.IS_REACTIVE) {
  3986. return true;
  3987. }
  3988. that.track(target, "get", key);
  3989. return Reflect.get(target, key, receiver);
  3990. },
  3991. set(target, key, value, receiver) {
  3992. let oldValue = target[key];
  3993. let result = Reflect.set(target, key, value, receiver);
  3994. if (oldValue !== value) {
  3995. that.trigger(target, "set", key, oldValue, value);
  3996. }
  3997. return result;
  3998. },
  3999. });
  4000. that.reactMap.set(target, proxy);
  4001. return proxy;
  4002. }
  4003. /**
  4004. * 观察被reactive的对象值改变
  4005. * @param source 被观察的对象,这里采用函数返回对象
  4006. * @param changeCallBack 值改变的回调
  4007. */
  4008. watch(source, changeCallBack) {
  4009. let getter;
  4010. if (VueUtils.isReactive(source)) {
  4011. getter = () => this.traversal(source);
  4012. }
  4013. else if (VueUtils.isFunction(source)) {
  4014. getter = source;
  4015. }
  4016. else {
  4017. return;
  4018. }
  4019. let oldValue;
  4020. const job = () => {
  4021. const newValue = effect.run((activeEffect) => {
  4022. this.activeEffect = activeEffect;
  4023. });
  4024. changeCallBack(newValue, oldValue);
  4025. oldValue = newValue;
  4026. };
  4027. const effect = new ReactiveEffect(getter, job);
  4028. oldValue = effect.run((activeEffect) => {
  4029. this.activeEffect = activeEffect;
  4030. });
  4031. }
  4032. toReactive(value) {
  4033. return VueUtils.isObject(value) ? this.reactive(value) : value;
  4034. }
  4035. ref(value) {
  4036. return new RefImpl(this, value);
  4037. }
  4038. toRef(object, key) {
  4039. return new ObjectRefImpl(object, key);
  4040. }
  4041. toRefs(object) {
  4042. const result = VueUtils.isArray(object) ? new Array(object.length) : {};
  4043. for (let key in object) {
  4044. // @ts-ignore
  4045. result[key] = this.toRef(object, key);
  4046. }
  4047. return result;
  4048. }
  4049. trigger(target, type, key, oldValue, value) {
  4050. const depsMap = this.targetMap.get(target);
  4051. if (!depsMap)
  4052. return;
  4053. const effects = depsMap.get(key);
  4054. this.triggerEffect(effects, "effects");
  4055. }
  4056. triggerEffect(effects, name) {
  4057. effects &&
  4058. effects.forEach((effect) => {
  4059. if (effect.scheduler) {
  4060. effect.scheduler();
  4061. }
  4062. else {
  4063. effect.run();
  4064. }
  4065. });
  4066. }
  4067. track(target, type, key) {
  4068. if (!this.activeEffect)
  4069. return;
  4070. let depsMap = this.targetMap.get(target);
  4071. if (!depsMap) {
  4072. this.targetMap.set(target, (depsMap = new Map()));
  4073. }
  4074. let dep = depsMap.get(key);
  4075. if (!dep) {
  4076. depsMap.set(key, (dep = new Set()));
  4077. }
  4078. this.trackEffect(dep);
  4079. }
  4080. trackEffect(dep) {
  4081. if (this.activeEffect) {
  4082. let shouldTrack = !dep.has(this.activeEffect);
  4083. if (shouldTrack) {
  4084. dep.add(this.activeEffect);
  4085. this.activeEffect.deps.push(dep);
  4086. }
  4087. }
  4088. }
  4089. traversal(value, set = new Set()) {
  4090. if (!VueUtils.isObject(value))
  4091. return value;
  4092. if (set.has(value)) {
  4093. return value;
  4094. }
  4095. set.add(value);
  4096. for (let key in value) {
  4097. this.traversal(value[key], set);
  4098. }
  4099. return value;
  4100. }
  4101. }
  4102.  
  4103. class Utils {
  4104. windowApi;
  4105. constructor(option) {
  4106. this.windowApi = new WindowApi(option);
  4107. }
  4108. /** 版本号 */
  4109. version = "2024.11.6";
  4110. addStyle(cssText) {
  4111. if (typeof cssText !== "string") {
  4112. throw new Error("Utils.addStyle 参数cssText 必须为String类型");
  4113. }
  4114. let cssNode = this.windowApi.document.createElement("style");
  4115. cssNode.setAttribute("type", "text/css");
  4116. cssNode.innerHTML = cssText;
  4117. if (this.windowApi.document.head) {
  4118. /* 插入head最后 */
  4119. this.windowApi.document.head.appendChild(cssNode);
  4120. }
  4121. else if (this.windowApi.document.body) {
  4122. /* 插入body后 */
  4123. this.windowApi.document.body.appendChild(cssNode);
  4124. }
  4125. else if (this.windowApi.document.documentElement.childNodes.length === 0) {
  4126. /* 插入#html第一个元素后 */
  4127. this.windowApi.document.documentElement.appendChild(cssNode);
  4128. }
  4129. else {
  4130. /* 插入head前面 */
  4131. this.windowApi.document.documentElement.insertBefore(cssNode, this.windowApi.document.documentElement.childNodes[0]);
  4132. }
  4133. return cssNode;
  4134. }
  4135. assign(target = {}, source = {}, isAdd = false) {
  4136. let UtilsContext = this;
  4137. if (Array.isArray(source)) {
  4138. let canTraverse = source.filter((item) => {
  4139. return typeof item === "object";
  4140. });
  4141. if (!canTraverse.length) {
  4142. return source;
  4143. }
  4144. }
  4145. if (source == null) {
  4146. return target;
  4147. }
  4148. if (target == null) {
  4149. target = {};
  4150. }
  4151. if (isAdd) {
  4152. for (const sourceKeyName in source) {
  4153. const targetKeyName = sourceKeyName;
  4154. let targetValue = target[targetKeyName];
  4155. let sourceValue = source[sourceKeyName];
  4156. if (typeof sourceValue === "object" &&
  4157. sourceValue != null &&
  4158. sourceKeyName in target &&
  4159. !UtilsContext.isDOM(sourceValue)) {
  4160. /* 源端的值是object类型,且不是元素节点 */
  4161. target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
  4162. continue;
  4163. }
  4164. target[sourceKeyName] = sourceValue;
  4165. }
  4166. }
  4167. else {
  4168. for (const targetKeyName in target) {
  4169. if (targetKeyName in source) {
  4170. let targetValue = target[targetKeyName];
  4171. let sourceValue = source[targetKeyName];
  4172. if (typeof sourceValue === "object" &&
  4173. sourceValue != null &&
  4174. !UtilsContext.isDOM(sourceValue) &&
  4175. Object.keys(sourceValue).length) {
  4176. /* 源端的值是object类型,且不是元素节点 */
  4177. target[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
  4178. continue;
  4179. }
  4180. /* 直接赋值 */
  4181. target[targetKeyName] = sourceValue;
  4182. }
  4183. }
  4184. }
  4185. return target;
  4186. }
  4187. async asyncReplaceAll(string, pattern, asyncFn) {
  4188. let UtilsContext = this;
  4189. if (typeof string !== "string") {
  4190. throw new TypeError("string必须是字符串");
  4191. }
  4192. if (typeof asyncFn !== "function") {
  4193. throw new TypeError("asyncFn必须是函数");
  4194. }
  4195. let reg;
  4196. if (typeof pattern === "string") {
  4197. reg = new RegExp(UtilsContext.parseStringToRegExpString(pattern), "g");
  4198. }
  4199. else if (pattern instanceof RegExp) {
  4200. if (!pattern.global) {
  4201. throw new TypeError("pattern必须是全局匹配");
  4202. }
  4203. reg = new RegExp(pattern);
  4204. }
  4205. else {
  4206. throw new TypeError("pattern必须是正则对象");
  4207. }
  4208. let result = [];
  4209. let match;
  4210. let lastIndex = 0;
  4211. while ((match = reg.exec(string)) !== null) {
  4212. /* 异步获取匹配对应的字符串 */
  4213. const item = asyncFn(match[0]);
  4214. /* 获取该匹配项和上一个匹配项的中间的字符串 */
  4215. const prefix = string.slice(lastIndex, match.index);
  4216. lastIndex = match.index + match[0].length;
  4217. result.push(item);
  4218. result.push(prefix);
  4219. }
  4220. result.push(string.slice(lastIndex));
  4221. /* 等待所有异步完成 */
  4222. result = await Promise.all(result);
  4223. return result.join("");
  4224. }
  4225. /**
  4226. * ajax劫持库,支持xhr和fetch劫持。
  4227. * + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
  4228. * + 作者:cxxjackie
  4229. * + 版本:1.4.1
  4230. * + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
  4231. */
  4232. ajaxHooker = AjaxHooker;
  4233. canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = globalThis) {
  4234. if (!(canvasElement instanceof HTMLCanvasElement)) {
  4235. throw new Error("Utils.canvasClickByPosition 参数canvasElement必须是canvas元素");
  4236. }
  4237. clientX = parseInt(clientX.toString());
  4238. clientY = parseInt(clientY.toString());
  4239. const eventInit = {
  4240. cancelBubble: true,
  4241. cancelable: true,
  4242. clientX: clientX,
  4243. clientY: clientY,
  4244. // @ts-ignore
  4245. view: view,
  4246. detail: 1,
  4247. };
  4248. canvasElement.dispatchEvent(new MouseEvent("mousedown", eventInit));
  4249. canvasElement.dispatchEvent(new MouseEvent("mouseup", eventInit));
  4250. }
  4251. checkUserClickInNode(element) {
  4252. let UtilsContext = this;
  4253. if (!UtilsContext.isDOM(element)) {
  4254. throw new Error("Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
  4255. }
  4256. let clickEvent = UtilsContext.windowApi.window.event;
  4257. let touchEvent = UtilsContext.windowApi.window.event;
  4258. let $click = clickEvent?.composedPath()?.[0];
  4259. // 点击的x坐标
  4260. let clickPosX = clickEvent?.clientX != null
  4261. ? clickEvent.clientX
  4262. : touchEvent.touches[0].clientX;
  4263. // 点击的y坐标
  4264. let clickPosY = clickEvent?.clientY != null
  4265. ? clickEvent.clientY
  4266. : touchEvent.touches[0].clientY;
  4267. let {
  4268. /* 要检测的元素的相对屏幕的横坐标最左边 */
  4269. left: elementPosXLeft,
  4270. /* 要检测的元素的相对屏幕的横坐标最右边 */
  4271. right: elementPosXRight,
  4272. /* 要检测的元素的相对屏幕的纵坐标最上边 */
  4273. top: elementPosYTop,
  4274. /* 要检测的元素的相对屏幕的纵坐标最下边 */
  4275. bottom: elementPosYBottom, } = element.getBoundingClientRect();
  4276. if (clickPosX >= elementPosXLeft &&
  4277. clickPosX <= elementPosXRight &&
  4278. clickPosY >= elementPosYTop &&
  4279. clickPosY <= elementPosYBottom) {
  4280. return true;
  4281. }
  4282. else if (($click && element.contains($click)) || $click == element) {
  4283. /* 这种情况是应对在界面中隐藏的元素,getBoundingClientRect获取的都是0 */
  4284. return true;
  4285. }
  4286. else {
  4287. return false;
  4288. }
  4289. }
  4290. cloneFormData(formData) {
  4291. let clonedFormData = new FormData();
  4292. for (let [key, value] of formData.entries()) {
  4293. clonedFormData.append(key, value);
  4294. }
  4295. return clonedFormData;
  4296. }
  4297. createOverload() {
  4298. let fnMap = new Map();
  4299. function overload(...args) {
  4300. let key = args.map((it) => typeof it).join(",");
  4301. let fn = fnMap.get(key);
  4302. if (!fn) {
  4303. throw new TypeError("没有找到对应的实现");
  4304. }
  4305. return fn.apply(this, args);
  4306. }
  4307. overload.addImpl = function (...args) {
  4308. let fn = args.pop();
  4309. if (typeof fn !== "function") {
  4310. throw new TypeError("最后一个参数必须是函数");
  4311. }
  4312. let key = args.join(",");
  4313. fnMap.set(key, fn);
  4314. };
  4315. return overload;
  4316. }
  4317. /**
  4318. * 颜色转换
  4319. * @returns
  4320. */
  4321. ColorConversion = ColorConversion;
  4322. deepClone(obj) {
  4323. let UtilsContext = this;
  4324. if (obj === void 0)
  4325. return void 0;
  4326. if (obj === null)
  4327. return null;
  4328. let clone = obj instanceof Array ? [] : {};
  4329. for (const [key, value] of Object.entries(obj)) {
  4330. clone[key] =
  4331. typeof value === "object" ? UtilsContext.deepClone(value) : value;
  4332. }
  4333. return clone;
  4334. }
  4335. debounce(fn, delay = 0) {
  4336. let timer = null;
  4337. const context = this;
  4338. return function (...args) {
  4339. clearTimeout(timer);
  4340. timer = setTimeout(function () {
  4341. fn.apply(context, args);
  4342. }, delay);
  4343. };
  4344. }
  4345. deleteParentNode(element, targetSelector) {
  4346. let UtilsContext = this;
  4347. if (element == null) {
  4348. return;
  4349. }
  4350. if (!UtilsContext.isDOM(element)) {
  4351. throw new Error("Utils.deleteParentNode 参数 target 必须为 Node|HTMLElement 类型");
  4352. }
  4353. if (typeof targetSelector !== "string") {
  4354. throw new Error("Utils.deleteParentNode 参数 targetSelector 必须为 string 类型");
  4355. }
  4356. let result = false;
  4357. let needRemoveDOM = element.closest(targetSelector);
  4358. if (needRemoveDOM) {
  4359. needRemoveDOM.remove();
  4360. result = true;
  4361. }
  4362. return result;
  4363. }
  4364. /**
  4365. * 字典
  4366. * @example
  4367. * let dictionary = new Utils.Dictionary();
  4368. * let dictionary2 = new Utils.Dictionary();
  4369. * dictionary.set("test","111");
  4370. * dictionary.get("test");
  4371. * > '111'
  4372. * dictionary.has("test");
  4373. * > true
  4374. * dictionary.concat(dictionary2);
  4375. **/
  4376. Dictionary = UtilsDictionary;
  4377. dispatchEvent(element, eventName, details) {
  4378. let eventNameList = [];
  4379. if (typeof eventName === "string") {
  4380. eventNameList = [eventName];
  4381. }
  4382. if (Array.isArray(eventName)) {
  4383. eventNameList = [...eventName];
  4384. }
  4385. eventNameList.forEach((_eventName_) => {
  4386. let event = new Event(_eventName_);
  4387. if (details) {
  4388. Object.assign(event, details);
  4389. }
  4390. element.dispatchEvent(event);
  4391. });
  4392. }
  4393. downloadBase64(base64Data, fileName, isIFrame = false) {
  4394. if (typeof base64Data !== "string") {
  4395. throw new Error("Utils.downloadBase64 参数 base64Data 必须为 string 类型");
  4396. }
  4397. if (typeof fileName !== "string") {
  4398. throw new Error("Utils.downloadBase64 参数 fileName 必须为 string 类型");
  4399. }
  4400. if (isIFrame) {
  4401. /* 使用iframe */
  4402. const iframeElement = this.windowApi.document.createElement("iframe");
  4403. iframeElement.style.display = "none";
  4404. iframeElement.src = base64Data;
  4405. this.windowApi.document.body.appendChild(iframeElement);
  4406. setTimeout(() => {
  4407. iframeElement.contentWindow.document.execCommand("SaveAs", true, fileName);
  4408. this.windowApi.document.body.removeChild(iframeElement);
  4409. }, 100);
  4410. }
  4411. else {
  4412. /* 使用A标签 */
  4413. const linkElement = this.windowApi.document.createElement("a");
  4414. linkElement.setAttribute("target", "_blank");
  4415. linkElement.download = fileName;
  4416. linkElement.href = base64Data;
  4417. linkElement.click();
  4418. }
  4419. }
  4420. findWebPageVisibleText(str = "", caseSensitive = false) {
  4421. let TRange = null;
  4422. let strFound;
  4423. if (this.windowApi.globalThis.find) {
  4424. /* CODE FOR BROWSERS THAT SUPPORT window.find */
  4425. let windowFind = this.windowApi.self.find;
  4426. strFound = windowFind(str, caseSensitive, true, true, false);
  4427. if (strFound &&
  4428. this.windowApi.self.getSelection &&
  4429. !this.windowApi.self.getSelection().anchorNode) {
  4430. strFound = windowFind(str, caseSensitive, true, true, false);
  4431. }
  4432. if (!strFound) {
  4433. strFound = windowFind(str, 0, 1);
  4434. while (windowFind(str, 0, 1))
  4435. continue;
  4436. }
  4437. }
  4438. else if (navigator.appName.indexOf("Microsoft") != -1) {
  4439. /* EXPLORER-SPECIFIC CODE */
  4440. if (TRange != null) {
  4441. TRange = TRange;
  4442. TRange.collapse(false);
  4443. strFound = TRange.findText(str);
  4444. if (strFound)
  4445. TRange.select();
  4446. }
  4447. if (TRange == null || strFound == 0) {
  4448. TRange = this.windowApi.self.document.body.createTextRange();
  4449. strFound = TRange.findText(str);
  4450. if (strFound)
  4451. TRange.select();
  4452. }
  4453. }
  4454. else if (navigator.appName == "Opera") {
  4455. alert("Opera browsers not supported, sorry...");
  4456. return;
  4457. }
  4458. return strFound ? true : false;
  4459. }
  4460. *findElementsWithText(element, text, filter) {
  4461. let that = this;
  4462. if (element.outerHTML.includes(text)) {
  4463. if (element.children.length === 0) {
  4464. let filterResult = typeof filter === "function" ? filter(element) : false;
  4465. if (!filterResult) {
  4466. yield element;
  4467. }
  4468. }
  4469. else {
  4470. let textElement = Array.from(element.childNodes).filter((ele) => ele.nodeType === Node.TEXT_NODE);
  4471. for (let ele of textElement) {
  4472. if (ele.textContent.includes(text)) {
  4473. let filterResult = typeof filter === "function" ? filter(element) : false;
  4474. if (!filterResult) {
  4475. yield ele;
  4476. }
  4477. }
  4478. }
  4479. }
  4480. }
  4481. for (let index = 0; index < element.children.length; index++) {
  4482. let childElement = element.children[index];
  4483. yield* that.findElementsWithText(childElement, text, filter);
  4484. }
  4485. }
  4486. /**
  4487. * 判断该元素是否可见,如果不可见,向上找它的父元素直至找到可见的元素
  4488. * @param element
  4489. * @example
  4490. * let visibleElement = Utils.findVisibleElement(document.querySelector("a.xx"));
  4491. * > <HTMLElement>
  4492. */
  4493. findVisibleElement(element) {
  4494. let currentElement = element;
  4495. while (currentElement) {
  4496. let elementRect = currentElement.getBoundingClientRect();
  4497. if (Boolean(elementRect.length)) {
  4498. return currentElement;
  4499. }
  4500. currentElement = currentElement.parentElement;
  4501. }
  4502. return null;
  4503. }
  4504. formatByteToSize(byteSize, addType = true) {
  4505. byteSize = parseInt(byteSize.toString());
  4506. if (isNaN(byteSize)) {
  4507. throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
  4508. }
  4509. let result = 0;
  4510. let resultType = "KB";
  4511. let sizeData = {};
  4512. sizeData.B = 1;
  4513. sizeData.KB = 1024;
  4514. sizeData.MB = sizeData.KB * sizeData.KB;
  4515. sizeData.GB = sizeData.MB * sizeData.KB;
  4516. sizeData.TB = sizeData.GB * sizeData.KB;
  4517. sizeData.PB = sizeData.TB * sizeData.KB;
  4518. sizeData.EB = sizeData.PB * sizeData.KB;
  4519. sizeData.ZB = sizeData.EB * sizeData.KB;
  4520. sizeData.YB = sizeData.ZB * sizeData.KB;
  4521. sizeData.BB = sizeData.YB * sizeData.KB;
  4522. sizeData.NB = sizeData.BB * sizeData.KB;
  4523. sizeData.DB = sizeData.NB * sizeData.KB;
  4524. for (let key in sizeData) {
  4525. result = byteSize / sizeData[key];
  4526. resultType = key;
  4527. if (sizeData.KB >= result) {
  4528. break;
  4529. }
  4530. }
  4531. result = result.toFixed(2);
  4532. result = addType
  4533. ? result + resultType.toString()
  4534. : parseFloat(result.toString());
  4535. return result;
  4536. }
  4537. getNodeListValue(...args) {
  4538. let resultArray = [];
  4539. for (let arg of args) {
  4540. let value = arg;
  4541. if (typeof arg === "function") {
  4542. /* 方法 */
  4543. value = arg();
  4544. }
  4545. if (value.length !== 0) {
  4546. resultArray = [...value];
  4547. break;
  4548. }
  4549. }
  4550. return resultArray;
  4551. }
  4552. getNonNullValue(...args) {
  4553. let resultValue = args[args.length - 1];
  4554. let UtilsContext = this;
  4555. for (const argValue of args) {
  4556. if (UtilsContext.isNotNull(argValue)) {
  4557. resultValue = argValue;
  4558. break;
  4559. }
  4560. }
  4561. return resultValue;
  4562. }
  4563. formatTime(text = new Date(), formatType = "yyyy-MM-dd HH:mm:ss") {
  4564. let time = text == null ? new Date() : new Date(text);
  4565. /**
  4566. * 校验时间补0
  4567. * @param timeNum
  4568. * @returns
  4569. */
  4570. function checkTime(timeNum) {
  4571. if (timeNum < 10)
  4572. return "0" + timeNum;
  4573. return timeNum;
  4574. }
  4575. /**
  4576. * 时间制修改 24小时制转12小时制
  4577. * @param hourNum 小时
  4578. * @returns
  4579. */
  4580. function timeSystemChange(hourNum) {
  4581. return hourNum > 12 ? hourNum - 12 : hourNum;
  4582. }
  4583. let timeRegexp = {
  4584. yyyy: time.getFullYear(),
  4585. /* 年 */
  4586. MM: checkTime(time.getMonth() + 1),
  4587. /* 月 */
  4588. dd: checkTime(time.getDate()),
  4589. /* 日 */
  4590. HH: checkTime(time.getHours()),
  4591. /* 时 (24小时制) */
  4592. hh: checkTime(timeSystemChange(time.getHours())),
  4593. /* 时 (12小时制) */
  4594. mm: checkTime(time.getMinutes()),
  4595. /* 分 */
  4596. ss: checkTime(time.getSeconds()),
  4597. /* 秒 */
  4598. };
  4599. Object.keys(timeRegexp).forEach(function (key) {
  4600. let replaecRegexp = new RegExp(key, "g");
  4601. formatType = formatType.replace(replaecRegexp, timeRegexp[key]);
  4602. });
  4603. return formatType;
  4604. }
  4605. formatToTimeStamp(text) {
  4606. /* 把字符串格式的时间(完整,包括日期和时间)格式化成时间 */
  4607. if (typeof text !== "string") {
  4608. throw new Error("Utils.formatToTimeStamp 参数 text 必须为 string 类型");
  4609. }
  4610. if (text.length === 8) {
  4611. /* 该字符串只有时分秒 */
  4612. let today = new Date();
  4613. text =
  4614. today.getFullYear() +
  4615. "-" +
  4616. (today.getMonth() + 1) +
  4617. "-" +
  4618. today.getDate() +
  4619. " " +
  4620. text;
  4621. }
  4622. text = text.substring(0, 19);
  4623. text = text.replace(/-/g, "/");
  4624. let timestamp = new Date(text).getTime();
  4625. return timestamp;
  4626. }
  4627. /**
  4628. * gbk格式的url编码,来自https://gf.qytechs.cn/zh-CN/scripts/427726-gbk-url-js
  4629. * @example
  4630. * let gbkEncoder = new Utils.GBKEncoder();
  4631. * gbkEncoder.encode("测试");
  4632. * > '%B2%E2%CA%D4'
  4633. * gbkEncoder.decode("%B2%E2%CA%D4");
  4634. * > 测试
  4635. */
  4636. GBKEncoder = GBKEncoder;
  4637. /**
  4638. * 获取 transitionend 的在各个浏览器的兼容名
  4639. */
  4640. getTransitionEndNameList() {
  4641. return [
  4642. "webkitTransitionEnd",
  4643. "mozTransitionEnd",
  4644. "MSTransitionEnd",
  4645. "otransitionend",
  4646. "transitionend",
  4647. ];
  4648. }
  4649. /**
  4650. * 获取 animationend 的在各个浏览器的兼容名
  4651. */
  4652. getAnimationEndNameList() {
  4653. return [
  4654. "webkitAnimationEnd",
  4655. "mozAnimationEnd",
  4656. "MSAnimationEnd",
  4657. "oanimationend",
  4658. "animationend",
  4659. ];
  4660. }
  4661. getArrayLastValue(targetObj) {
  4662. return targetObj[targetObj.length - 1];
  4663. }
  4664. getArrayRealValue(...args) {
  4665. let result = null;
  4666. for (let arg of args) {
  4667. if (typeof arg === "function") {
  4668. /* 方法 */
  4669. arg = arg();
  4670. }
  4671. if (arg != null) {
  4672. result = arg;
  4673. break;
  4674. }
  4675. }
  4676. return result;
  4677. }
  4678. getDaysDifference(timestamp1 = Date.now(), timestamp2 = Date.now(), type = "天") {
  4679. type = type.trim();
  4680. if (timestamp1.toString().length === 10) {
  4681. timestamp1 = timestamp1 * 1000;
  4682. }
  4683. if (timestamp2.toString().length === 10) {
  4684. timestamp2 = timestamp2 * 1000;
  4685. }
  4686. let smallTimeStamp = timestamp1 > timestamp2 ? timestamp2 : timestamp1;
  4687. let bigTimeStamp = timestamp1 > timestamp2 ? timestamp1 : timestamp2;
  4688. let oneSecond = 1000; /* 一秒的毫秒数 */
  4689. let oneMinute = 60 * oneSecond; /* 一分钟的毫秒数 */
  4690. let oneHour = 60 * oneMinute; /* 一小时的毫秒数 */
  4691. let oneDay = 24 * oneHour; /* 一天的毫秒数 */
  4692. let oneMonth = 30 * oneDay; /* 一个月的毫秒数(30天) */
  4693. let oneYear = 12 * oneMonth; /* 一年的毫秒数 */
  4694. let bigDate = new Date(bigTimeStamp);
  4695. let smallDate = new Date(smallTimeStamp);
  4696. let remainderValue = 1;
  4697. if (type === "年") {
  4698. remainderValue = oneYear;
  4699. }
  4700. else if (type === "月") {
  4701. remainderValue = oneMonth;
  4702. }
  4703. else if (type === "天") {
  4704. remainderValue = oneDay;
  4705. }
  4706. else if (type === "时") {
  4707. remainderValue = oneHour;
  4708. }
  4709. else if (type === "分") {
  4710. remainderValue = oneMinute;
  4711. }
  4712. else if (type === "秒") {
  4713. remainderValue = oneSecond;
  4714. }
  4715. let diffValue = Math.round(Math.abs((bigDate - smallDate) / remainderValue));
  4716. if (type === "auto") {
  4717. let timeDifference = bigTimeStamp - smallTimeStamp;
  4718. diffValue = Math.floor(timeDifference / (24 * 3600 * 1000));
  4719. if (diffValue > 0) {
  4720. diffValue = diffValue + "天";
  4721. }
  4722. else {
  4723. /* 计算出小时数 */
  4724. let leave1 = timeDifference % (24 * 3600 * 1000); /* 计算天数后剩余的毫秒数 */
  4725. let hours = Math.floor(leave1 / (3600 * 1000));
  4726. if (hours > 0) {
  4727. diffValue = hours + "小时";
  4728. }
  4729. else {
  4730. /* 计算相差分钟数 */
  4731. let leave2 = leave1 % (3600 * 1000); /* 计算小时数后剩余的毫秒数 */
  4732. let minutes = Math.floor(leave2 / (60 * 1000));
  4733. if (minutes > 0) {
  4734. diffValue = minutes + "分钟";
  4735. }
  4736. else {
  4737. /* 计算相差秒数 */
  4738. let leave3 = leave2 % (60 * 1000); /* 计算分钟数后剩余的毫秒数 */
  4739. let seconds = Math.round(leave3 / 1000);
  4740. diffValue = seconds + "秒";
  4741. }
  4742. }
  4743. }
  4744. }
  4745. return diffValue;
  4746. }
  4747. getElementSelector(element) {
  4748. let UtilsContext = this;
  4749. // @ts-ignore
  4750. if (!element)
  4751. return;
  4752. // @ts-ignore
  4753. if (!element.parentElement)
  4754. return;
  4755. /* 如果元素有id属性,则直接返回id选择器 */
  4756. if (element.id)
  4757. return "#" + element.id;
  4758. /* 递归地获取父元素的选择器 */
  4759. let selector = UtilsContext.getElementSelector(element.parentElement);
  4760. if (!selector) {
  4761. return element.tagName.toLowerCase();
  4762. }
  4763. /* 如果有多个相同类型的兄弟元素,则需要添加索引 */
  4764. if (element.parentElement.querySelectorAll(element.tagName).length > 1) {
  4765. let index = Array.prototype.indexOf.call(element.parentElement.children, element) +
  4766. 1;
  4767. selector +=
  4768. " > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
  4769. }
  4770. else {
  4771. selector += " > " + element.tagName.toLowerCase();
  4772. }
  4773. return selector;
  4774. }
  4775. /**
  4776. * 获取最大值
  4777. * @example
  4778. * Utils.getMaxValue([{1:123},{2:345},{3:456}],(index,value)=>{return parseInt(index)})
  4779. * > 2
  4780. */
  4781. getMaxValue(...args) {
  4782. let result = [...args];
  4783. let newResult = [];
  4784. if (result.length === 0) {
  4785. // @ts-ignore
  4786. return;
  4787. }
  4788. if (result.length > 1) {
  4789. if (result.length === 2 &&
  4790. typeof result[0] === "object" &&
  4791. typeof result[1] === "function") {
  4792. let data = result[0];
  4793. let handleDataFunc = result[1];
  4794. Object.keys(data).forEach((keyName) => {
  4795. newResult = [...newResult, handleDataFunc(keyName, data[keyName])];
  4796. });
  4797. }
  4798. else {
  4799. result.forEach((item) => {
  4800. if (!isNaN(parseFloat(item))) {
  4801. newResult = [...newResult, parseFloat(item)];
  4802. }
  4803. });
  4804. }
  4805. return Math.max(...newResult);
  4806. }
  4807. else {
  4808. result[0].forEach((item) => {
  4809. if (!isNaN(parseFloat(item))) {
  4810. newResult = [...newResult, parseFloat(item)];
  4811. }
  4812. });
  4813. return Math.max(...newResult);
  4814. }
  4815. }
  4816. getMaxZIndexNodeInfo(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
  4817. deviation = Number.isNaN(deviation) ? 1 : deviation;
  4818. const UtilsContext = this;
  4819. // 最大值2147483647
  4820. const maxZIndex = Math.pow(2, 31) - 1;
  4821. // 比较值2000000000
  4822. const maxZIndexCompare = 2 * Math.pow(10, 9);
  4823. // 当前页面最大的z-index
  4824. let zIndex = 0;
  4825. // 当前的最大z-index的元素,调试使用
  4826. // @ts-ignore
  4827. let maxZIndexNode = null;
  4828. /**
  4829. * 元素是否可见
  4830. * @param $css
  4831. */
  4832. function isVisibleNode($css) {
  4833. return $css.position !== "static" && $css.display !== "none";
  4834. }
  4835. /**
  4836. * 查询元素的z-index
  4837. * 并比较值是否是已获取的最大值
  4838. * @param $ele
  4839. */
  4840. function queryMaxZIndex($ele) {
  4841. if (typeof ignoreCallBack === "function") {
  4842. let ignoreResult = ignoreCallBack($ele);
  4843. if (typeof ignoreResult === "boolean" && !ignoreResult) {
  4844. return;
  4845. }
  4846. }
  4847. /** 元素的样式 */
  4848. const nodeStyle = UtilsContext.windowApi.window.getComputedStyle($ele);
  4849. /* 不对position为static和display为none的元素进行获取它们的z-index */
  4850. if (isVisibleNode(nodeStyle)) {
  4851. let nodeZIndex = parseInt(nodeStyle.zIndex);
  4852. if (!isNaN(nodeZIndex)) {
  4853. if (nodeZIndex > zIndex) {
  4854. // 赋值到全局
  4855. zIndex = nodeZIndex;
  4856. maxZIndexNode = $ele;
  4857. }
  4858. }
  4859. // 判断shadowRoot
  4860. if ($ele.shadowRoot != null && $ele instanceof ShadowRoot) {
  4861. $ele.shadowRoot.querySelectorAll("*").forEach(($shadowEle) => {
  4862. queryMaxZIndex($shadowEle);
  4863. });
  4864. }
  4865. }
  4866. }
  4867. target.querySelectorAll("*").forEach(($ele, index) => {
  4868. queryMaxZIndex($ele);
  4869. });
  4870. zIndex += deviation;
  4871. if (zIndex >= maxZIndexCompare) {
  4872. // 最好不要超过最大值
  4873. zIndex = maxZIndex;
  4874. }
  4875. return {
  4876. node: maxZIndexNode,
  4877. zIndex: zIndex,
  4878. };
  4879. }
  4880. getMaxZIndex(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
  4881. return this.getMaxZIndexNodeInfo(deviation, target, ignoreCallBack).zIndex;
  4882. }
  4883. getMinValue(...args) {
  4884. let result = [...args];
  4885. let newResult = [];
  4886. if (result.length === 0) {
  4887. // @ts-ignore
  4888. return;
  4889. }
  4890. if (result.length > 1) {
  4891. if (result.length === 2 &&
  4892. typeof result[0] === "object" &&
  4893. typeof result[1] === "function") {
  4894. let data = result[0];
  4895. let handleDataFunc = result[1];
  4896. Object.keys(data).forEach((keyName) => {
  4897. newResult = [...newResult, handleDataFunc(keyName, data[keyName])];
  4898. });
  4899. }
  4900. else {
  4901. result.forEach((item) => {
  4902. if (!isNaN(parseFloat(item))) {
  4903. newResult = [...newResult, parseFloat(item)];
  4904. }
  4905. });
  4906. }
  4907. return Math.min(...newResult);
  4908. }
  4909. else {
  4910. result[0].forEach((item) => {
  4911. if (!isNaN(parseFloat(item))) {
  4912. newResult = [...newResult, parseFloat(item)];
  4913. }
  4914. });
  4915. return Math.min(...newResult);
  4916. }
  4917. }
  4918. getRandomAndroidUA() {
  4919. let UtilsContext = this;
  4920. let mobileNameList = [
  4921. "LDN-LX3",
  4922. "RNE-L03",
  4923. "ASUS_X00ID Build/NMF26F",
  4924. "WAS-LX3",
  4925. "PRA-LX3",
  4926. "MYA-L03",
  4927. "Moto G Play",
  4928. "Moto C Build/NRD90M.063",
  4929. "Redmi Note 4 Build/NRD90M",
  4930. "HUAWEI VNS-L21 Build/HUAWEIVNS-L21",
  4931. "VTR-L09",
  4932. "TRT-LX3",
  4933. "M2003J15SC Build/RP1A.200720.011; wv",
  4934. "MI 13 Build/OPR1.170623.027; wv",
  4935. ];
  4936. let androidVersion = UtilsContext.getRandomValue(12, 14);
  4937. let randomMobile = UtilsContext.getRandomValue(mobileNameList);
  4938. let chromeVersion1 = UtilsContext.getRandomValue(115, 127);
  4939. let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
  4940. let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
  4941. let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
  4942. return `Mozilla/5.0 (Linux; Android ${androidVersion}; ${randomMobile}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Mobile Safari/537.36`;
  4943. }
  4944. getRandomValue(...args) {
  4945. let result = [...args];
  4946. if (result.length > 1) {
  4947. if (result.length === 2 &&
  4948. typeof result[0] === "number" &&
  4949. typeof result[1] === "number") {
  4950. let leftNumber = result[0] > result[1] ? result[1] : result[0];
  4951. let rightNumber = result[0] > result[1] ? result[0] : result[1];
  4952. return (Math.round(Math.random() * (rightNumber - leftNumber)) + leftNumber);
  4953. }
  4954. else {
  4955. return result[Math.floor(Math.random() * result.length)];
  4956. }
  4957. }
  4958. else if (result.length === 1) {
  4959. let paramData = result[0];
  4960. if (Array.isArray(paramData)) {
  4961. return paramData[Math.floor(Math.random() * paramData.length)];
  4962. }
  4963. else if (typeof paramData === "object" &&
  4964. Object.keys(paramData).length > 0) {
  4965. let paramObjDataKey = Object.keys(paramData)[Math.floor(Math.random() * Object.keys(paramData).length)];
  4966. return paramData[paramObjDataKey];
  4967. }
  4968. else {
  4969. return paramData;
  4970. }
  4971. }
  4972. }
  4973. /**
  4974. * 获取随机的电脑端User-Agent
  4975. * + Mozilla/5.0:以前用于Netscape浏览器,目前大多数浏览器UA都会带有
  4976. * + Windows NT 13:代表Window11系统
  4977. * + Windows NT 10.0:代表Window10系统
  4978. * + Windows NT 6.1:代表windows7系统
  4979. * + WOW64:Windows-on-Windows 64-bit,32位的应用程序运行于此64位处理器上
  4980. * + Win64:64位
  4981. * + AppleWebKit/537.36:浏览器内核
  4982. * + KHTML:HTML排版引擎
  4983. * + like Gecko:这不是Geckeo 浏览器,但是运行起来像Geckeo浏览器
  4984. * + Chrome/106.0.5068.19:Chrome版本号
  4985. * + Safari/537.36:宣称自己是Safari?
  4986. * @returns 返回随机字符串
  4987. * @example
  4988. * Utils.getRandomPCUA();
  4989. * > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
  4990. **/
  4991. getRandomPCUA() {
  4992. let UtilsContext = this;
  4993. let chromeVersion1 = UtilsContext.getRandomValue(115, 127);
  4994. let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
  4995. let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
  4996. let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
  4997. return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Safari/537.36`;
  4998. }
  4999. /**
  5000. * 获取元素上的使用React框架的实例属性,目前包括reactFiber、reactProps、reactEvents、reactEventHandlers、reactInternalInstance
  5001. * @param element 需要获取的目标元素
  5002. * @returns
  5003. * @example
  5004. * Utils.getReactObj(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
  5005. */
  5006. getReactObj(element) {
  5007. let result = {};
  5008. Object.keys(element).forEach((domPropsName) => {
  5009. if (domPropsName.startsWith("__react")) {
  5010. let propsName = domPropsName.replace(/__(.+)\$.+/i, "$1");
  5011. if (propsName in result) ;
  5012. else {
  5013. result[propsName] = element[domPropsName];
  5014. }
  5015. }
  5016. });
  5017. return result;
  5018. }
  5019. /**
  5020. * 获取对象上的Symbol属性,如果没设置keyName,那么返回一个对象,对象是所有遍历到的Symbol对象
  5021. * @param target 目标对象
  5022. * @param keyName (可选)Symbol名或者Symbol对象
  5023. */
  5024. getSymbol(target, keyName) {
  5025. if (typeof target !== "object") {
  5026. throw new TypeError("target不是一个对象");
  5027. }
  5028. let objectsSymbols = Object.getOwnPropertySymbols(target);
  5029. if (typeof keyName === "string") {
  5030. let findSymbol = objectsSymbols.find((key) => {
  5031. return key.toString() === keyName;
  5032. });
  5033. if (findSymbol) {
  5034. return target[findSymbol];
  5035. }
  5036. }
  5037. else if (typeof keyName === "symbol") {
  5038. let findSymbol = objectsSymbols.find((key) => {
  5039. return key === keyName;
  5040. });
  5041. if (findSymbol) {
  5042. return target[findSymbol];
  5043. }
  5044. }
  5045. else {
  5046. let result = {};
  5047. objectsSymbols.forEach((item) => {
  5048. result[item] = target[item];
  5049. });
  5050. return result;
  5051. }
  5052. }
  5053. /**
  5054. * 获取文本的字符长度
  5055. * @param text
  5056. * @example
  5057. * Utils.getTextLength("测试文本")
  5058. * > 12
  5059. */
  5060. getTextLength(text) {
  5061. let encoder = new TextEncoder();
  5062. let bytes = encoder.encode(text);
  5063. return bytes.length;
  5064. }
  5065. getTextStorageSize(text, addType = true) {
  5066. let UtilsContext = this;
  5067. return UtilsContext.formatByteToSize(UtilsContext.getTextLength(text), addType);
  5068. }
  5069. getThunderUrl(url) {
  5070. if (url == null) {
  5071. throw new TypeError("url不能为空");
  5072. }
  5073. if (typeof url !== "string") {
  5074. throw new TypeError("url必须是string类型");
  5075. }
  5076. if (url.trim() === "") {
  5077. throw new TypeError("url不能为空字符串或纯空格");
  5078. }
  5079. return `thunder://${this.windowApi.globalThis.btoa("AA" + url + "ZZ")}`;
  5080. }
  5081. /**
  5082. * 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
  5083. * @example
  5084. let GM_cookie = new Utils.GM_Cookie();
  5085. GM_cookie.list({name:"xxx_cookie_xxx"},function(cookies,error){
  5086. if (!error) {
  5087. console.log(cookies);
  5088. console.log(cookies.value);
  5089. } else {
  5090. console.error(error);
  5091. }
  5092. });
  5093. GM_cookie.set({name:"xxx_cookie_test_xxx",value:"这是Cookie测试值"},function(error){
  5094. if (error) {
  5095. console.error(error);
  5096. } else {
  5097. console.log('Cookie set successfully.');
  5098. }
  5099. })
  5100. GM_cookie.delete({name:"xxx_cookie_test_xxx"},function(error){
  5101. if (error) {
  5102. console.error(error);
  5103. } else {
  5104. console.log('Cookie set successfully.');
  5105. }
  5106. })
  5107. **/
  5108. GM_Cookie = UtilsGMCookie;
  5109. /**
  5110. * 注册(不可用)油猴菜单,要求本地存储的键名不能存在其它键名`GM_Menu_Local_Map`会冲突/覆盖
  5111. * @example
  5112. let GM_Menu = new Utils.GM_Menu({
  5113. data: [
  5114. {
  5115. menu_key: "menu_key",
  5116. text: "测试按钮",
  5117. enable: true,
  5118. accessKey: "a",
  5119. autoClose: false,
  5120. showText(text, enable) {
  5121. return "[" + (enable ? "√" : "×") + "]" + text;
  5122. },
  5123. callback(data) {
  5124. console.log("点击菜单,值修改为", data.enable);
  5125. },
  5126. },
  5127. ],
  5128. autoReload: false,
  5129. GM_getValue,
  5130. GM_setValue,
  5131. GM_registerMenuCommand,
  5132. GM_unregisterMenuCommand,
  5133. });
  5134. // 获取某个菜单项的值
  5135. GM_Menu.get("menu_key");
  5136. > true
  5137. // 获取某个菜单项的开启/关闭后显示的文本
  5138. GM_Menu.getShowTextValue("menu_key");
  5139. > √测试按钮
  5140. // 添加键为menu_key2的菜单项
  5141. GM_Menu.add({
  5142. key:"menu_key2",
  5143. text: "测试按钮2",
  5144. enable: false,
  5145. showText(text,enable){
  5146. return "[" + (enable ? "√" : "×") + "]" + text;
  5147. },
  5148. callback(data){
  5149. console.log("点击菜单,值修改为",data.enable);
  5150. }
  5151. });
  5152. // 使用数组的方式添加多个菜单,如menu_key3、menu_key4
  5153. GM_Menu.add([
  5154. {
  5155. key:"menu_key3",
  5156. text: "测试按钮3",
  5157. enable: false,
  5158. showText(text,enable){
  5159. return "[" + (enable ? "√" : "×") + "]" + text;
  5160. },
  5161. callback(data){
  5162. console.log("点击菜单,值修改为",data.enable);
  5163. }
  5164. },
  5165. {
  5166. key:"menu_key4",
  5167. text: "测试按钮4",
  5168. enable: false,
  5169. showText(text,enable){
  5170. return "[" + (enable ? "√" : "×") + "]" + text;
  5171. },
  5172. callback(data){
  5173. console.log("点击菜单,值修改为",data.enable);
  5174. }
  5175. }
  5176. ]);
  5177. // 更新键为menu_key的显示文字和点击回调
  5178. GM_Menu.update({
  5179. menu_key:{
  5180. text: "更新后的测试按钮",
  5181. enable: true,
  5182. showText(text,enable){
  5183. return "[" + (enable ? "√" : "×") + "]" + text;
  5184. },
  5185. callback(data){
  5186. console.log("点击菜单更新后的测试按钮,新值修改为",data.enable);
  5187. }
  5188. }
  5189. });
  5190. // 删除键为menu_key的菜单
  5191. GM_Menu.delete("menu_key");
  5192. **/
  5193. GM_Menu = GMMenu;
  5194. /**
  5195. * 基于Function prototype,能够勾住和释放任何函数
  5196. *
  5197. * .hook
  5198. * + realFunc {string} 用于保存原始函数的函数名称,用于unHook
  5199. * + hookFunc {string} 替换的hook函数
  5200. * + context {object} 目标函数所在对象,用于hook非window对象下的函数,如String.protype.slice,carInstance1
  5201. * + methodName {string} 匿名函数需显式传入目标函数名eg:this.Begin = function(){....};}
  5202. *
  5203. * .unhook
  5204. * + realFunc {string} 用于保存原始函数的函数名称,用于unHook
  5205. * + funcName {string} 被Hook的函数名称
  5206. * + context {object} 目标函数所在对象,用于hook非window对象下的函数,如String.protype.slice,carInstance1
  5207. * @example
  5208. let hook = new Utils.Hooks();
  5209. hook.initEnv();
  5210. function myFunction(){
  5211. console.log("我自己需要执行的函数");
  5212. }
  5213. function testFunction(){
  5214. console.log("正常执行的函数");
  5215. }
  5216. testFunction.hook(testFunction,myFunction,window);
  5217. **/
  5218. Hooks = Hooks;
  5219. /**
  5220. * 为减少代码量和回调,把GM_xmlhttpRequest封装
  5221. * 文档地址: https://www.tampermonkey.net/documentation.php?ext=iikm
  5222. * 其中onloadstart、onprogress、onreadystatechange是回调形式,onabort、ontimeout、onerror可以设置全局回调函数
  5223. * @param _GM_xmlHttpRequest_ 油猴中的GM_xmlhttpRequest
  5224. * @example
  5225. let httpx = new Utils.Httpx(GM_xmlhttpRequest);
  5226. let postResp = await httpx.post({
  5227. url:url,
  5228. data:JSON.stringify({
  5229. test:1
  5230. }),
  5231. timeout: 5000
  5232. });
  5233. console.log(postResp);
  5234. > {
  5235. status: true,
  5236. data: {responseText: "...", response: xxx,...},
  5237. msg: "请求完毕",
  5238. type: "onload",
  5239. }
  5240. if(postResp === "onload" && postResp.status){
  5241. // onload
  5242. }else if(postResp === "ontimeout"){
  5243. // ontimeout
  5244. }
  5245. * @example
  5246. // 也可以先配置全局参数
  5247. let httpx = new Utils.Httpx(GM_xmlhttpRequest);
  5248. httpx.config({
  5249. timeout: 5000,
  5250. async: false,
  5251. responseType: "html",
  5252. redirect: "follow",
  5253. })
  5254. // 优先级为 默认details < 全局details < 单独的details
  5255. */
  5256. Httpx = Httpx;
  5257. /**
  5258. * 浏览器端的indexedDB操作封装
  5259. * @example
  5260. let db = new Utils.indexedDB('web_DB', 'nav_text')
  5261. let data = {name:'管理员', roleId: 1, type: 1};
  5262. db.save('list',data).then((resolve)=>{
  5263. console.log(resolve,'存储成功')
  5264. })
  5265. db.get('list').then((resolve)=>{
  5266. console.log(resolve,'查询成功')
  5267. })
  5268. db.getPaging('list',20,10).then((resolve)=>{
  5269. console.log(resolve,'查询分页偏移第20,一共10行成功');
  5270. })
  5271. db.delete('list').then(resolve=>{
  5272. console.log(resolve,'删除成功---->>>>>>name')
  5273. })
  5274. db.deleteAll().then(resolve=>{
  5275. console.log(resolve,'清除数据库---->>>>>>name')
  5276. })
  5277. **/
  5278. indexedDB = indexedDB;
  5279. isNativeFunc(target) {
  5280. return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
  5281. }
  5282. isNearBottom(...args) {
  5283. let nearBottomHeight = 50;
  5284. let checkWindow = () => {
  5285. // 已滚动的距离
  5286. let scrollTop = this.windowApi.window.pageYOffset ||
  5287. this.windowApi.document.documentElement.scrollTop;
  5288. // 视窗高度
  5289. let viewportHeight = this.windowApi.window.innerHeight ||
  5290. this.windowApi.document.documentElement.clientHeight;
  5291. // 最大滚动距离
  5292. let maxScrollHeight = this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
  5293. return scrollTop + viewportHeight >= maxScrollHeight;
  5294. };
  5295. let checkNode = ($ele) => {
  5296. // 已滚动的距离
  5297. let scrollTop = $ele.scrollTop;
  5298. // 视窗高度
  5299. let viewportHeight = $ele.clientHeight;
  5300. // 最大滚动距离
  5301. let maxScrollHeight = $ele.scrollHeight - viewportHeight - nearBottomHeight;
  5302. return scrollTop >= maxScrollHeight;
  5303. };
  5304. let firstArg = args[0];
  5305. if (args.length === 0 || typeof args[0] === "number") {
  5306. // nearBottomHeight
  5307. //
  5308. return checkWindow();
  5309. }
  5310. else if (typeof args[0] === "object" && args[0] instanceof HTMLElement) {
  5311. // target
  5312. // target,nearBottomHeight
  5313. if (typeof args[1] === "number" && !Number.isNaN(args[1])) {
  5314. nearBottomHeight = args[1];
  5315. }
  5316. return checkNode(args[0]);
  5317. }
  5318. else {
  5319. throw new TypeError("参数1类型错误" + typeof firstArg);
  5320. }
  5321. }
  5322. isDOM(target) {
  5323. return target instanceof Node;
  5324. }
  5325. isFullscreenEnabled() {
  5326. return !!(this.windowApi.document.fullscreenEnabled ||
  5327. this.windowApi.document.webkitFullScreenEnabled ||
  5328. this.windowApi.document.mozFullScreenEnabled ||
  5329. this.windowApi.document.msFullScreenEnabled);
  5330. }
  5331. isJQuery(target) {
  5332. let result = false;
  5333. // @ts-ignore
  5334. if (typeof jQuery === "object" && target instanceof jQuery) {
  5335. result = true;
  5336. }
  5337. if (target == null) {
  5338. return false;
  5339. }
  5340. if (typeof target === "object") {
  5341. /* 也有种可能,这个jQuery对象是1.8.3版本的,页面中的jQuery是3.4.1版本的 */
  5342. let jQueryProps = [
  5343. "add",
  5344. "addBack",
  5345. "addClass",
  5346. "after",
  5347. "ajaxComplete",
  5348. "ajaxError",
  5349. "ajaxSend",
  5350. "ajaxStart",
  5351. "ajaxStop",
  5352. "ajaxSuccess",
  5353. "animate",
  5354. "append",
  5355. "appendTo",
  5356. "attr",
  5357. "before",
  5358. "bind",
  5359. "blur",
  5360. "change",
  5361. "children",
  5362. "clearQueue",
  5363. "click",
  5364. "clone",
  5365. "closest",
  5366. "constructor",
  5367. "contents",
  5368. "contextmenu",
  5369. "css",
  5370. "data",
  5371. "dblclick",
  5372. "delay",
  5373. "delegate",
  5374. "dequeue",
  5375. "each",
  5376. "empty",
  5377. "end",
  5378. "eq",
  5379. "extend",
  5380. "fadeIn",
  5381. "fadeOut",
  5382. "fadeTo",
  5383. "fadeToggle",
  5384. "filter",
  5385. "find",
  5386. "first",
  5387. "focus",
  5388. "focusin",
  5389. "focusout",
  5390. "get",
  5391. "has",
  5392. "hasClass",
  5393. "height",
  5394. "hide",
  5395. "hover",
  5396. "html",
  5397. "index",
  5398. "init",
  5399. "innerHeight",
  5400. "innerWidth",
  5401. "insertAfter",
  5402. "insertBefore",
  5403. "is",
  5404. "jquery",
  5405. "keydown",
  5406. "keypress",
  5407. "keyup",
  5408. "last",
  5409. "load",
  5410. "map",
  5411. "mousedown",
  5412. "mouseenter",
  5413. "mouseleave",
  5414. "mousemove",
  5415. "mouseout",
  5416. "mouseover",
  5417. "mouseup",
  5418. "next",
  5419. "nextAll",
  5420. "not",
  5421. "off",
  5422. "offset",
  5423. "offsetParent",
  5424. "on",
  5425. "one",
  5426. "outerHeight",
  5427. "outerWidth",
  5428. "parent",
  5429. "parents",
  5430. "position",
  5431. "prepend",
  5432. "prependTo",
  5433. "prev",
  5434. "prevAll",
  5435. "prevUntil",
  5436. "promise",
  5437. "prop",
  5438. "pushStack",
  5439. "queue",
  5440. "ready",
  5441. "remove",
  5442. "removeAttr",
  5443. "removeClass",
  5444. "removeData",
  5445. "removeProp",
  5446. "replaceAll",
  5447. "replaceWith",
  5448. "resize",
  5449. "scroll",
  5450. "scrollLeft",
  5451. "scrollTop",
  5452. "select",
  5453. "show",
  5454. "siblings",
  5455. "slice",
  5456. "slideDown",
  5457. "slideToggle",
  5458. "slideUp",
  5459. "sort",
  5460. "splice",
  5461. "text",
  5462. "toArray",
  5463. "toggle",
  5464. "toggleClass",
  5465. "trigger",
  5466. "triggerHandler",
  5467. "unbind",
  5468. "width",
  5469. "wrap",
  5470. ];
  5471. for (const jQueryPropsName of jQueryProps) {
  5472. if (!(jQueryPropsName in target)) {
  5473. result = false;
  5474. /* console.log(jQueryPropsName); */
  5475. break;
  5476. }
  5477. else {
  5478. result = true;
  5479. }
  5480. }
  5481. }
  5482. return result;
  5483. }
  5484. isPhone(userAgent = navigator.userAgent) {
  5485. return Boolean(/(iPhone|iPad|iPod|iOS|Android|Mobile)/i.test(userAgent));
  5486. }
  5487. isSameChars(targetStr, coefficient = 1) {
  5488. if (typeof targetStr !== "string") {
  5489. throw new TypeError("参数 str 必须是 string 类型");
  5490. }
  5491. if (targetStr.length < 2) {
  5492. return false;
  5493. }
  5494. targetStr = targetStr.toLowerCase();
  5495. const targetCharMap = {};
  5496. let targetStrLength = 0;
  5497. for (const char of targetStr) {
  5498. if (Reflect.has(targetCharMap, char)) {
  5499. targetCharMap[char]++;
  5500. }
  5501. else {
  5502. targetCharMap[char] = 1;
  5503. }
  5504. targetStrLength++;
  5505. }
  5506. let result = false;
  5507. for (const char in targetCharMap) {
  5508. if (targetCharMap[char] / targetStrLength >= coefficient) {
  5509. result = true;
  5510. break;
  5511. }
  5512. }
  5513. return result;
  5514. }
  5515. isNotNull(...args) {
  5516. let UtilsContext = this;
  5517. return !UtilsContext.isNull.apply(this, args);
  5518. }
  5519. isNull(...args) {
  5520. let result = true;
  5521. let checkList = [...args];
  5522. for (const objItem of checkList) {
  5523. let itemResult = false;
  5524. if (objItem === null || objItem === undefined) {
  5525. itemResult = true;
  5526. }
  5527. else {
  5528. switch (typeof objItem) {
  5529. case "object":
  5530. if (typeof objItem[Symbol.iterator] === "function") {
  5531. /* 可迭代 */
  5532. itemResult = objItem.length === 0;
  5533. }
  5534. else {
  5535. itemResult = Object.keys(objItem).length === 0;
  5536. }
  5537. break;
  5538. case "number":
  5539. itemResult = objItem === 0;
  5540. break;
  5541. case "string":
  5542. itemResult =
  5543. objItem.trim() === "" ||
  5544. objItem === "null" ||
  5545. objItem === "undefined";
  5546. break;
  5547. case "boolean":
  5548. itemResult = !objItem;
  5549. break;
  5550. case "function":
  5551. let funcStr = objItem.toString().replace(/\s/g, "");
  5552. /* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
  5553. itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
  5554. break;
  5555. }
  5556. }
  5557. result = result && itemResult;
  5558. }
  5559. return result;
  5560. }
  5561. isThemeDark() {
  5562. return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
  5563. .matches;
  5564. }
  5565. /**
  5566. * 判断元素是否在页面中可见
  5567. * @param element 需要检查的元素,可以是普通元素|数组形式的元素|通过querySelectorAll获取的元素数组
  5568. * @param inView
  5569. * + true 在窗口可视区域
  5570. * + false 不在窗口可视区域
  5571. * @returns
  5572. * + true 可见
  5573. * + false 不可见
  5574. * @example
  5575. * Utils.isVisible(document.documentElement)
  5576. * > true
  5577. */
  5578. isVisible(element, inView = false) {
  5579. let needCheckDomList = [];
  5580. if (element instanceof Array || element instanceof NodeList) {
  5581. element = element;
  5582. needCheckDomList = [...element];
  5583. }
  5584. else {
  5585. needCheckDomList = [element];
  5586. }
  5587. let result = true;
  5588. for (const domItem of needCheckDomList) {
  5589. let domDisplay = this.windowApi.window.getComputedStyle(domItem);
  5590. if (domDisplay.display === "none") {
  5591. result = false;
  5592. }
  5593. else {
  5594. let domClientRect = domItem.getBoundingClientRect();
  5595. if (inView) {
  5596. let viewportWidth = this.windowApi.window.innerWidth ||
  5597. this.windowApi.document.documentElement.clientWidth;
  5598. let viewportHeight = this.windowApi.window.innerHeight ||
  5599. this.windowApi.document.documentElement.clientHeight;
  5600. result = !(domClientRect.right < 0 ||
  5601. domClientRect.left > viewportWidth ||
  5602. domClientRect.bottom < 0 ||
  5603. domClientRect.top > viewportHeight);
  5604. }
  5605. else {
  5606. result = Boolean(domItem.getClientRects().length);
  5607. }
  5608. }
  5609. if (!result) {
  5610. /* 有一个不可见就退出循环 */
  5611. break;
  5612. }
  5613. }
  5614. return result;
  5615. }
  5616. isWebView_Via() {
  5617. let result = true;
  5618. let UtilsContext = this;
  5619. if (typeof this.windowApi.top.window.via === "object") {
  5620. for (const key in Object.values(this.windowApi.top.window.via)) {
  5621. if (Reflect.has(this.windowApi.top.window.via, key)) {
  5622. let objValueFunc = this.windowApi.top.window.via[key];
  5623. if (typeof objValueFunc === "function" &&
  5624. UtilsContext.isNativeFunc(objValueFunc)) {
  5625. result = true;
  5626. }
  5627. else {
  5628. result = false;
  5629. break;
  5630. }
  5631. }
  5632. }
  5633. }
  5634. else {
  5635. result = false;
  5636. }
  5637. return result;
  5638. }
  5639. isWebView_X() {
  5640. let result = true;
  5641. let UtilsContext = this;
  5642. if (typeof this.windowApi.top.window.mbrowser === "object") {
  5643. for (const key in Object.values(this.windowApi.top.window.mbrowser)) {
  5644. if (Reflect.has(this.windowApi.top.window.mbrowser, key)) {
  5645. let objValueFunc = this.windowApi.top.window.mbrowser[key];
  5646. if (typeof objValueFunc === "function" &&
  5647. UtilsContext.isNativeFunc(objValueFunc)) {
  5648. result = true;
  5649. }
  5650. else {
  5651. result = false;
  5652. break;
  5653. }
  5654. }
  5655. }
  5656. }
  5657. else {
  5658. result = false;
  5659. }
  5660. return result;
  5661. }
  5662. parseObjectToArray(target) {
  5663. if (typeof target !== "object") {
  5664. throw new Error("Utils.parseObjectToArray 参数 target 必须为 object 类型");
  5665. }
  5666. let result = [];
  5667. Object.keys(target).forEach(function (keyName) {
  5668. result = result.concat(target[keyName]);
  5669. });
  5670. return result;
  5671. }
  5672. /**
  5673. * 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
  5674. * @example
  5675. let lock = new Utils.LockFunction(()=>{console.log(1)}))
  5676. lock.run();
  5677. > 1
  5678. * @example
  5679. let lock = new Utils.LockFunction(()=>{console.log(1)}),true) -- 异步操作
  5680. await lock.run();
  5681. > 1
  5682. **/
  5683. LockFunction = LockFunction;
  5684. /**
  5685. * 日志对象
  5686. * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}}
  5687. * @example
  5688. let log = new Utils.Log(GM_info);
  5689. log.info("普通输出");
  5690. > 普通输出
  5691. log.success("成功输出");
  5692. > 成功输出
  5693. log.error("错误输出");
  5694. > 错误输出
  5695. log.warn("警告输出");
  5696. > 警告输出
  5697. log.tag = "自定义tag信息";
  5698. log.info("自定义info的颜色","#e0e0e0");
  5699. > 自定义info的颜色
  5700. log.config({
  5701. successColor: "#31dc02",
  5702. errorColor: "#e02d2d",
  5703. infoColor: "black",
  5704. })
  5705. log.success("颜色为#31dc02");
  5706. > 颜色为#31dc02
  5707. */
  5708. Log = Log;
  5709. mergeArrayToString(data, handleFunc) {
  5710. if (!(data instanceof Array)) {
  5711. throw new Error("Utils.mergeArrayToString 参数 data 必须为 Array 类型");
  5712. }
  5713. let content = "";
  5714. if (typeof handleFunc === "function") {
  5715. data.forEach((item) => {
  5716. content += handleFunc(item);
  5717. });
  5718. }
  5719. else if (typeof handleFunc === "string") {
  5720. data.forEach((item) => {
  5721. content += item[handleFunc];
  5722. });
  5723. }
  5724. else {
  5725. data.forEach((item) => {
  5726. Object.values(item)
  5727. .filter((item2) => typeof item2 === "string")
  5728. .forEach((item3) => {
  5729. content += item3;
  5730. });
  5731. });
  5732. }
  5733. return content;
  5734. }
  5735. mutationObserver(target, observer_config) {
  5736. let UtilsContext = this;
  5737. let default_obverser_config = {
  5738. /* 监听到元素有反馈,需执行的函数 */
  5739. callback: () => { },
  5740. config: {
  5741. /**
  5742. * + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
  5743. * + false (默认) 不生效
  5744. */
  5745. subtree: void 0,
  5746. /**
  5747. * + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
  5748. * + false (默认) 不生效
  5749. */
  5750. childList: void 0,
  5751. /**
  5752. * + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
  5753. * + false (默认) 不生效
  5754. */
  5755. attributes: void 0,
  5756. /**
  5757. * 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
  5758. */
  5759. attributeFilter: void 0,
  5760. /**
  5761. * + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
  5762. * + false (默认) 不生效
  5763. */
  5764. attributeOldValue: void 0,
  5765. /**
  5766. * + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
  5767. * + false (默认) 不生效
  5768. */
  5769. characterData: void 0,
  5770. /**
  5771. * + true 记录前一个被监听的节点中发生的文本变化
  5772. * + false (默认) 不生效
  5773. */
  5774. characterDataOldValue: void 0,
  5775. },
  5776. immediate: false,
  5777. };
  5778. observer_config = UtilsContext.assign(default_obverser_config, observer_config);
  5779. let windowMutationObserver = this.windowApi.window.MutationObserver ||
  5780. this.windowApi.window.webkitMutationObserver ||
  5781. this.windowApi.window.MozMutationObserver;
  5782. // 观察者对象
  5783. let mutationObserver = new windowMutationObserver(function (mutations, observer) {
  5784. if (typeof observer_config.callback === "function") {
  5785. observer_config.callback(mutations, observer);
  5786. }
  5787. });
  5788. if (Array.isArray(target) || target instanceof NodeList) {
  5789. // 传入的是数组或者元素数组
  5790. target.forEach((item) => {
  5791. mutationObserver.observe(item, observer_config.config);
  5792. });
  5793. }
  5794. else if (UtilsContext.isJQuery(target)) {
  5795. /* 传入的参数是jQuery对象 */
  5796. target.each((index, item) => {
  5797. mutationObserver.observe(item, observer_config.config);
  5798. });
  5799. }
  5800. else {
  5801. mutationObserver.observe(target, observer_config.config);
  5802. }
  5803. if (observer_config.immediate) {
  5804. /* 主动触发一次 */
  5805. if (typeof observer_config.callback === "function") {
  5806. observer_config.callback([], mutationObserver);
  5807. }
  5808. }
  5809. return mutationObserver;
  5810. }
  5811. /**
  5812. * 使用观察器观察元素出现在视图内,出现的话触发回调
  5813. * @param target 目标元素
  5814. * @param callback 触发的回调
  5815. * @param options 观察器配置
  5816. * @example
  5817. * Utils.mutationVisible(document.querySelector("div.xxxx"),(entries,observer)=>{
  5818. * console.log("该元素出现在视图内");
  5819. * }))
  5820. */
  5821. mutationVisible(target, callback, options) {
  5822. if (typeof IntersectionObserver === "undefined") {
  5823. throw new TypeError("IntersectionObserver is not defined");
  5824. }
  5825. if (target == null) {
  5826. throw new TypeError("mutatuinVisible target is null");
  5827. }
  5828. let defaultOptions = {
  5829. root: null,
  5830. rootMargin: "0px 0px 0px 0px",
  5831. threshold: [0.01, 0.99],
  5832. };
  5833. defaultOptions = this.assign(defaultOptions, options || {});
  5834. let intersectionObserver = new IntersectionObserver((entries, observer) => {
  5835. if (entries[0].isIntersecting) {
  5836. if (typeof callback === "function") {
  5837. callback(entries, observer);
  5838. }
  5839. }
  5840. }, defaultOptions);
  5841. if (Array.isArray(target)) {
  5842. target.forEach((item) => {
  5843. intersectionObserver.observe(item);
  5844. });
  5845. }
  5846. else {
  5847. intersectionObserver.observe(target);
  5848. }
  5849. }
  5850. /**
  5851. * 去除全局window下的Utils,返回控制权
  5852. * @example
  5853. * let utils = Utils.noConflict();
  5854. * > ...
  5855. */
  5856. noConflict() {
  5857. if (this.windowApi.window.Utils) {
  5858. Reflect.deleteProperty(this.windowApi.window, "Utils");
  5859. }
  5860. this.windowApi.window.Utils = utils;
  5861. return utils;
  5862. }
  5863. noConflictFunc(needReleaseObject, needReleaseName, functionNameList = [], release = true) {
  5864. let UtilsContext = this;
  5865. if (typeof needReleaseObject !== "object") {
  5866. throw new Error("Utils.noConflictFunc 参数 needReleaseObject 必须为 object 类型");
  5867. }
  5868. if (typeof needReleaseName !== "string") {
  5869. throw new Error("Utils.noConflictFunc 参数 needReleaseName 必须为 string 类型");
  5870. }
  5871. if (!Array.isArray(functionNameList)) {
  5872. throw new Error("Utils.noConflictFunc 参数 functionNameList 必须为 Array 类型");
  5873. }
  5874. let needReleaseKey = "__" + needReleaseName;
  5875. /**
  5876. * 释放所有
  5877. */
  5878. function releaseAll() {
  5879. if (typeof UtilsContext.windowApi.window[needReleaseKey] !==
  5880. "undefined") {
  5881. /* 已存在 */
  5882. return;
  5883. }
  5884. UtilsContext.windowApi.window[needReleaseKey] =
  5885. UtilsContext.deepClone(needReleaseObject);
  5886. Object.values(needReleaseObject).forEach((value) => {
  5887. if (typeof value === "function") {
  5888. needReleaseObject[value.name] = () => { };
  5889. }
  5890. });
  5891. }
  5892. /**
  5893. * 释放单个
  5894. */
  5895. function releaseOne() {
  5896. Array.from(functionNameList).forEach((item) => {
  5897. Object.values(needReleaseObject).forEach((value) => {
  5898. if (typeof value === "function") {
  5899. if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
  5900. "undefined") {
  5901. UtilsContext.windowApi.window[needReleaseKey] = {};
  5902. }
  5903. if (item === value.name) {
  5904. UtilsContext.windowApi.window[needReleaseKey][value.name] = needReleaseObject[value.name];
  5905. needReleaseObject[value.name] = () => { };
  5906. }
  5907. }
  5908. });
  5909. });
  5910. }
  5911. /**
  5912. * 恢复所有
  5913. */
  5914. function recoveryAll() {
  5915. if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
  5916. "undefined") {
  5917. /* 未存在 */
  5918. return;
  5919. }
  5920. Object.assign(needReleaseObject, UtilsContext.windowApi.window[needReleaseKey]);
  5921. Reflect.deleteProperty(UtilsContext.windowApi.window, "needReleaseKey");
  5922. }
  5923. /**
  5924. * 恢复单个
  5925. */
  5926. function recoveryOne() {
  5927. if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
  5928. "undefined") {
  5929. /* 未存在 */
  5930. return;
  5931. }
  5932. Array.from(functionNameList).forEach((item) => {
  5933. if (UtilsContext.windowApi.window[needReleaseKey][item]) {
  5934. needReleaseObject[item] = UtilsContext.windowApi.window[needReleaseKey][item];
  5935. Reflect.deleteProperty(UtilsContext.windowApi.window[needReleaseKey], item);
  5936. if (Object.keys(UtilsContext.windowApi.window[needReleaseKey])
  5937. .length === 0) {
  5938. Reflect.deleteProperty(window, needReleaseKey);
  5939. }
  5940. }
  5941. });
  5942. }
  5943. if (release) {
  5944. /* 释放 */
  5945. if (functionNameList.length === 0) {
  5946. releaseAll();
  5947. }
  5948. else {
  5949. /* 对单个进行操作 */
  5950. releaseOne();
  5951. }
  5952. }
  5953. else {
  5954. /* 恢复 */
  5955. if (functionNameList.length === 0) {
  5956. recoveryAll();
  5957. }
  5958. else {
  5959. /* 对单个进行操作 */
  5960. recoveryOne();
  5961. }
  5962. }
  5963. }
  5964. parseBase64ToBlob(dataUri) {
  5965. if (typeof dataUri !== "string") {
  5966. throw new Error("Utils.parseBase64ToBlob 参数 dataUri 必须为 string 类型");
  5967. }
  5968. let dataUriSplit = dataUri.split(","), dataUriMime = dataUriSplit[0].match(/:(.*?);/)[1], dataUriBase64Str = atob(dataUriSplit[1]), dataUriLength = dataUriBase64Str.length, u8arr = new Uint8Array(dataUriLength);
  5969. while (dataUriLength--) {
  5970. u8arr[dataUriLength] = dataUriBase64Str.charCodeAt(dataUriLength);
  5971. }
  5972. return new Blob([u8arr], {
  5973. type: dataUriMime,
  5974. });
  5975. }
  5976. parseBase64ToFile(dataUri, fileName = "example") {
  5977. if (typeof dataUri !== "string") {
  5978. throw new Error("Utils.parseBase64ToFile 参数 dataUri 必须为 string 类型");
  5979. }
  5980. if (typeof fileName !== "string") {
  5981. throw new Error("Utils.parseBase64ToFile 参数 fileName 必须为 string 类型");
  5982. }
  5983. let dataUriSplit = dataUri.split(","), dataUriMime = dataUriSplit[0].match(/:(.*?);/)[1], dataUriBase64Str = atob(dataUriSplit[1]), dataUriLength = dataUriBase64Str.length, u8arr = new Uint8Array(dataUriLength);
  5984. while (dataUriLength--) {
  5985. u8arr[dataUriLength] = dataUriBase64Str.charCodeAt(dataUriLength);
  5986. }
  5987. return new File([u8arr], fileName, {
  5988. type: dataUriMime,
  5989. });
  5990. }
  5991. parseInt(matchList = [], defaultValue = 0) {
  5992. if (matchList == null) {
  5993. return parseInt(defaultValue.toString());
  5994. }
  5995. let parseValue = parseInt(matchList[matchList.length - 1]);
  5996. if (isNaN(parseValue)) {
  5997. parseValue = parseInt(defaultValue.toString());
  5998. }
  5999. return parseValue;
  6000. }
  6001. async parseBlobToFile(blobUrl, fileName = "example") {
  6002. return new Promise((resolve, reject) => {
  6003. fetch(blobUrl)
  6004. .then((response) => response.blob())
  6005. .then((blob) => {
  6006. const file = new File([blob], fileName, { type: blob.type });
  6007. resolve(file);
  6008. })
  6009. .catch((error) => {
  6010. console.error("Error:", error);
  6011. reject(error);
  6012. });
  6013. });
  6014. }
  6015. parseCDATA(text = "") {
  6016. let result = "";
  6017. let cdataRegexp = /<\!\[CDATA\[([\s\S]*)\]\]>/;
  6018. let cdataMatch = cdataRegexp.exec(text.trim());
  6019. if (cdataMatch && cdataMatch.length > 1) {
  6020. result = cdataMatch[cdataMatch.length - 1];
  6021. }
  6022. return result;
  6023. }
  6024. async parseFileToBase64(fileObj) {
  6025. let reader = new FileReader();
  6026. reader.readAsDataURL(fileObj);
  6027. return new Promise((resolve) => {
  6028. reader.onload = function (event) {
  6029. resolve(event.target.result);
  6030. };
  6031. });
  6032. }
  6033. parseFromString(text, mimeType = "text/html") {
  6034. let parser = new DOMParser();
  6035. return parser.parseFromString(text, mimeType);
  6036. }
  6037. parseStringToRegExpString(text) {
  6038. if (typeof text !== "string") {
  6039. throw new TypeError("string必须是字符串");
  6040. }
  6041. let regString = text.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
  6042. return regString;
  6043. }
  6044. preventEvent(element, eventNameList = [], capture) {
  6045. function stopEvent(event) {
  6046. /* 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的URL */
  6047. event?.preventDefault();
  6048. /* 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素 */
  6049. event?.stopPropagation();
  6050. /* 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发 */
  6051. event?.stopImmediatePropagation();
  6052. return false;
  6053. }
  6054. if (arguments.length === 1) {
  6055. /* 直接阻止事件 */
  6056. return stopEvent(arguments[0]);
  6057. }
  6058. else {
  6059. /* 添加对应的事件来阻止触发 */
  6060. if (typeof eventNameList === "string") {
  6061. eventNameList = [eventNameList];
  6062. }
  6063. eventNameList.forEach((eventName) => {
  6064. element.addEventListener(eventName, stopEvent, {
  6065. capture: Boolean(capture),
  6066. });
  6067. });
  6068. }
  6069. }
  6070. /**
  6071. * 在canvas元素节点上绘制进度圆圈
  6072. * @example
  6073. let progress = new Utils.Process({canvasNode:document.querySelector("canvas")});
  6074. progress.draw();
  6075. * **/
  6076. Progress = Progress;
  6077. registerTrustClickEvent(isTrustValue = true, filter) {
  6078. function trustEvent(event) {
  6079. return new Proxy(event, {
  6080. get: function (target, property) {
  6081. if (property === "isTrusted") {
  6082. return isTrustValue;
  6083. }
  6084. else {
  6085. return Reflect.get(target, property);
  6086. }
  6087. },
  6088. });
  6089. }
  6090. if (filter == null) {
  6091. filter = function (typeName) {
  6092. return typeName === "click";
  6093. };
  6094. }
  6095. const originalListener = EventTarget.prototype.addEventListener;
  6096. EventTarget.prototype.addEventListener = function (...args) {
  6097. let type = args[0];
  6098. let callback = args[1];
  6099. // @ts-ignore
  6100. args[2];
  6101. if (filter(type)) {
  6102. if (typeof callback === "function") {
  6103. args[1] = function (event) {
  6104. callback.call(this, trustEvent(event));
  6105. };
  6106. }
  6107. else if (typeof callback === "object" &&
  6108. "handleEvent" in callback) {
  6109. let oldHandleEvent = callback["handleEvent"];
  6110. args[1]["handleEvent"] = function (event) {
  6111. if (event == null) {
  6112. return;
  6113. }
  6114. try {
  6115. /* Proxy对象使用instanceof会报错 */
  6116. event instanceof Proxy;
  6117. oldHandleEvent.call(this, trustEvent(event));
  6118. }
  6119. catch (error) {
  6120. // @ts-ignore
  6121. event["isTrusted"] = isTrustValue;
  6122. }
  6123. };
  6124. }
  6125. }
  6126. return originalListener.apply(this, args);
  6127. };
  6128. }
  6129. reverseNumber(num) {
  6130. let reversedNum = 0;
  6131. let isNegative = false;
  6132. if (num < 0) {
  6133. isNegative = true;
  6134. num = Math.abs(num);
  6135. }
  6136. while (num > 0) {
  6137. reversedNum = reversedNum * 10 + (num % 10);
  6138. num = Math.floor(num / 10);
  6139. }
  6140. return isNegative ? -reversedNum : reversedNum;
  6141. }
  6142. selectElementText(element, childTextNode, startIndex, endIndex) {
  6143. let range = this.windowApi.document.createRange();
  6144. range.selectNodeContents(element);
  6145. if (childTextNode) {
  6146. if (childTextNode.nodeType !== Node.TEXT_NODE) {
  6147. throw new TypeError("childTextNode必须是#text元素");
  6148. }
  6149. if (startIndex != null && endIndex != null) {
  6150. range.setStart(childTextNode, startIndex);
  6151. range.setEnd(childTextNode, endIndex);
  6152. }
  6153. }
  6154. let selection = this.windowApi.globalThis.getSelection();
  6155. if (selection) {
  6156. selection.removeAllRanges();
  6157. selection.addRange(range);
  6158. }
  6159. }
  6160. setClip(data, info = {
  6161. type: "text",
  6162. mimetype: "text/plain",
  6163. }) {
  6164. if (typeof data === "object") {
  6165. if (data instanceof Element) {
  6166. data = data.outerHTML;
  6167. }
  6168. else {
  6169. data = JSON.stringify(data);
  6170. }
  6171. }
  6172. else if (typeof data !== "string") {
  6173. data = data.toString();
  6174. }
  6175. let textType = typeof info === "object" ? info.type : info;
  6176. if (textType.includes("html")) {
  6177. textType = "text/html";
  6178. }
  6179. else {
  6180. textType = "text/plain";
  6181. }
  6182. let UtilsContext = this;
  6183. class UtilsClipboard {
  6184. #resolve;
  6185. #copyData;
  6186. #copyDataType;
  6187. constructor(resolve, copyData, copyDataType) {
  6188. this.#resolve = resolve;
  6189. this.#copyData = copyData;
  6190. this.#copyDataType = copyDataType;
  6191. }
  6192. async init() {
  6193. let copyStatus = false;
  6194. // @ts-ignore
  6195. await this.requestClipboardPermission();
  6196. if (this.hasClipboard() &&
  6197. (this.hasClipboardWrite() || this.hasClipboardWriteText())) {
  6198. try {
  6199. copyStatus = await this.copyDataByClipboard();
  6200. }
  6201. catch (error) {
  6202. console.error("复制失败,使用第二种方式,error👉", error);
  6203. copyStatus = this.copyTextByTextArea();
  6204. }
  6205. }
  6206. else {
  6207. copyStatus = this.copyTextByTextArea();
  6208. }
  6209. this.#resolve(copyStatus);
  6210. this.destroy();
  6211. }
  6212. destroy() {
  6213. // @ts-ignore
  6214. this.#resolve = null;
  6215. // @ts-ignore
  6216. this.#copyData = null;
  6217. // @ts-ignore
  6218. this.#copyDataType = null;
  6219. }
  6220. isText() {
  6221. return this.#copyDataType.includes("text");
  6222. }
  6223. hasClipboard() {
  6224. return navigator?.clipboard != null;
  6225. }
  6226. hasClipboardWrite() {
  6227. return navigator?.clipboard?.write != null;
  6228. }
  6229. hasClipboardWriteText() {
  6230. return navigator?.clipboard?.writeText != null;
  6231. }
  6232. /**
  6233. * 使用textarea和document.execCommand("copy")来复制文字
  6234. */
  6235. copyTextByTextArea() {
  6236. try {
  6237. let copyElement = UtilsContext.windowApi.document.createElement("textarea");
  6238. copyElement.value = this.#copyData;
  6239. copyElement.setAttribute("type", "text");
  6240. copyElement.setAttribute("style", "opacity:0;position:absolute;");
  6241. copyElement.setAttribute("readonly", "readonly");
  6242. UtilsContext.windowApi.document.body.appendChild(copyElement);
  6243. copyElement.select();
  6244. UtilsContext.windowApi.document.execCommand("copy");
  6245. UtilsContext.windowApi.document.body.removeChild(copyElement);
  6246. return true;
  6247. }
  6248. catch (error) {
  6249. console.error("复制失败,error👉", error);
  6250. return false;
  6251. }
  6252. }
  6253. /**
  6254. * 申请剪贴板权限
  6255. */
  6256. requestClipboardPermission() {
  6257. return new Promise((resolve, reject) => {
  6258. if (navigator.permissions && navigator.permissions.query) {
  6259. navigator.permissions
  6260. .query({
  6261. // @ts-ignore
  6262. name: "clipboard-write",
  6263. })
  6264. .then((permissionStatus) => {
  6265. resolve(true);
  6266. })
  6267. .catch((error) => {
  6268. console.error([
  6269. "申请剪贴板权限失败,尝试直接写入👉",
  6270. error.message ?? error.name ?? error.stack,
  6271. ]);
  6272. resolve(false);
  6273. });
  6274. }
  6275. else {
  6276. resolve(false);
  6277. }
  6278. });
  6279. }
  6280. /**
  6281. * 使用clipboard直接写入数据到剪贴板
  6282. */
  6283. copyDataByClipboard() {
  6284. return new Promise((resolve, reject) => {
  6285. if (this.isText()) {
  6286. /* 只复制文字 */
  6287. navigator.clipboard
  6288. .writeText(this.#copyData)
  6289. .then(() => {
  6290. resolve(true);
  6291. })
  6292. .catch((error) => {
  6293. reject(error);
  6294. });
  6295. }
  6296. else {
  6297. /* 可复制对象 */
  6298. let textBlob = new Blob([this.#copyData], {
  6299. type: this.#copyDataType,
  6300. });
  6301. navigator.clipboard
  6302. .write([
  6303. new ClipboardItem({
  6304. [this.#copyDataType]: textBlob,
  6305. }),
  6306. ])
  6307. .then(() => {
  6308. resolve(true);
  6309. })
  6310. .catch((error) => {
  6311. reject(error);
  6312. });
  6313. }
  6314. });
  6315. }
  6316. }
  6317. return new Promise((resolve) => {
  6318. const utilsClipboard = new UtilsClipboard(resolve, data, textType);
  6319. if (UtilsContext.windowApi.document.hasFocus()) {
  6320. utilsClipboard.init();
  6321. }
  6322. else {
  6323. UtilsContext.windowApi.window.addEventListener("focus", () => {
  6324. utilsClipboard.init();
  6325. }, { once: true });
  6326. }
  6327. });
  6328. }
  6329. setTimeout(callback, delayTime = 0) {
  6330. let UtilsContext = this;
  6331. if (typeof callback !== "function" && typeof callback !== "string") {
  6332. throw new TypeError("Utils.setTimeout 参数 callback 必须为 function|string 类型");
  6333. }
  6334. if (typeof delayTime !== "number") {
  6335. throw new TypeError("Utils.setTimeout 参数 delayTime 必须为 number 类型");
  6336. }
  6337. return new Promise((resolve) => {
  6338. setTimeout(() => {
  6339. resolve(UtilsContext.tryCatch().run(callback));
  6340. }, delayTime);
  6341. });
  6342. }
  6343. sleep(delayTime = 0) {
  6344. if (typeof delayTime !== "number") {
  6345. throw new Error("Utils.sleep 参数 delayTime 必须为 number 类型");
  6346. }
  6347. return new Promise((resolve) => {
  6348. setTimeout(() => {
  6349. resolve(void 0);
  6350. }, delayTime);
  6351. });
  6352. }
  6353. dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
  6354. let UtilsContext = this;
  6355. function initMouseEvent(eventName, offSetX, offSetY) {
  6356. // @ts-ignore
  6357. let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
  6358. let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
  6359. mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
  6360. return mouseEvent;
  6361. }
  6362. let sliderElement = typeof selector === "string"
  6363. ? this.windowApi.document.querySelector(selector)
  6364. : selector;
  6365. if (!(sliderElement instanceof Node) ||
  6366. !(sliderElement instanceof Element)) {
  6367. throw new Error("Utils.dragSlider 参数selector 必须为Node/Element类型");
  6368. }
  6369. let rect = sliderElement.getBoundingClientRect(), x0 = rect.x || rect.left, y0 = rect.y || rect.top, x1 = x0 + offsetX, y1 = y0;
  6370. sliderElement.dispatchEvent(initMouseEvent("mousedown", x0, y0));
  6371. sliderElement.dispatchEvent(initMouseEvent("mousemove", x1, y1));
  6372. sliderElement.dispatchEvent(initMouseEvent("mouseleave", x1, y1));
  6373. sliderElement.dispatchEvent(initMouseEvent("mouseout", x1, y1));
  6374. }
  6375. enterFullScreen(element = this.windowApi.document.documentElement, options) {
  6376. try {
  6377. if (element.requestFullscreen) {
  6378. element.requestFullscreen(options);
  6379. }
  6380. else if (element.webkitRequestFullScreen) {
  6381. element.webkitRequestFullScreen();
  6382. }
  6383. else if (element.mozRequestFullScreen) {
  6384. element.mozRequestFullScreen();
  6385. }
  6386. else if (element.msRequestFullscreen) {
  6387. element.msRequestFullscreen();
  6388. }
  6389. else {
  6390. throw new TypeError("该浏览器不支持全屏API");
  6391. }
  6392. }
  6393. catch (err) {
  6394. console.error(err);
  6395. }
  6396. }
  6397. exitFullScreen(element = this.windowApi.document.documentElement) {
  6398. if (this.windowApi.document.exitFullscreen) {
  6399. return this.windowApi.document.exitFullscreen();
  6400. }
  6401. else if (this.windowApi.document.msExitFullscreen) {
  6402. return this.windowApi.document.msExitFullscreen();
  6403. }
  6404. else if (this.windowApi.document.mozCancelFullScreen) {
  6405. return this.windowApi.document.mozCancelFullScreen();
  6406. }
  6407. else if (this.windowApi.document.webkitCancelFullScreen) {
  6408. return this.windowApi.document.webkitCancelFullScreen();
  6409. }
  6410. else {
  6411. return new Promise((resolve, reject) => {
  6412. reject(new TypeError("该浏览器不支持全屏API"));
  6413. });
  6414. }
  6415. }
  6416. sortListByProperty(data, getPropertyValueFunc, sortByDesc = true) {
  6417. let UtilsContext = this;
  6418. if (typeof getPropertyValueFunc !== "function" &&
  6419. typeof getPropertyValueFunc !== "string") {
  6420. throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
  6421. }
  6422. if (typeof sortByDesc !== "boolean") {
  6423. throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
  6424. }
  6425. let getObjValue = function (obj) {
  6426. return typeof getPropertyValueFunc === "string"
  6427. ? obj[getPropertyValueFunc]
  6428. : getPropertyValueFunc(obj);
  6429. };
  6430. /**
  6431. * 排序方法
  6432. * @param {any} after_obj
  6433. * @param {any} before_obj
  6434. * @returns
  6435. */
  6436. let sortFunc = function (after_obj, before_obj) {
  6437. let beforeValue = getObjValue(before_obj); /* 前 */
  6438. let afterValue = getObjValue(after_obj); /* 后 */
  6439. if (sortByDesc) {
  6440. if (afterValue > beforeValue) {
  6441. return -1;
  6442. }
  6443. else if (afterValue < beforeValue) {
  6444. return 1;
  6445. }
  6446. else {
  6447. return 0;
  6448. }
  6449. }
  6450. else {
  6451. if (afterValue < beforeValue) {
  6452. return -1;
  6453. }
  6454. else if (afterValue > beforeValue) {
  6455. return 1;
  6456. }
  6457. else {
  6458. return 0;
  6459. }
  6460. }
  6461. };
  6462. /**
  6463. * 排序元素方法
  6464. * @param nodeList 元素列表
  6465. * @param getNodeListFunc 获取元素列表的函数
  6466. */
  6467. let sortNodeFunc = function (nodeList, getNodeListFunc) {
  6468. let nodeListLength = nodeList.length;
  6469. for (let i = 0; i < nodeListLength - 1; i++) {
  6470. for (let j = 0; j < nodeListLength - 1 - i; j++) {
  6471. let beforeNode = nodeList[j];
  6472. let afterNode = nodeList[j + 1];
  6473. let beforeValue = getObjValue(beforeNode); /* 前 */
  6474. let afterValue = getObjValue(afterNode); /* 后 */
  6475. if ((sortByDesc == true && beforeValue < afterValue) ||
  6476. (sortByDesc == false && beforeValue > afterValue)) {
  6477. /* 升序/降序 */
  6478. /* 相邻元素两两对比 */
  6479. let temp = beforeNode.nextElementSibling;
  6480. afterNode.after(beforeNode);
  6481. if (temp == null) {
  6482. /* 如果为空,那么是最后一个元素,使用append */
  6483. temp.parentNode.appendChild(afterNode);
  6484. }
  6485. else {
  6486. /* 不为空,使用before */
  6487. temp.before(afterNode);
  6488. }
  6489. nodeList = getNodeListFunc();
  6490. }
  6491. }
  6492. }
  6493. };
  6494. let result = data;
  6495. let getDataFunc = null;
  6496. if (data instanceof Function) {
  6497. getDataFunc = data;
  6498. data = data();
  6499. }
  6500. if (Array.isArray(data)) {
  6501. data.sort(sortFunc);
  6502. }
  6503. else if (data instanceof NodeList ||
  6504. UtilsContext.isJQuery(data)) {
  6505. sortNodeFunc(data, getDataFunc);
  6506. result = getDataFunc();
  6507. }
  6508. else {
  6509. throw new Error("Utils.sortListByProperty 参数 data 必须为 Array|NodeList|jQuery 类型");
  6510. }
  6511. return result;
  6512. }
  6513. stringToRegular(targetString, flags = "ig") {
  6514. let reg;
  6515. // @ts-ignore
  6516. flags = flags.toLowerCase();
  6517. if (typeof targetString === "string") {
  6518. reg = new RegExp(targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"), flags);
  6519. }
  6520. else if (targetString instanceof RegExp) {
  6521. reg = targetString;
  6522. }
  6523. else {
  6524. throw new Error("Utils.stringToRegular 参数targetString必须是string|Regexp类型");
  6525. }
  6526. return reg;
  6527. }
  6528. stringTitleToUpperCase(targetString, otherStrToLowerCase = false) {
  6529. let newTargetString = targetString.slice(0, 1).toUpperCase();
  6530. if (otherStrToLowerCase) {
  6531. newTargetString = newTargetString + targetString.slice(1).toLowerCase();
  6532. }
  6533. else {
  6534. newTargetString = newTargetString + targetString.slice(1);
  6535. }
  6536. return newTargetString;
  6537. }
  6538. startsWith(target, searchString, position = 0) {
  6539. let UtilsContext = this;
  6540. if (position > target.length) {
  6541. /* 超出目标字符串的长度 */
  6542. return false;
  6543. }
  6544. if (position !== 0) {
  6545. target = target.slice(position, target.length);
  6546. }
  6547. let searchStringRegexp = searchString;
  6548. if (typeof searchString === "string") {
  6549. searchStringRegexp = new RegExp(`^${searchString}`);
  6550. }
  6551. else if (Array.isArray(searchString)) {
  6552. let flag = false;
  6553. for (const searcStr of searchString) {
  6554. if (!UtilsContext.startsWith(target, searcStr, position)) {
  6555. flag = true;
  6556. break;
  6557. }
  6558. }
  6559. return flag;
  6560. }
  6561. return Boolean(target.match(searchStringRegexp));
  6562. }
  6563. stringTitleToLowerCase(targetString, otherStrToUpperCase = false) {
  6564. let newTargetString = targetString.slice(0, 1).toLowerCase();
  6565. if (otherStrToUpperCase) {
  6566. newTargetString = newTargetString + targetString.slice(1).toUpperCase();
  6567. }
  6568. else {
  6569. newTargetString = newTargetString + targetString.slice(1);
  6570. }
  6571. return newTargetString;
  6572. }
  6573. toJSON(data, errorCallBack) {
  6574. let UtilsContext = this;
  6575. let result = {};
  6576. if (typeof data === "object") {
  6577. return data;
  6578. }
  6579. UtilsContext.tryCatch()
  6580. .config({ log: false })
  6581. .error((error) => {
  6582. UtilsContext.tryCatch()
  6583. .error(() => {
  6584. try {
  6585. result = UtilsContext.windowApi.window.eval("(" + data + ")");
  6586. }
  6587. catch (error2) {
  6588. if (typeof errorCallBack === "function") {
  6589. errorCallBack(error2);
  6590. }
  6591. }
  6592. })
  6593. .run(() => {
  6594. if (data &&
  6595. /^[\],:{}\s]*$/.test(data
  6596. .replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
  6597. .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
  6598. .replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
  6599. result = new Function("return " + data)();
  6600. }
  6601. else {
  6602. if (typeof errorCallBack === "function") {
  6603. errorCallBack(new Error("target is not a JSON"));
  6604. }
  6605. }
  6606. });
  6607. })
  6608. .run(() => {
  6609. data = data.trim();
  6610. result = JSON.parse(data);
  6611. });
  6612. return result;
  6613. }
  6614. toSearchParamsStr(obj, addPrefix) {
  6615. let UtilsContext = this;
  6616. let searhParamsStr = "";
  6617. if (Array.isArray(obj)) {
  6618. obj.forEach((item) => {
  6619. if (searhParamsStr === "") {
  6620. searhParamsStr += UtilsContext.toSearchParamsStr(item);
  6621. }
  6622. else {
  6623. searhParamsStr += "&" + UtilsContext.toSearchParamsStr(item);
  6624. }
  6625. });
  6626. }
  6627. else {
  6628. searhParamsStr = new URLSearchParams(Object.entries(obj)).toString();
  6629. }
  6630. if (addPrefix && !searhParamsStr.startsWith("?")) {
  6631. searhParamsStr = "?" + searhParamsStr;
  6632. }
  6633. return searhParamsStr;
  6634. }
  6635. /**
  6636. * 将UrlSearchParams格式的字符串转为对象
  6637. */
  6638. searchParamStrToObj(searhParamsStr) {
  6639. if (typeof searhParamsStr !== "string") {
  6640. // @ts-ignore
  6641. return {};
  6642. }
  6643. // @ts-ignore
  6644. return Object.fromEntries(new URLSearchParams(searhParamsStr));
  6645. }
  6646. /**
  6647. * 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
  6648. * @example
  6649. * Utils.tryCatch().error().run(()=>{console.log(1)});
  6650. * > 1
  6651. * @example
  6652. * Utils.tryCatch().config({log:true}).error((error)=>{console.log(error)}).run(()=>{throw new Error('测试错误')});
  6653. * > ()=>{throw new Error('测试错误')}出现错误
  6654. */
  6655. tryCatch = TryCatch;
  6656. uniqueArray(uniqueArrayData = [], compareArrayData, compareFun = (item, item2) => {
  6657. return item === item2;
  6658. }) {
  6659. if (typeof compareArrayData === "function") {
  6660. const compareFn = compareArrayData;
  6661. const seen = new Set();
  6662. const result = [];
  6663. for (const item of uniqueArrayData) {
  6664. // 使用compareFn函数来获取当前对象的唯一标识
  6665. const identfier = compareFn(item);
  6666. // 如果Set中还没有这个标识,则添加到结果数组中,并将其标识存入Set
  6667. if (!seen.has(identfier)) {
  6668. seen.add(identfier);
  6669. result.push(item);
  6670. }
  6671. }
  6672. return result;
  6673. }
  6674. else {
  6675. return Array.from(uniqueArrayData).filter((item) => !Array.from(compareArrayData).some(function (item2) {
  6676. return compareFun(item, item2);
  6677. }));
  6678. }
  6679. }
  6680. waitArrayLoopToEnd(data, handleFunc) {
  6681. let UtilsContext = this;
  6682. if (typeof handleFunc !== "function" && typeof handleFunc !== "string") {
  6683. throw new Error("Utils.waitArrayLoopToEnd 参数 handleDataFunction 必须为 function|string 类型");
  6684. }
  6685. return Promise.all(Array.from(data).map(async (item, index) => {
  6686. await UtilsContext.tryCatch(index, item).run(handleFunc);
  6687. }));
  6688. }
  6689. waitNode(...args) {
  6690. // 过滤掉undefined
  6691. args = args.filter((arg) => arg !== void 0);
  6692. let UtilsContext = this;
  6693. // 选择器
  6694. let selector = args[0];
  6695. // 父元素(监听的元素)
  6696. let parent = UtilsContext.windowApi.document;
  6697. // 超时时间
  6698. let timeout = 0;
  6699. if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
  6700. throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]");
  6701. }
  6702. if (args.length === 1) ;
  6703. else if (args.length === 2) {
  6704. let secondParam = args[1];
  6705. if (typeof secondParam === "number") {
  6706. // "div",10000
  6707. timeout = secondParam;
  6708. }
  6709. else if (typeof secondParam === "object" &&
  6710. secondParam instanceof Node) {
  6711. // "div",document
  6712. parent = secondParam;
  6713. }
  6714. else {
  6715. throw new TypeError("Utils.waitNode 第二个参数必须是number|Node");
  6716. }
  6717. }
  6718. else if (args.length === 3) {
  6719. // "div",document,10000
  6720. // 第二个参数,parent
  6721. let secondParam = args[1];
  6722. // 第三个参数,timeout
  6723. let thirdParam = args[2];
  6724. if (typeof secondParam === "object" && secondParam instanceof Node) {
  6725. parent = secondParam;
  6726. if (typeof thirdParam === "number") {
  6727. timeout = thirdParam;
  6728. }
  6729. else {
  6730. throw new TypeError("Utils.waitNode 第三个参数必须是number");
  6731. }
  6732. }
  6733. else {
  6734. throw new TypeError("Utils.waitNode 第二个参数必须是Node");
  6735. }
  6736. }
  6737. else {
  6738. throw new TypeError("Utils.waitNode 参数个数错误");
  6739. }
  6740. return new Promise((resolve) => {
  6741. function getNode() {
  6742. if (Array.isArray(selector)) {
  6743. let result = [];
  6744. for (let index = 0; index < selector.length; index++) {
  6745. let node = parent.querySelector(selector[index]);
  6746. if (node) {
  6747. result.push(node);
  6748. }
  6749. }
  6750. if (result.length === selector.length) {
  6751. return result;
  6752. }
  6753. }
  6754. else {
  6755. return parent.querySelector(selector);
  6756. }
  6757. }
  6758. var observer = UtilsContext.mutationObserver(parent, {
  6759. config: {
  6760. subtree: true,
  6761. childList: true,
  6762. attributes: true,
  6763. },
  6764. callback() {
  6765. let node = getNode();
  6766. if (node) {
  6767. // 取消观察器
  6768. if (typeof observer?.disconnect === "function") {
  6769. observer.disconnect();
  6770. }
  6771. resolve(node);
  6772. return;
  6773. }
  6774. },
  6775. immediate: true,
  6776. });
  6777. if (timeout > 0) {
  6778. setTimeout(() => {
  6779. // 取消观察器
  6780. if (typeof observer?.disconnect === "function") {
  6781. observer.disconnect();
  6782. }
  6783. resolve(null);
  6784. }, timeout);
  6785. }
  6786. });
  6787. }
  6788. waitAnyNode(...args) {
  6789. // 过滤掉undefined
  6790. args = args.filter((arg) => arg !== void 0);
  6791. let UtilsContext = this;
  6792. // 选择器
  6793. let selectorList = args[0];
  6794. // 父元素(监听的元素)
  6795. let parent = UtilsContext.windowApi.document;
  6796. // 超时时间
  6797. let timeout = 0;
  6798. if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
  6799. throw new TypeError("Utils.waitAnyNode 第一个参数必须是string[]");
  6800. }
  6801. if (args.length === 1) ;
  6802. else if (args.length === 2) {
  6803. let secondParam = args[1];
  6804. if (typeof secondParam === "number") {
  6805. // "div",10000
  6806. timeout = secondParam;
  6807. }
  6808. else if (typeof secondParam === "object" &&
  6809. secondParam instanceof Node) {
  6810. // "div",document
  6811. parent = secondParam;
  6812. }
  6813. else {
  6814. throw new TypeError("Utils.waitAnyNode 第二个参数必须是number|Node");
  6815. }
  6816. }
  6817. else if (args.length === 3) {
  6818. // "div",document,10000
  6819. // 第二个参数,parent
  6820. let secondParam = args[1];
  6821. // 第三个参数,timeout
  6822. let thirdParam = args[2];
  6823. if (typeof secondParam === "object" && secondParam instanceof Node) {
  6824. parent = secondParam;
  6825. if (typeof thirdParam === "number") {
  6826. timeout = thirdParam;
  6827. }
  6828. else {
  6829. throw new TypeError("Utils.waitAnyNode 第三个参数必须是number");
  6830. }
  6831. }
  6832. else {
  6833. throw new TypeError("Utils.waitAnyNode 第二个参数必须是Node");
  6834. }
  6835. }
  6836. else {
  6837. throw new TypeError("Utils.waitAnyNode 参数个数错误");
  6838. }
  6839. let promiseList = selectorList.map((selector) => {
  6840. return UtilsContext.waitNode(selector, parent, timeout);
  6841. });
  6842. return Promise.any(promiseList);
  6843. }
  6844. waitNodeList(...args) {
  6845. // 过滤掉undefined
  6846. args = args.filter((arg) => arg !== void 0);
  6847. let UtilsContext = this;
  6848. // 选择器数组
  6849. let selector = args[0];
  6850. // 父元素(监听的元素)
  6851. let parent = UtilsContext.windowApi.document;
  6852. // 超时时间
  6853. let timeout = 0;
  6854. if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
  6855. throw new TypeError("Utils.waitNodeList 第一个参数必须是string|string[]");
  6856. }
  6857. if (args.length === 1) ;
  6858. else if (args.length === 2) {
  6859. let secondParam = args[1];
  6860. if (typeof secondParam === "number") {
  6861. // "div",10000
  6862. timeout = secondParam;
  6863. }
  6864. else if (typeof secondParam === "object" &&
  6865. secondParam instanceof Node) {
  6866. // "div",document
  6867. parent = secondParam;
  6868. }
  6869. else {
  6870. throw new TypeError("Utils.waitNodeList 第二个参数必须是number|Node");
  6871. }
  6872. }
  6873. else if (args.length === 3) {
  6874. // "div",document,10000
  6875. // 第二个参数,parent
  6876. let secondParam = args[1];
  6877. // 第三个参数,timeout
  6878. let thirdParam = args[2];
  6879. if (typeof secondParam === "object" && secondParam instanceof Node) {
  6880. parent = secondParam;
  6881. if (typeof thirdParam === "number") {
  6882. timeout = thirdParam;
  6883. }
  6884. else {
  6885. throw new TypeError("Utils.waitNodeList 第三个参数必须是number");
  6886. }
  6887. }
  6888. else {
  6889. throw new TypeError("Utils.waitNodeList 第二个参数必须是Node");
  6890. }
  6891. }
  6892. else {
  6893. throw new TypeError("Utils.waitNodeList 参数个数错误");
  6894. }
  6895. return new Promise((resolve) => {
  6896. function getNodeList() {
  6897. if (Array.isArray(selector)) {
  6898. let result = [];
  6899. for (let index = 0; index < selector.length; index++) {
  6900. let nodeList = parent.querySelectorAll(selector[index]);
  6901. if (nodeList.length) {
  6902. result.push(nodeList);
  6903. }
  6904. }
  6905. if (result.length === selector.length) {
  6906. return result;
  6907. }
  6908. }
  6909. else {
  6910. let nodeList = parent.querySelectorAll(selector);
  6911. if (nodeList.length) {
  6912. return nodeList;
  6913. }
  6914. }
  6915. }
  6916. var observer = UtilsContext.mutationObserver(parent, {
  6917. config: {
  6918. subtree: true,
  6919. childList: true,
  6920. attributes: true,
  6921. },
  6922. callback() {
  6923. let node = getNodeList();
  6924. if (node) {
  6925. // 取消观察器
  6926. try {
  6927. observer.disconnect();
  6928. }
  6929. catch (error) { }
  6930. resolve(node);
  6931. return;
  6932. }
  6933. },
  6934. immediate: true,
  6935. });
  6936. if (timeout > 0) {
  6937. setTimeout(() => {
  6938. // 取消观察器
  6939. if (typeof observer?.disconnect === "function") {
  6940. observer.disconnect();
  6941. }
  6942. resolve(null);
  6943. }, timeout);
  6944. }
  6945. });
  6946. }
  6947. waitAnyNodeList(...args) {
  6948. // 过滤掉undefined
  6949. args = args.filter((arg) => arg !== void 0);
  6950. let UtilsContext = this;
  6951. // 选择器数组
  6952. let selectorList = args[0];
  6953. // 父元素(监听的元素)
  6954. let parent = UtilsContext.windowApi.document;
  6955. // 超时时间
  6956. let timeout = 0;
  6957. if (!Array.isArray(args[0])) {
  6958. throw new TypeError("Utils.waitAnyNodeList 第一个参数必须是string[]");
  6959. }
  6960. if (args.length === 1) ;
  6961. else if (args.length === 2) {
  6962. let secondParam = args[1];
  6963. if (typeof secondParam === "number") {
  6964. // "div",10000
  6965. timeout = secondParam;
  6966. }
  6967. else if (typeof secondParam === "object" &&
  6968. secondParam instanceof Node) {
  6969. // "div",document
  6970. parent = secondParam;
  6971. }
  6972. else {
  6973. throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是number|Node");
  6974. }
  6975. }
  6976. else if (args.length === 3) {
  6977. // "div",document,10000
  6978. // 第二个参数,parent
  6979. let secondParam = args[1];
  6980. // 第三个参数,timeout
  6981. let thirdParam = args[2];
  6982. if (typeof secondParam === "object" && secondParam instanceof Node) {
  6983. parent = secondParam;
  6984. if (typeof thirdParam === "number") {
  6985. timeout = thirdParam;
  6986. }
  6987. else {
  6988. throw new TypeError("Utils.waitAnyNodeList 第三个参数必须是number");
  6989. }
  6990. }
  6991. else {
  6992. throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是Node");
  6993. }
  6994. }
  6995. else {
  6996. throw new TypeError("Utils.waitAnyNodeList 参数个数错误");
  6997. }
  6998. let promiseList = selectorList.map((selector) => {
  6999. return UtilsContext.waitNodeList(selector, parent, timeout);
  7000. });
  7001. return Promise.any(promiseList);
  7002. }
  7003. waitProperty(checkObj, checkPropertyName) {
  7004. return new Promise((resolve) => {
  7005. let obj = checkObj;
  7006. if (typeof checkObj === "function") {
  7007. obj = checkObj();
  7008. }
  7009. if (Reflect.has(obj, checkPropertyName)) {
  7010. resolve(obj[checkPropertyName]);
  7011. }
  7012. else {
  7013. Object.defineProperty(obj, checkPropertyName, {
  7014. set: function (value) {
  7015. try {
  7016. resolve(value);
  7017. }
  7018. catch (error) {
  7019. console.error("Error setting property:", error);
  7020. }
  7021. },
  7022. });
  7023. }
  7024. });
  7025. }
  7026. waitPropertyByInterval(checkObj, checkPropertyName, intervalTimer = 250, maxTime = -1) {
  7027. if (checkObj == null) {
  7028. throw new TypeError("checkObj 不能为空对象 ");
  7029. }
  7030. let isResolve = false;
  7031. return new Promise((resolve, reject) => {
  7032. let interval = setInterval(() => {
  7033. let obj = checkObj;
  7034. if (typeof checkObj === "function") {
  7035. obj = checkObj();
  7036. }
  7037. if (typeof obj !== "object") {
  7038. return;
  7039. }
  7040. if (obj == null) {
  7041. return;
  7042. }
  7043. if ((typeof checkPropertyName === "function" && checkPropertyName(obj)) ||
  7044. Reflect.has(obj, checkPropertyName)) {
  7045. isResolve = true;
  7046. clearInterval(interval);
  7047. resolve(obj[checkPropertyName]);
  7048. }
  7049. }, intervalTimer);
  7050. if (maxTime !== -1) {
  7051. setTimeout(() => {
  7052. if (!isResolve) {
  7053. clearInterval(interval);
  7054. reject();
  7055. }
  7056. }, maxTime);
  7057. }
  7058. });
  7059. }
  7060. async waitVueByInterval(element, propertyName, timer = 250, maxTime = -1, vueName = "__vue__") {
  7061. if (element == null) {
  7062. throw new Error("Utils.waitVueByInterval 参数element 不能为空");
  7063. }
  7064. let flag = false;
  7065. let UtilsContext = this;
  7066. try {
  7067. await UtilsContext.waitPropertyByInterval(element, function (targetElement) {
  7068. if (targetElement == null) {
  7069. return false;
  7070. }
  7071. if (!(vueName in targetElement)) {
  7072. return false;
  7073. }
  7074. if (propertyName == null) {
  7075. return true;
  7076. }
  7077. let vueObject = targetElement[vueName];
  7078. if (typeof propertyName === "string") {
  7079. if (propertyName in vueObject) {
  7080. flag = true;
  7081. return true;
  7082. }
  7083. }
  7084. else {
  7085. /* Function */
  7086. if (propertyName(vueObject)) {
  7087. flag = true;
  7088. return true;
  7089. }
  7090. }
  7091. return false;
  7092. }, timer, maxTime);
  7093. }
  7094. catch (error) {
  7095. return flag;
  7096. }
  7097. return flag;
  7098. }
  7099. watchObject(target, propertyName, getCallBack, setCallBack) {
  7100. if (typeof getCallBack !== "function" &&
  7101. typeof setCallBack !== "function") {
  7102. return;
  7103. }
  7104. if (typeof getCallBack === "function") {
  7105. Object.defineProperty(target, propertyName, {
  7106. get() {
  7107. if (typeof getCallBack === "function") {
  7108. return getCallBack(target[propertyName]);
  7109. }
  7110. else {
  7111. return target[propertyName];
  7112. }
  7113. },
  7114. });
  7115. }
  7116. else if (typeof setCallBack === "function") {
  7117. Object.defineProperty(target, propertyName, {
  7118. set(value) {
  7119. if (typeof setCallBack === "function") {
  7120. setCallBack(value);
  7121. }
  7122. },
  7123. });
  7124. }
  7125. else {
  7126. Object.defineProperty(target, propertyName, {
  7127. get() {
  7128. if (typeof getCallBack === "function") {
  7129. return getCallBack(target[propertyName]);
  7130. }
  7131. else {
  7132. return target[propertyName];
  7133. }
  7134. },
  7135. set(value) {
  7136. if (typeof setCallBack === "function") {
  7137. setCallBack(value);
  7138. }
  7139. },
  7140. });
  7141. }
  7142. }
  7143. /**
  7144. * 深度获取对象属性
  7145. * @param target 待获取的对象
  7146. * @param handler 获取属性的回调
  7147. */
  7148. queryProperty(target, handler) {
  7149. if (target == null) {
  7150. return;
  7151. }
  7152. let handleResult = handler(target);
  7153. if (handleResult &&
  7154. typeof handleResult.isFind === "boolean" &&
  7155. handleResult.isFind) {
  7156. return handleResult.data;
  7157. }
  7158. return this.queryProperty(handleResult.data, handler);
  7159. }
  7160. /**
  7161. * 创建一个新的Utils实例
  7162. * @param option
  7163. * @returns
  7164. */
  7165. createUtils(option) {
  7166. return new Utils(option);
  7167. }
  7168. /**
  7169. * 将对象转换为FormData
  7170. * @param data 待转换的对象
  7171. * @param isEncode 是否对值为string进行编码转换(encodeURIComponent),默认false
  7172. * @param valueAutoParseToStr 是否对值强制使用JSON.stringify()转换,默认false
  7173. * @example
  7174. * Utils.toFormData({
  7175. * test: "1",
  7176. * 666: 666,
  7177. * })
  7178. */
  7179. toFormData(data, isEncode = false, valueAutoParseToStr = false) {
  7180. const formData = new FormData();
  7181. Object.keys(data).forEach((key) => {
  7182. let value = data[key];
  7183. if (valueAutoParseToStr) {
  7184. value = JSON.stringify(value);
  7185. }
  7186. if (typeof value === "number") {
  7187. value = value.toString();
  7188. }
  7189. if (isEncode && typeof value === "string") {
  7190. value = encodeURIComponent(value);
  7191. }
  7192. if (value instanceof File) {
  7193. formData.append(key, value, value.name);
  7194. }
  7195. else {
  7196. formData.append(key, value);
  7197. }
  7198. });
  7199. return formData;
  7200. }
  7201. /**
  7202. * 将链接转为URL对象,自动补充URL的protocol或者origin
  7203. * @param text 需要转换的链接字符串
  7204. * @example
  7205. * Utils.toUrl("//www.baidu.com/s?word=666");
  7206. * Utils.toUrl("/s?word=666");
  7207. */
  7208. toUrl(text) {
  7209. if (typeof text !== "string") {
  7210. throw new TypeError("toUrl: text must be string");
  7211. }
  7212. text = text.trim();
  7213. if (text === "") {
  7214. throw new TypeError("toUrl: text must not be empty");
  7215. }
  7216. if (text.startsWith("//")) {
  7217. /* //www.baidu.com/xxxxxxx */
  7218. /* 没有protocol,加上 */
  7219. text = this.windowApi.globalThis.location.protocol + text;
  7220. }
  7221. else if (text.startsWith("/")) {
  7222. /* /xxx/info?xxx=xxx */
  7223. /* 没有Origin,加上 */
  7224. text = this.windowApi.globalThis.location.origin + text;
  7225. }
  7226. return new URL(text);
  7227. }
  7228. /**
  7229. * 生成uuid
  7230. * @example
  7231. * Utils.generateUUID()
  7232. */
  7233. generateUUID = GenerateUUID;
  7234. /**
  7235. * 自定义的动态响应对象
  7236. * @example
  7237. * let vue = new Utils.Vue();
  7238. * let reactive = new vue.reactive({});
  7239. * vue.watch(()=>reactive["name"], (newValue, oldValue)=>{
  7240. * console.log("newValue ==> " + newValue);
  7241. * console.log("oldValue ==> " + oldValue);
  7242. * })
  7243. * vue["name"] = "测试";
  7244. * > "测试"
  7245. */
  7246. Vue = Vue;
  7247. }
  7248. let utils = new Utils();
  7249.  
  7250. return utils;
  7251.  
  7252. }));
  7253. //# sourceMappingURL=index.umd.js.map

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址