File size: 2,141 Bytes
ff994df
 
 
 
 
 
6d3b08c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff994df
 
6d3b08c
 
 
 
 
 
 
 
 
 
ff994df
 
 
6d3b08c
 
ff994df
6d3b08c
ff994df
6d3b08c
 
 
 
 
ff994df
6d3b08c
 
 
 
ff994df
6d3b08c
 
 
 
 
 
 
33d8a68
 
 
 
 
 
 
 
 
 
 
6d3b08c
ff994df
6d3b08c
ff994df
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<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>