index.html 844 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <h2 style="font-family:sans-serif;">📡 实时数据日志</h2>
  2. <button onclick="clearLog()" style="
  3. margin-bottom: 10px;
  4. padding: 6px 16px;
  5. background-color: #444;
  6. color: #fff;
  7. border: none;
  8. border-radius: 6px;
  9. cursor: pointer;
  10. ">
  11. 🧹 清空日志
  12. </button>
  13. <pre id="logBox" style="
  14. height: 600px;
  15. overflow: auto;
  16. background: #111;
  17. color: #0f0;
  18. padding: 16px;
  19. font-size: 18px;
  20. font-family: monospace;
  21. border-radius: 8px;
  22. box-shadow: 0 0 10px #0f0;
  23. "></pre>
  24. <script>
  25. const logBox = document.getElementById("logBox");
  26. const ws = new WebSocket("ws://" + location.host + "/ws");
  27. ws.onmessage = (event) => {
  28. logBox.textContent += event.data + "\n";
  29. logBox.scrollTop = logBox.scrollHeight;
  30. };
  31. function clearLog() {
  32. logBox.textContent = "";
  33. }
  34. </script>