Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): add timer to radio page #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions delta_radio/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<input type="range" min="0" max="1" step="0.01" value="0.5" id="volume-slider" class="w-full h-4 rounded-full overflow-hidden appearance-none bg-gray-200">
</div>

<!-- Timer that counts how long the page has been open -->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a label to the timer for accessibility purposes.

<div>
<span id="timer">00:00</span>
</div>

<audio id="audio" autoplay="true" controls=true style="display: none;"></audio>
</body>

Expand All @@ -35,4 +40,25 @@
localStorage.setItem('volume', volumeSlider.value);
});
</script>

<script>
const timerElement = document.getElementById("timer");
let seconds = 0;
let minutes = 0;

setInterval(() => {
seconds++;
if (seconds === 60) {
seconds = 0;
minutes++;
}

const formattedTime = `${padZero(minutes)}:${padZero(seconds)}`;
timerElement.textContent = formattedTime;
}, 1000);

function padZero(num) {
return num.toString().padStart(2, '0');
}
</script>
</html>