2024-10-18 22:39:29 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Pomodoro Timer</title>
|
2024-10-19 08:08:54 +00:00
|
|
|
<style>
|
|
|
|
button {
|
|
|
|
padding: 10px 20px;
|
|
|
|
margin: 5px;
|
|
|
|
font-size: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#timer {
|
|
|
|
font-size: 24px;
|
|
|
|
margin-top: 20px;
|
|
|
|
}
|
|
|
|
</style>
|
2024-10-18 22:39:29 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<h1>Pomodoro Timer</h1>
|
|
|
|
<div id="timer">Connecting to server...</div>
|
|
|
|
|
2024-10-19 08:08:54 +00:00
|
|
|
<!-- Buttons to start and stop the timer -->
|
|
|
|
<button id="startButton">Start</button>
|
|
|
|
<button id="stopButton">Stop</button>
|
|
|
|
|
2024-10-18 22:39:29 +00:00
|
|
|
<script>
|
|
|
|
var ws = new WebSocket("ws://localhost:8080/ws");
|
|
|
|
|
2024-10-19 08:08:54 +00:00
|
|
|
ws.onopen = function () {
|
|
|
|
document.getElementById("timer").innerText = "Connected to server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
// Handle incoming messages and update the timer display
|
2024-10-18 22:39:29 +00:00
|
|
|
ws.onmessage = function (event) {
|
2024-10-19 08:08:54 +00:00
|
|
|
var data = JSON.parse(event.data);
|
|
|
|
var mode = data.mode;
|
|
|
|
var session = data.session;
|
|
|
|
var maxSession = data.max_session;
|
|
|
|
var timeLeft = data.time_left;
|
|
|
|
|
|
|
|
document.getElementById("timer").innerText =
|
|
|
|
mode + " Session " + session + "/" + maxSession + ": " + formatTime(timeLeft);
|
2024-10-18 22:39:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ws.onclose = function () {
|
|
|
|
document.getElementById("timer").innerText = "Connection closed.";
|
|
|
|
};
|
2024-10-19 08:08:54 +00:00
|
|
|
|
|
|
|
// Format time in MM:SS
|
|
|
|
function formatTime(seconds) {
|
|
|
|
var minutes = Math.floor(seconds / 60);
|
|
|
|
var remainingSeconds = seconds % 60;
|
|
|
|
return minutes.toString().padStart(2, '0') + ":" + remainingSeconds.toString().padStart(2, '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send start command to the server
|
|
|
|
document.getElementById("startButton").addEventListener("click", function () {
|
|
|
|
ws.send(JSON.stringify({command: "start"}));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Send stop command to the server
|
|
|
|
document.getElementById("stopButton").addEventListener("click", function () {
|
|
|
|
ws.send(JSON.stringify({command: "stop"}));
|
|
|
|
});
|
2024-10-18 22:39:29 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|