monitor.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Torrent Monitor</title>
  6. <script src="{{ url_for('static', filename='js/jquery-3.7.1.min.js') }}"></script>
  7. <script src="{{ url_for('static', filename='js/socket.io.js') }}"></script>
  8. </head>
  9. <body>
  10. <h1>Torrent Monitor</h1>
  11. <table id="torrentsTable" border="1">
  12. <thead>
  13. <tr>
  14. <th>Name</th>
  15. <th>Download Speed</th>
  16. <th>Upload Speed</th>
  17. <th>Status</th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. <!-- 表格内容将通过SocketIO动态更新 -->
  22. </tbody>
  23. </table>
  24. <script>
  25. $(document).ready(function(){
  26. var socket = io.connect('http://' + document.domain + ':' + location.port);
  27. socket.on('torrents_status_update', function(data) {
  28. console.log("Received torrents status update:", data); // 打印接收到的数据到控制台
  29. var tbody = $('#torrentsTable tbody');
  30. tbody.empty(); // 清空表格内容
  31. console.log(data)
  32. // 确保data对象中包含torrents_status_update属性,并且它是一个数组
  33. if (data.torrents_status_update && Array.isArray(data.torrents_status_update)) {
  34. data.torrents_status_update.forEach(function(torrent) {
  35. var row = `<tr>
  36. <td>${torrent.name}</td>
  37. <td>${torrent.download_speed}</td>
  38. <td>${torrent.upload_speed}</td>
  39. <td>${torrent.status}</td>
  40. </tr>`;
  41. tbody.append(row);
  42. });
  43. } else {
  44. console.error("Error: Data does not contain a torrents_status_update array.");
  45. }
  46. });
  47. });
  48. </script>
  49. </body>
  50. </html>