diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-01-02 20:42:01 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-01-05 12:33:59 +0100 |
commit | b21316248572cb27ed1f504529ad6680a473022e (patch) | |
tree | f8a2f81258cae3b1d2429fb7df5a3287954b683a /views/http/components/timer.twig | |
parent | f621d95f89ded05a2e916c5ee363bfe75ea37482 (diff) |
gemini
Diffstat (limited to 'views/http/components/timer.twig')
-rw-r--r-- | views/http/components/timer.twig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/views/http/components/timer.twig b/views/http/components/timer.twig new file mode 100644 index 0000000..ccb31a7 --- /dev/null +++ b/views/http/components/timer.twig @@ -0,0 +1,26 @@ +<span class="timer" data-time="{{ time }}"> + <span class="timer__time"></span> +</span> +<script> +document.addEventListener('DOMContentLoaded', function (ev) { + const timer = document.querySelector('.timer[data-time="{{ time }}"] .timer__time'); + const time = new Date('{{ time }}'); + + const interval = setInterval(setTime, 1000); + function setTime() { + let diff = time - new Date(); + if (diff <= 0) { + clearInterval(interval); + window.location.reload(); + } + + const hh = Math.floor(diff/1000/60/60); + diff -= hh*1000*60*60; + const mm = Math.floor(diff/1000/60); + diff -= mm*1000*60; + const ss = Math.floor(diff/1000); + timer.innerHTML = `${('00' + hh).slice(-2)}:${('00' + mm).slice(-2)}:${('00' + ss).slice(-2)}`; + } + setTime(); +}); +</script> |