to_nas.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>自动跳转</title>
  7. </head>
  8. <body>
  9. 跳转中......
  10. <!-- 列表,不同的type对应不同的url -->
  11. <li><a href="?type=tri">tri 笔记</a></li>
  12. <li><a href="?type=photo">photo 照片</a></li>
  13. <li><a href="?type=photo_family">photo_family 分享</a></li>
  14. <li><a href="?type=kedao">nkedaoyun</a></li>
  15. </body>
  16. <script>
  17. (function () {
  18. let urlMap = {
  19. tri: ["http://192.168.3.36:9002/", "https://tri.tianyunperfect.cn/"],
  20. photo_family: [
  21. "http://192.168.3.36:8063/share?key=LSMTb36t",
  22. "https://photo.n.tianyunperfect.cn/share?key=LSMTb36t",
  23. "https://photo.tianyunperfect.cn/share?key=LSMTb36t",
  24. ],
  25. photo: [
  26. "http://192.168.3.36:8063/",
  27. "https://photo.n.tianyunperfect.cn/",
  28. "https://photo.tianyunperfect.cn/photos",
  29. ],
  30. kedao: [
  31. "http://192.168.3.36:8081/",
  32. "https://nkedaoyun.tianyunperfect.cn/#explorer",
  33. "https://kedao.n.tianyunperfect.cn/",
  34. ],
  35. };
  36. // 从url里面读取参数 type
  37. const urlParams = new URLSearchParams(window.location.search);
  38. const type = urlParams.get("type");
  39. // 如果type为空,则警告lert("请输入type参数")
  40. if (!type) {
  41. showStatus("请输入type参数");
  42. return;
  43. }
  44. const urls = urlMap[type];
  45. function checkUrl(url) {
  46. return new Promise((resolve) => {
  47. const startTime = performance.now();
  48. const img = new Image();
  49. let isResolved = false;
  50. img.onload = function () {
  51. if (!isResolved) {
  52. isResolved = true;
  53. resolve({
  54. url: url,
  55. accessible: true,
  56. responseTime: performance.now() - startTime,
  57. });
  58. }
  59. };
  60. img.onerror = function () {
  61. if (!isResolved) {
  62. isResolved = true;
  63. resolve({
  64. url: url,
  65. accessible: true,
  66. responseTime: performance.now() - startTime,
  67. });
  68. }
  69. };
  70. setTimeout(() => {
  71. if (!isResolved) {
  72. isResolved = true;
  73. resolve({
  74. url: url,
  75. accessible: false,
  76. responseTime: 99999,
  77. });
  78. }
  79. }, 5000);
  80. const timestamp = new Date().getTime();
  81. img.src = url + `favicon.ico?t=${timestamp}`;
  82. });
  83. }
  84. function showStatus(message, isError = false) {
  85. let statusDiv = document.getElementById("url-checker-status");
  86. if (!statusDiv) {
  87. statusDiv = document.createElement("div");
  88. statusDiv.id = "url-checker-status";
  89. statusDiv.style.cssText = `
  90. position: fixed;
  91. top: 10px;
  92. right: 10px;
  93. padding: 10px;
  94. background: ${
  95. isError ? "rgba(255, 0, 0, 0.8)" : "rgba(0, 0, 0, 0.8)"
  96. };
  97. color: white;
  98. border-radius: 5px;
  99. z-index: 999999;
  100. font-family: Arial, sans-serif;
  101. font-size: 14px;
  102. max-width: 300px;
  103. word-break: break-word;
  104. `;
  105. document.body.appendChild(statusDiv);
  106. }
  107. statusDiv.textContent = message;
  108. return statusDiv;
  109. }
  110. async function checkAllUrls() {
  111. const statusDiv = showStatus("正在检测网络连接...");
  112. try {
  113. const results = await Promise.all(urls.map((url) => checkUrl(url)));
  114. const accessibleUrls = results.filter((result) => result.accessible);
  115. console.log("检测结果:", results);
  116. if (accessibleUrls.length === 0) {
  117. showStatus("所有地址均无法访问!", true);
  118. setTimeout(() => statusDiv.remove(), 3000);
  119. return;
  120. }
  121. const fastestUrl = accessibleUrls.reduce((prev, current) =>
  122. prev.responseTime < current.responseTime ? prev : current
  123. );
  124. showStatus(
  125. `正在跳转到最快地址: ${fastestUrl.url}\n响应时间: ${Math.round(
  126. fastestUrl.responseTime
  127. )}ms`
  128. );
  129. setTimeout(() => {
  130. window.location.href = fastestUrl.url;
  131. statusDiv.remove();
  132. }, 1500);
  133. } catch (error) {
  134. console.error("检测过程出错:", error);
  135. showStatus("检测过程出错,请稍后重试", true);
  136. setTimeout(() => statusDiv.remove(), 3000);
  137. }
  138. }
  139. checkAllUrls();
  140. })();
  141. </script>
  142. </html>