1
0

votes.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Active votes</title>
  7. <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
  8. <style>
  9. body {
  10. background-color: transparent;
  11. color: white;
  12. width: 400px;
  13. position: absolute;
  14. bottom: 0; left: 0;
  15. font-weight: bold;
  16. }
  17. </style>
  18. <script>
  19. function checkForVoteUpdates() {
  20. fetch('/updateVotes')
  21. .then(response => response.json())
  22. .then(data => {
  23. const newVotes = data.votes;
  24. const currentVotes = Array.from(document.querySelectorAll('tbody tr')).map(tr => {
  25. return {
  26. text: tr.children[0].textContent,
  27. count: parseInt(tr.children[1].textContent)
  28. };
  29. });
  30. if (JSON.stringify(newVotes) !== JSON.stringify(currentVotes)) {
  31. window.location.reload(); // Refresh if votes have changed
  32. }
  33. })
  34. .catch(error => console.error('Error fetching updated votes:', error));
  35. }
  36. setInterval(checkForVoteUpdates, 15 * 1000); // Check every 15 seconds
  37. </script>
  38. </head>
  39. <body>
  40. {% if votes %}
  41. <table>
  42. <thead>
  43. <tr>
  44. <th>Item</th>
  45. <th>Votes</th>
  46. </tr>
  47. </thead>
  48. <tbody>
  49. {% for vote in votes %}
  50. <tr>
  51. <td>{{ vote[2] }}</td>
  52. <td>{{ vote[1] }} vote{% if vote[1] != 1 %}s{% endif %}</td>
  53. </tr>
  54. {% endfor %}
  55. </tbody>
  56. </table>
  57. {% else %}
  58. <p>No active votes at the moment.</p>
  59. {% endif %}
  60. </body>
  61. </html>