feat(countdown): redirect to /adhesion at the end

This commit is contained in:
Matthieu Bessat 2023-07-14 11:31:40 +02:00
parent 741ba5c10e
commit 16aa9bd4bb

View file

@ -69,25 +69,32 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/3.3.0/luxon.min.js" integrity="sha512-KKbQg5o92MwtJKR9sfm/HkREzfyzNMiKPIQ7i7SZOxwEdiNCm4Svayn2DBq7MKEdrqPJUOSIpy1v6PpFlCQ0YA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/3.3.0/luxon.min.js" integrity="sha512-KKbQg5o92MwtJKR9sfm/HkREzfyzNMiKPIQ7i7SZOxwEdiNCm4Svayn2DBq7MKEdrqPJUOSIpy1v6PpFlCQ0YA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script> <script>
const components = ['days', 'hours', 'minutes', 'seconds']
// to test: const target = luxon.DateTime.now().plus(luxon.Duration.fromISO("PT10S"))
const target = luxon.DateTime.utc(2023, 7, 14, 10, 0, 0)
const components = ['days', 'hours', 'minutes', 'seconds'] function render() {
let now = luxon.DateTime.now()
let duration = now.diff(target, components)
console.debug(duration.values)
function render() { if (target < now) {
let duration = luxon.DateTime.now().diff(luxon.DateTime.utc(2023, 7, 14, 10, 0, 0), components) console.log("COUNTDOWN: Target reached!")
console.log(duration.values) document.location = document.location.origin + "/adhesion"
}
components.forEach(key => { components.forEach(key => {
document.getElementById(key).innerText = (-duration.values[key]).toString().split(".")[0].padStart(2, "0") document.getElementById(key).innerText = (-duration.values[key]).toString().split(".")[0].padStart(2, "0")
// test with random values // test with random values
// document.getElementById(key).innerText = (Math.floor(Math.random() * 99)).toString().split(".")[0].padStart(2, "0") // document.getElementById(key).innerText = (Math.floor(Math.random() * 99)).toString().split(".")[0].padStart(2, "0")
}) })
} }
render()
setInterval(() => {
render() render()
}, 1000) setInterval(() => {
render()
}, 1000)
</script> </script>
{{ end }} {{ end }}