Initial
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Timer</title>
|
||||
<style>
|
||||
body, html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.timer {
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
padding: 20px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 10px;
|
||||
background-color: white;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.timer.green {
|
||||
background-color: green;
|
||||
color: white;
|
||||
}
|
||||
.timer.blue {
|
||||
background-color: blue;
|
||||
color: white;
|
||||
}
|
||||
.timer.red {
|
||||
background-color: red;
|
||||
color: white;
|
||||
}
|
||||
.controls {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.controls button {
|
||||
padding: 10px 20px;
|
||||
font-size: 1em;
|
||||
margin: 0 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="totalTimeDisplay" class="timer"></div>
|
||||
<div id="exerciseDisplay" class="timer"></div>
|
||||
<div id="setDisplay" class="timer"></div>
|
||||
<div id="lapDisplay" class="timer"></div>
|
||||
<div class="controls">
|
||||
<button id="startButton">Start</button>
|
||||
<button id="stopButton" disabled>Stop</button>
|
||||
</div>
|
||||
<script>
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const timerId = urlParams.get('id');
|
||||
|
||||
let totalTime, setTime, restTime, moveTime, setCount, exerciseCount, lapCount;
|
||||
let currentLap = 0;
|
||||
let currentExercise = 0;
|
||||
let currentSet = 0;
|
||||
let currentPhase = 'set';
|
||||
let timeLeft, totalTimeLeft;
|
||||
let interval;
|
||||
|
||||
const totalTimeDisplay = document.getElementById('totalTimeDisplay');
|
||||
const exerciseDisplay = document.getElementById('exerciseDisplay');
|
||||
const setDisplay = document.getElementById('setDisplay');
|
||||
const lapDisplay = document.getElementById('lapDisplay');
|
||||
const startButton = document.getElementById('startButton');
|
||||
const stopButton = document.getElementById('stopButton');
|
||||
|
||||
startButton.addEventListener('click', startTimer);
|
||||
stopButton.addEventListener('click', stopTimer);
|
||||
|
||||
async function fetchTimerData() {
|
||||
const response = await fetch(`/timers/${timerId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
alert('Failed to fetch timer data');
|
||||
return;
|
||||
}
|
||||
const timerData = await response.json();
|
||||
totalTime = timerData.totalTime;
|
||||
setTime = timerData.setTime;
|
||||
restTime = timerData.restTime;
|
||||
moveTime = timerData.moveTime;
|
||||
setCount = timerData.setCount;
|
||||
exerciseCount = timerData.exerciseCount;
|
||||
lapCount = timerData.lapCount;
|
||||
timeLeft = setTime;
|
||||
totalTimeLeft = totalTime;
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
function formatTime(seconds) {
|
||||
const hrs = Math.floor(seconds / 3600);
|
||||
const mins = Math.floor((seconds % 3600) / 60);
|
||||
const secs = seconds % 60;
|
||||
return `${String(hrs).padStart(2, '0')}:${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function updateDisplay() {
|
||||
totalTimeDisplay.textContent = `Total Time: ${formatTime(totalTimeLeft)}`;
|
||||
setDisplay.textContent = `${currentPhase === 'set' ? 'Set' : currentPhase === 'rest' ? 'Rest' : 'Transition'} Time: ${formatTime(timeLeft)}`;
|
||||
setDisplay.className = `timer ${currentPhase === 'set' ? 'green' : currentPhase === 'rest' ? 'blue' : 'red'}`;
|
||||
exerciseDisplay.textContent = `Exercise: ${currentExercise + 1} / ${exerciseCount}`;
|
||||
lapDisplay.textContent = `Lap: ${currentLap + 1} / ${lapCount}`;
|
||||
}
|
||||
|
||||
function startTimer() {
|
||||
startButton.disabled = true;
|
||||
stopButton.disabled = false;
|
||||
interval = setInterval(timer, 1000);
|
||||
}
|
||||
|
||||
function stopTimer() {
|
||||
startButton.disabled = false;
|
||||
stopButton.disabled = true;
|
||||
clearInterval(interval);
|
||||
}
|
||||
|
||||
function timer() {
|
||||
totalTimeLeft--;
|
||||
timeLeft--;
|
||||
if (totalTimeLeft <= 0) {
|
||||
clearInterval(interval);
|
||||
alert('Workout complete!');
|
||||
return;
|
||||
}
|
||||
if (timeLeft < 0) {
|
||||
if (currentPhase === 'set') {
|
||||
if (currentSet < setCount - 1) {
|
||||
currentPhase = 'rest';
|
||||
timeLeft = restTime;
|
||||
currentSet++;
|
||||
} else {
|
||||
currentPhase = 'move';
|
||||
timeLeft = moveTime;
|
||||
}
|
||||
} else if (currentPhase === 'rest') {
|
||||
currentPhase = 'set';
|
||||
timeLeft = setTime;
|
||||
} else if (currentPhase === 'move') {
|
||||
currentExercise++;
|
||||
if (currentExercise >= exerciseCount) {
|
||||
currentExercise = 0;
|
||||
currentLap++;
|
||||
if (currentLap >= lapCount) {
|
||||
clearInterval(interval);
|
||||
alert('Workout complete!');
|
||||
return;
|
||||
}
|
||||
}
|
||||
currentPhase = 'set';
|
||||
timeLeft = setTime;
|
||||
currentSet = 0;
|
||||
}
|
||||
}
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', fetchTimerData);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user