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;
|
|
|
|
}
|
2024-10-21 16:23:50 +00:00
|
|
|
|
|
|
|
input {
|
|
|
|
width: 75px;
|
|
|
|
}
|
2024-10-19 08:08:54 +00:00
|
|
|
</style>
|
2024-10-18 22:39:29 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<h1>Pomodoro Timer</h1>
|
|
|
|
|
2024-10-21 16:23:50 +00:00
|
|
|
<!-- Input fields for custom Pomodoro config and control password -->
|
|
|
|
<p>
|
|
|
|
<label for="password">Control Password:</label>
|
|
|
|
<input type="text" id="password" placeholder="Password" />
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<label for="workDuration">Work Duration (seconds):</label>
|
|
|
|
<input type="number" id="workDuration" placeholder="Work time in seconds" value="900" />
|
|
|
|
<br />
|
|
|
|
<label for="shortBreakDuration">Short Break Duration (seconds):</label>
|
|
|
|
<input type="number" id="shortBreakDuration" placeholder="Short break in seconds" value="300" />
|
|
|
|
<br />
|
|
|
|
<label for="longBreakDuration">Long Break Duration (seconds):</label>
|
|
|
|
<input type="number" id="longBreakDuration" placeholder="Long break in seconds" value="600" />
|
|
|
|
<br />
|
|
|
|
<label for="sessions">Number of Sessions:</label>
|
|
|
|
<input type="number" id="sessions" placeholder="Number of sessions" value="4" />
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<div id="timer">Connting to server...</div>
|
|
|
|
|
|
|
|
<!-- Buttons to start, pause/resume, and reset the timer -->
|
2024-10-19 08:08:54 +00:00
|
|
|
<button id="startButton">Start</button>
|
2024-10-19 16:15:16 +00:00
|
|
|
<button id="pauseResumeButton" style="display: none;">Pause</button>
|
2024-10-20 08:02:00 +00:00
|
|
|
<button id="resetButton" style="display: none;">Reset</button>
|
2024-10-19 08:08:54 +00:00
|
|
|
|
2024-10-18 22:39:29 +00:00
|
|
|
<script>
|
|
|
|
var ws = new WebSocket("ws://localhost:8080/ws");
|
2024-10-19 16:15:16 +00:00
|
|
|
var isPaused = false; // Track if the timer is paused
|
2024-10-18 22:39:29 +00:00
|
|
|
|
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;
|
2024-10-20 21:20:23 +00:00
|
|
|
var totalSession = data.total_sessions;
|
2024-10-19 08:08:54 +00:00
|
|
|
var timeLeft = data.time_left;
|
|
|
|
|
|
|
|
document.getElementById("timer").innerText =
|
2024-10-20 21:20:23 +00:00
|
|
|
mode + " Session " + session + "/" + totalSession + ": " + 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');
|
|
|
|
}
|
|
|
|
|
2024-10-19 16:15:16 +00:00
|
|
|
// Start Button Click Event
|
2024-10-19 08:08:54 +00:00
|
|
|
document.getElementById("startButton").addEventListener("click", function () {
|
2024-10-21 16:23:50 +00:00
|
|
|
// Get the values from the input fields
|
|
|
|
var password = document.getElementById("password").value;
|
|
|
|
var work = parseInt(document.getElementById("workDuration").value);
|
|
|
|
var shortBreak = parseInt(document.getElementById("shortBreakDuration").value);
|
|
|
|
var longBreak = parseInt(document.getElementById("longBreakDuration").value);
|
|
|
|
var sessions = parseInt(document.getElementById("sessions").value);
|
|
|
|
|
|
|
|
// Send the start command with the custom config and password
|
|
|
|
ws.send(JSON.stringify({
|
|
|
|
command: "start",
|
|
|
|
password: password,
|
|
|
|
config: {
|
|
|
|
work: work,
|
|
|
|
shortBreak: shortBreak,
|
|
|
|
longBreak: longBreak,
|
|
|
|
sessions: sessions
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Hide start button and show pause/resume and reset buttons
|
2024-10-19 16:15:16 +00:00
|
|
|
document.getElementById("startButton").style.display = "none";
|
|
|
|
document.getElementById("pauseResumeButton").style.display = "inline-block";
|
2024-10-20 08:02:00 +00:00
|
|
|
document.getElementById("resetButton").style.display = "inline-block";
|
2024-10-19 16:15:16 +00:00
|
|
|
|
|
|
|
// Set the pause/resume button to show "Pause" initially
|
|
|
|
isPaused = false;
|
|
|
|
document.getElementById("pauseResumeButton").innerText = "Pause";
|
2024-10-19 08:08:54 +00:00
|
|
|
});
|
|
|
|
|
2024-10-19 16:15:16 +00:00
|
|
|
// Pause/Resume Button Click Event
|
|
|
|
document.getElementById("pauseResumeButton").addEventListener("click", function () {
|
2024-10-21 16:23:50 +00:00
|
|
|
var password = document.getElementById("password").value;
|
2024-10-19 16:15:16 +00:00
|
|
|
if (isPaused) {
|
|
|
|
// If paused, send resume command and update button text
|
2024-10-21 16:23:50 +00:00
|
|
|
ws.send(JSON.stringify({command: "resume", password: password}));
|
2024-10-19 16:15:16 +00:00
|
|
|
document.getElementById("pauseResumeButton").innerText = "Pause";
|
|
|
|
isPaused = false;
|
|
|
|
} else {
|
|
|
|
// If running, send pause command and update button text
|
2024-10-21 16:23:50 +00:00
|
|
|
ws.send(JSON.stringify({command: "pause", password: password}));
|
2024-10-19 16:15:16 +00:00
|
|
|
document.getElementById("pauseResumeButton").innerText = "Resume";
|
|
|
|
isPaused = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-10-20 08:02:00 +00:00
|
|
|
// Reset Button Click Event
|
|
|
|
document.getElementById("resetButton").addEventListener("click", function () {
|
2024-10-21 16:23:50 +00:00
|
|
|
var password = document.getElementById("password").value;
|
|
|
|
ws.send(JSON.stringify({
|
|
|
|
command: "stop",
|
|
|
|
password: password
|
|
|
|
}));
|
2024-10-19 16:15:16 +00:00
|
|
|
|
|
|
|
// Reset buttons after stopping
|
|
|
|
document.getElementById("startButton").style.display = "inline-block";
|
|
|
|
document.getElementById("pauseResumeButton").style.display = "none";
|
2024-10-20 08:02:00 +00:00
|
|
|
document.getElementById("resetButton").style.display = "none";
|
2024-10-19 08:08:54 +00:00
|
|
|
});
|
2024-10-18 22:39:29 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|