Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Timer App</title> | |
| <style> | |
| body { | |
| font-family: Arial, sans-serif; | |
| text-align: center; | |
| margin-top: 50px; | |
| } | |
| .container { | |
| display: inline-block; | |
| text-align: left; | |
| } | |
| #timer_output { | |
| margin-top: 20px; | |
| font-size: 20px; | |
| font-weight: bold; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>Timer App</h1> | |
| <label for="seconds">Set Timer (seconds):</label> | |
| <input type="number" id="seconds" min="1" max="600" step="1" value="10"> | |
| <button onclick="startTimer()">Start Timer</button> | |
| <div id="timer_output"></div> | |
| </div> | |
| <script> | |
| function startTimer() { | |
| var seconds = document.getElementById("seconds").value; | |
| fetch("/start_timer", { | |
| method: "POST", | |
| body: new URLSearchParams({ | |
| seconds: seconds | |
| }), | |
| headers: { | |
| "Content-Type": "application/x-www-form-urlencoded" | |
| } | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| console.log(data.message); | |
| }); | |
| updateTimerOutput(); | |
| } | |
| function updateTimerOutput() { | |
| var timerOutput = document.getElementById("timer_output"); | |
| var interval = setInterval(function() { | |
| fetch("/get_timer") | |
| .then(response => response.json()) | |
| .then(data => { | |
| if (data.message) { | |
| timerOutput.innerText = data.message; | |
| } | |
| if (data.message === "Time's up!") { | |
| clearInterval(interval); | |
| } | |
| }); | |
| }, 1000); // Poll every second to get the timer update | |
| } | |
| </script> | |
| </body> | |
| </html> | |