|
@@ -1,87 +1,101 @@
|
|
<!DOCTYPE html>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<html lang="en">
|
|
-<head>
|
|
|
|
- <meta charset="UTF-8">
|
|
|
|
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
|
+ <head>
|
|
|
|
+ <meta charset="UTF-8" />
|
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>自动跳转</title>
|
|
<title>自动跳转</title>
|
|
-</head>
|
|
|
|
-<body>
|
|
|
|
|
|
+ </head>
|
|
|
|
+ <body>
|
|
跳转中......
|
|
跳转中......
|
|
-</body>
|
|
|
|
-<script>
|
|
|
|
|
|
+ <!-- 列表,不同的type对应不同的url -->
|
|
|
|
+ <li><a href="?type=tri">tri 笔记</a></li>
|
|
|
|
+ <li><a href="?type=photo">photo 照片</a></li>
|
|
|
|
+ <li><a href="?type=photo_family">photo_family 分享</a></li>
|
|
|
|
+ </body>
|
|
|
|
+ <script>
|
|
(function () {
|
|
(function () {
|
|
- // 从url里面读取参数 type
|
|
|
|
- const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
- const type = urlParams.get("type");
|
|
|
|
- // 如果type为空,则警告lert("请输入type参数")
|
|
|
|
- if (!type) {
|
|
|
|
- showStatus("请输入type参数");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let urlMap = {
|
|
|
|
- tri: ["http://192.168.3.36:9002/", "https://tri.tianyunperfect.cn/"],
|
|
|
|
- photo: ["http://192.168.3.36:8063/", "https://photo.n.tianyunperfect.cn/","https://photo.tianyunperfect.cn/photos"]
|
|
|
|
- };
|
|
|
|
|
|
+ let urlMap = {
|
|
|
|
+ tri: ["http://192.168.3.36:9002/", "https://tri.tianyunperfect.cn/"],
|
|
|
|
+ photo_family: [
|
|
|
|
+ "http://192.168.3.36:8063/share?key=LSMTb36t",
|
|
|
|
+ "https://photo.n.tianyunperfect.cn/share?key=LSMTb36t",
|
|
|
|
+ "https://photo.tianyunperfect.cn/share?key=LSMTb36t",
|
|
|
|
+ ],
|
|
|
|
+ photo: [
|
|
|
|
+ "http://192.168.3.36:8063/",
|
|
|
|
+ "https://photo.n.tianyunperfect.cn/",
|
|
|
|
+ "https://photo.tianyunperfect.cn/photos",
|
|
|
|
+ ],
|
|
|
|
+ };
|
|
|
|
|
|
- const urls = urlMap[type];
|
|
|
|
|
|
+ // 从url里面读取参数 type
|
|
|
|
+ const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
+ const type = urlParams.get("type");
|
|
|
|
+ // 如果type为空,则警告lert("请输入type参数")
|
|
|
|
+ if (!type) {
|
|
|
|
+ showStatus("请输入type参数");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- function checkUrl(url) {
|
|
|
|
- return new Promise((resolve) => {
|
|
|
|
- const startTime = performance.now();
|
|
|
|
- const img = new Image();
|
|
|
|
- let isResolved = false;
|
|
|
|
|
|
+ const urls = urlMap[type];
|
|
|
|
|
|
- img.onload = function () {
|
|
|
|
- if (!isResolved) {
|
|
|
|
- isResolved = true;
|
|
|
|
- resolve({
|
|
|
|
- url: url,
|
|
|
|
- accessible: true,
|
|
|
|
- responseTime: performance.now() - startTime,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+ function checkUrl(url) {
|
|
|
|
+ return new Promise((resolve) => {
|
|
|
|
+ const startTime = performance.now();
|
|
|
|
+ const img = new Image();
|
|
|
|
+ let isResolved = false;
|
|
|
|
|
|
- img.onerror = function () {
|
|
|
|
- if (!isResolved) {
|
|
|
|
- isResolved = true;
|
|
|
|
- resolve({
|
|
|
|
- url: url,
|
|
|
|
- accessible: true,
|
|
|
|
- responseTime: performance.now() - startTime,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+ img.onload = function () {
|
|
|
|
+ if (!isResolved) {
|
|
|
|
+ isResolved = true;
|
|
|
|
+ resolve({
|
|
|
|
+ url: url,
|
|
|
|
+ accessible: true,
|
|
|
|
+ responseTime: performance.now() - startTime,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
- if (!isResolved) {
|
|
|
|
- isResolved = true;
|
|
|
|
- resolve({
|
|
|
|
- url: url,
|
|
|
|
- accessible: false,
|
|
|
|
- responseTime: 99999,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }, 5000);
|
|
|
|
|
|
+ img.onerror = function () {
|
|
|
|
+ if (!isResolved) {
|
|
|
|
+ isResolved = true;
|
|
|
|
+ resolve({
|
|
|
|
+ url: url,
|
|
|
|
+ accessible: true,
|
|
|
|
+ responseTime: performance.now() - startTime,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
|
|
- const timestamp = new Date().getTime();
|
|
|
|
- img.src = url + `favicon.ico?t=${timestamp}`;
|
|
|
|
- });
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ if (!isResolved) {
|
|
|
|
+ isResolved = true;
|
|
|
|
+ resolve({
|
|
|
|
+ url: url,
|
|
|
|
+ accessible: false,
|
|
|
|
+ responseTime: 99999,
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
+ }, 5000);
|
|
|
|
|
|
- function showStatus(message, isError = false) {
|
|
|
|
- let statusDiv = document.getElementById("url-checker-status");
|
|
|
|
- if (!statusDiv) {
|
|
|
|
- statusDiv = document.createElement("div");
|
|
|
|
- statusDiv.id = "url-checker-status";
|
|
|
|
- statusDiv.style.cssText = `
|
|
|
|
|
|
+ const timestamp = new Date().getTime();
|
|
|
|
+ img.src = url + `favicon.ico?t=${timestamp}`;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function showStatus(message, isError = false) {
|
|
|
|
+ let statusDiv = document.getElementById("url-checker-status");
|
|
|
|
+ if (!statusDiv) {
|
|
|
|
+ statusDiv = document.createElement("div");
|
|
|
|
+ statusDiv.id = "url-checker-status";
|
|
|
|
+ statusDiv.style.cssText = `
|
|
position: fixed;
|
|
position: fixed;
|
|
top: 10px;
|
|
top: 10px;
|
|
right: 10px;
|
|
right: 10px;
|
|
padding: 10px;
|
|
padding: 10px;
|
|
- background: ${isError ? "rgba(255, 0, 0, 0.8)" : "rgba(0, 0, 0, 0.8)"
|
|
|
|
- };
|
|
|
|
|
|
+ background: ${
|
|
|
|
+ isError ? "rgba(255, 0, 0, 0.8)" : "rgba(0, 0, 0, 0.8)"
|
|
|
|
+ };
|
|
color: white;
|
|
color: white;
|
|
border-radius: 5px;
|
|
border-radius: 5px;
|
|
z-index: 999999;
|
|
z-index: 999999;
|
|
@@ -90,48 +104,48 @@
|
|
max-width: 300px;
|
|
max-width: 300px;
|
|
word-break: break-word;
|
|
word-break: break-word;
|
|
`;
|
|
`;
|
|
- document.body.appendChild(statusDiv);
|
|
|
|
- }
|
|
|
|
- statusDiv.textContent = message;
|
|
|
|
- return statusDiv;
|
|
|
|
- }
|
|
|
|
|
|
+ document.body.appendChild(statusDiv);
|
|
|
|
+ }
|
|
|
|
+ statusDiv.textContent = message;
|
|
|
|
+ return statusDiv;
|
|
|
|
+ }
|
|
|
|
|
|
- async function checkAllUrls() {
|
|
|
|
- const statusDiv = showStatus("正在检测网络连接...");
|
|
|
|
|
|
+ async function checkAllUrls() {
|
|
|
|
+ const statusDiv = showStatus("正在检测网络连接...");
|
|
|
|
|
|
- try {
|
|
|
|
- const results = await Promise.all(urls.map((url) => checkUrl(url)));
|
|
|
|
- const accessibleUrls = results.filter((result) => result.accessible);
|
|
|
|
- console.log("检测结果:", results);
|
|
|
|
|
|
+ try {
|
|
|
|
+ const results = await Promise.all(urls.map((url) => checkUrl(url)));
|
|
|
|
+ const accessibleUrls = results.filter((result) => result.accessible);
|
|
|
|
+ console.log("检测结果:", results);
|
|
|
|
|
|
- if (accessibleUrls.length === 0) {
|
|
|
|
- showStatus("所有地址均无法访问!", true);
|
|
|
|
- setTimeout(() => statusDiv.remove(), 3000);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ if (accessibleUrls.length === 0) {
|
|
|
|
+ showStatus("所有地址均无法访问!", true);
|
|
|
|
+ setTimeout(() => statusDiv.remove(), 3000);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- const fastestUrl = accessibleUrls.reduce((prev, current) =>
|
|
|
|
- prev.responseTime < current.responseTime ? prev : current
|
|
|
|
- );
|
|
|
|
|
|
+ const fastestUrl = accessibleUrls.reduce((prev, current) =>
|
|
|
|
+ prev.responseTime < current.responseTime ? prev : current
|
|
|
|
+ );
|
|
|
|
|
|
- showStatus(
|
|
|
|
- `正在跳转到最快地址: ${fastestUrl.url}\n响应时间: ${Math.round(
|
|
|
|
- fastestUrl.responseTime
|
|
|
|
- )}ms`
|
|
|
|
- );
|
|
|
|
|
|
+ showStatus(
|
|
|
|
+ `正在跳转到最快地址: ${fastestUrl.url}\n响应时间: ${Math.round(
|
|
|
|
+ fastestUrl.responseTime
|
|
|
|
+ )}ms`
|
|
|
|
+ );
|
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
- window.location.href = fastestUrl.url;
|
|
|
|
- statusDiv.remove();
|
|
|
|
- }, 1500);
|
|
|
|
- } catch (error) {
|
|
|
|
- console.error("检测过程出错:", error);
|
|
|
|
- showStatus("检测过程出错,请稍后重试", true);
|
|
|
|
- setTimeout(() => statusDiv.remove(), 3000);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ window.location.href = fastestUrl.url;
|
|
|
|
+ statusDiv.remove();
|
|
|
|
+ }, 1500);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("检测过程出错:", error);
|
|
|
|
+ showStatus("检测过程出错,请稍后重试", true);
|
|
|
|
+ setTimeout(() => statusDiv.remove(), 3000);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- checkAllUrls();
|
|
|
|
- })();
|
|
|
|
-</script>
|
|
|
|
|
|
+ checkAllUrls();
|
|
|
|
+ })();
|
|
|
|
+ </script>
|
|
</html>
|
|
</html>
|