浏览代码

!2 did not stop ws if connect from localhost

pcacc 5 月之前
父节点
当前提交
49f17a5cd0
共有 2 个文件被更改,包括 16 次插入9 次删除
  1. 1 0
      .gitignore
  2. 15 9
      templates/index_dongri.html

+ 1 - 0
.gitignore

@@ -5,3 +5,4 @@ __pycache__/yys_define.cpython-311.pyc
 __pycache__/yys_pic.cpython-311.pyc
 __pycache__/yys_task.cpython-311.pyc
 config.json
+*.pyc

+ 15 - 9
templates/index_dongri.html

@@ -144,15 +144,21 @@
             socket.emit('reset_script');
         }
         function stopPageAndCloseSocket() {
-            // 停止定时器
-            clearInterval(timerId);
-            // 关闭WebSocket连接
-            socket.disconnect();
-            // 清除画布内容(可选)
-            var canvas = document.getElementById("canvas");
-            var ctx = canvas.getContext("2d");
-            ctx.clearRect(0, 0, canvas.width, canvas.height);
-            // 可以添加其他停止页面运行的逻辑...
+            // 获取当前连接的 WebSocket URL
+            const socketUrl = socket.io.uri;
+
+            // 检查是否为本地连接
+            if (!socketUrl.includes("127.0.0.1")) {
+                // 停止定时器
+                clearInterval(timerId);
+                // 关闭 WebSocket 连接
+                socket.disconnect();
+                // 清除画布内容(可选)
+                var canvas = document.getElementById("canvas");
+                var ctx = canvas.getContext("2d");
+                ctx.clearRect(0, 0, canvas.width, canvas.height);
+                // 可以添加其他停止页面运行的逻辑...
+            }
         }
 
         // 页面加载时设置5分钟后的定时器