Spaces:
Sleeping
Sleeping
Create templates/index.html
Browse files- templates/index.html +56 -17
templates/index.html
CHANGED
|
@@ -4,32 +4,71 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Timer App</title>
|
| 7 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
-
|
| 11 |
-
<div>
|
| 12 |
-
<
|
| 13 |
-
|
| 14 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
</div>
|
| 16 |
-
<div id="timer_output"></div>
|
| 17 |
|
| 18 |
<script>
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
let seconds = $("#seconds").val();
|
| 22 |
|
| 23 |
-
|
| 24 |
-
$.ajax({
|
| 25 |
-
url: "/start_timer",
|
| 26 |
method: "POST",
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
});
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
</script>
|
|
|
|
| 34 |
</body>
|
| 35 |
</html>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Timer App</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: Arial, sans-serif;
|
| 10 |
+
text-align: center;
|
| 11 |
+
margin-top: 50px;
|
| 12 |
+
}
|
| 13 |
+
.container {
|
| 14 |
+
display: inline-block;
|
| 15 |
+
text-align: left;
|
| 16 |
+
}
|
| 17 |
+
#timer_output {
|
| 18 |
+
margin-top: 20px;
|
| 19 |
+
font-size: 20px;
|
| 20 |
+
font-weight: bold;
|
| 21 |
+
}
|
| 22 |
+
</style>
|
| 23 |
</head>
|
| 24 |
<body>
|
| 25 |
+
|
| 26 |
+
<div class="container">
|
| 27 |
+
<h1>Timer App</h1>
|
| 28 |
+
|
| 29 |
+
<label for="seconds">Set Timer (seconds):</label>
|
| 30 |
+
<input type="number" id="seconds" min="1" max="600" step="1" value="10">
|
| 31 |
+
|
| 32 |
+
<button onclick="startTimer()">Start Timer</button>
|
| 33 |
+
|
| 34 |
+
<div id="timer_output"></div>
|
| 35 |
</div>
|
|
|
|
| 36 |
|
| 37 |
<script>
|
| 38 |
+
function startTimer() {
|
| 39 |
+
var seconds = document.getElementById("seconds").value;
|
|
|
|
| 40 |
|
| 41 |
+
fetch("/start_timer", {
|
|
|
|
|
|
|
| 42 |
method: "POST",
|
| 43 |
+
body: new URLSearchParams({
|
| 44 |
+
seconds: seconds
|
| 45 |
+
}),
|
| 46 |
+
headers: {
|
| 47 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
| 48 |
}
|
| 49 |
+
})
|
| 50 |
+
.then(response => response.json())
|
| 51 |
+
.then(data => {
|
| 52 |
+
console.log(data.message);
|
| 53 |
});
|
| 54 |
+
|
| 55 |
+
updateTimerOutput();
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function updateTimerOutput() {
|
| 59 |
+
var timerOutput = document.getElementById("timer_output");
|
| 60 |
+
var remaining = parseInt(document.getElementById("seconds").value);
|
| 61 |
+
var interval = setInterval(function() {
|
| 62 |
+
if (remaining > 0) {
|
| 63 |
+
timerOutput.innerText = remaining + " seconds remaining...";
|
| 64 |
+
remaining--;
|
| 65 |
+
} else {
|
| 66 |
+
timerOutput.innerText = "Time's up!";
|
| 67 |
+
clearInterval(interval);
|
| 68 |
+
}
|
| 69 |
+
}, 1000);
|
| 70 |
+
}
|
| 71 |
</script>
|
| 72 |
+
|
| 73 |
</body>
|
| 74 |
</html>
|