Browse Source

test(tmp): 在 tmp.html 中添加 HTTP 请求示例代码

- 注释掉了使用 axios 库的请求示例
- 添加了使用 Fetch API 的 POST 请求示例
- 设置了请求头,包括 Referer、User-Agent、Token 等信息
- 发送了包含 id 和 token 参数的 JSON 数据
- 处理了请求的响应和错误
tianyunperfect 5 months ago
parent
commit
2172816d1c
4 changed files with 162 additions and 1 deletions
  1. 1 0
      folder-alias.json
  2. 111 0
      monkey/域名检测跳转.js
  3. 1 0
      tmp/chang_local.js
  4. 49 1
      tmp/tmp.html

+ 1 - 0
folder-alias.json

@@ -0,0 +1 @@
+{}

+ 111 - 0
monkey/域名检测跳转.js

@@ -0,0 +1,111 @@
+javascript: (function () {
+  const urls = ["http://192.168.3.36:9002/", "https://tri.tianyunperfect.cn/"];
+
+  function checkUrl(url) {
+    return new Promise((resolve) => {
+      const startTime = performance.now();
+      const img = new Image();
+      let isResolved = false;
+
+      img.onload = function () {
+        if (!isResolved) {
+          isResolved = true;
+          resolve({
+            url: url,
+            accessible: true,
+            responseTime: performance.now() - startTime,
+          });
+        }
+      };
+
+      img.onerror = 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);
+
+      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;
+                top: 10px;
+                right: 10px;
+                padding: 10px;
+                background: ${
+                  isError ? "rgba(255, 0, 0, 0.8)" : "rgba(0, 0, 0, 0.8)"
+                };
+                color: white;
+                border-radius: 5px;
+                z-index: 999999;
+                font-family: Arial, sans-serif;
+                font-size: 14px;
+                max-width: 300px;
+                word-break: break-word;
+            `;
+      document.body.appendChild(statusDiv);
+    }
+    statusDiv.textContent = message;
+    return statusDiv;
+  }
+
+  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);
+
+      if (accessibleUrls.length === 0) {
+        showStatus("所有地址均无法访问!", true);
+        setTimeout(() => statusDiv.remove(), 3000);
+        return;
+      }
+
+      const fastestUrl = accessibleUrls.reduce((prev, current) =>
+        prev.responseTime < current.responseTime ? prev : current
+      );
+
+      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);
+    }
+  }
+
+  checkAllUrls();
+})();

+ 1 - 0
tmp/chang_local.js

@@ -0,0 +1 @@
+// 检测顺序:http://192.168.3.36:9002/    https://tri.tianyunperfect.cn/

+ 49 - 1
tmp/tmp.html

@@ -30,6 +30,54 @@
 <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
 <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
 </body>
 </body>
 <script>
 <script>
-    <!--   -->
+  //   curl 'https://www.suoyoutongxue.cn/biz/video_lesson' \
+  // -H 'Referer: http://localhost:8080/' \
+  // -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
+  // -H 'Token: 4fefa7f2f623b3ab-e2dbfaadc863221a941069830427056a276b8882fed736822ec83102eeefa660aaa055c1003cf4ab0da572' \
+  // -H 'content-type: application/json;charset=UTF-8' \
+  // --data-raw '{"id":"970","token":"4fefa7f2f623b3ab-e2dbfaadc863221a941069830427056a276b8882fed736822ec83102eeefa660aaa055c1003cf4ab0da572"}'
+  // const data = {
+  //     id: "970",
+  //     token: "4fefa7f2f623b3ab-e2dbfaadc863221a941069830427056a276b8882fed736822ec83102eeefa660aaa055c1003cf4ab0da572"
+  // };
+  //
+  // const config = {
+  //     headers: {
+  //         'Referer': 'http://localhost:8080/',
+  //         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
+  //         'Token': '4fefa7f2f623b3ab-e2dbfaadc863221a941069830427056a276b8882fed736822ec83102eeefa660aaa055c1003cf4ab0da572',
+  //         'content-type': 'application/json;charset=UTF-8'
+  //     }
+  // };
+  //
+  // axios.post('https://www.suoyoutongxue.cn/biz/video_lesson', data, config)
+  //     .then(response => {
+  //         console.log(response.data);
+  //     })
+  //     .catch(error => {
+  //         console.error(error);
+  //     });
+  var myHeaders = new Headers();
+  myHeaders.append("Referer", "http://localhost:8080/");
+  myHeaders.append("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36");
+  myHeaders.append("Token", "4fefa7f2f623b3ab-e2dbfaadc863221a941069830427056a276b8882fed736822ec83102eeefa660aaa055c1003cf4ab0da572");
+  myHeaders.append("content-type", "application/json;charset=UTF-8");
+  myHeaders.append("Accept", "*/*");
+  myHeaders.append("Host", "www.suoyoutongxue.cn");
+  myHeaders.append("Connection", "keep-alive");
+
+  var raw = "{\"id\":\"970\",\"token\":\"4fefa7f2f623b3ab-e2dbfaadc863221a941069830427056a276b8882fed736822ec83102eeefa660aaa055c1003cf4ab0da572\"}";
+
+  var requestOptions = {
+      method: 'POST',
+      headers: myHeaders,
+      body: raw,
+      redirect: 'follow'
+  };
+
+  fetch("https://www.suoyoutongxue.cn/biz/video_lesson", requestOptions)
+      .then(response => response.text())
+      .then(result => console.log(result))
+      .catch(error => console.log('error', error));
 </script>
 </script>
 </html>
 </html>