feat(countdown): redirect to /adhesion at the end
This commit is contained in:
parent
aa822b6f2e
commit
8687dae1ee
1 changed files with 21 additions and 14 deletions
|
@ -69,15 +69,23 @@
|
|||
|
||||
<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>
|
||||
|
||||
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)
|
||||
|
||||
function render() {
|
||||
let duration = luxon.DateTime.now().diff(luxon.DateTime.utc(2023, 7, 14, 10, 0, 0), components)
|
||||
console.log(duration.values)
|
||||
let now = luxon.DateTime.now()
|
||||
let duration = now.diff(target, components)
|
||||
console.debug(duration.values)
|
||||
|
||||
if (target < now) {
|
||||
console.log("COUNTDOWN: Target reached!")
|
||||
document.location = document.location.origin + "/adhesion"
|
||||
}
|
||||
|
||||
components.forEach(key => {
|
||||
document.getElementById(key).innerText = (-duration.values[key]).toString().split(".")[0].padStart(2, "0")
|
||||
|
||||
// test with random values
|
||||
// document.getElementById(key).innerText = (Math.floor(Math.random() * 99)).toString().split(".")[0].padStart(2, "0")
|
||||
})
|
||||
|
@ -87,7 +95,6 @@ render()
|
|||
setInterval(() => {
|
||||
render()
|
||||
}, 1000)
|
||||
|
||||
</script>
|
||||
{{ end }}
|
||||
|
||||
|
|
Loading…
Reference in a new issue