diff --git a/templates/index.html b/templates/index.html index 005cd91..11f144c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -21,51 +21,38 @@ </div> <div id="registration-closed" class="registration-closed" style="display: none;"> - Registration is currently closed + {{ message }} </div> <p class="info-text"> <span id="info-message">A registration token will be emailed to you.</span><br> - Token resets in: <span id="countdown" class="countdown">--:--:--</span> + <span id="countdown" class="countdown">--:--:--</span> </p> </div> <script> - function updateCountdown() { - const now = new Date(); - const tomorrow = new Date(); - tomorrow.setUTCHours(24, 0, 0, 0); - - // Registration closes 15 minutes before midnight UTC - const registrationCloseTime = new Date(tomorrow); - registrationCloseTime.setUTCMinutes(-15); - - const timeUntilReset = tomorrow - now; - const isRegistrationOpen = now < registrationCloseTime; - - // Update UI based on registration status - document.getElementById('registration-form').style.display = - isRegistrationOpen ? 'block' : 'none'; - document.getElementById('registration-closed').style.display = - isRegistrationOpen ? 'none' : 'block'; - - // Update info message based on status - const infoMessage = document.getElementById('info-message'); - infoMessage.textContent = isRegistrationOpen - ? 'A registration token will be emailed to you.' - : 'Please come back after the token resets.'; - - // Format time remaining - const hours = String(Math.floor(timeUntilReset / (1000 * 60 * 60))).padStart(2, '0'); - const minutes = String(Math.floor((timeUntilReset % (1000 * 60 * 60)) / (1000 * 60))).padStart(2, '0'); - const seconds = String(Math.floor((timeUntilReset % (1000 * 60)) / 1000)).padStart(2, '0'); - - document.getElementById('countdown').textContent = `${hours}:${minutes}:${seconds}`; + function updateStatus() { + fetch('/api/time') + .then(response => response.json()) + .then(data => { + const now = new Date(); + const registrationClosed = {{ registration_closed|tojson }}; + + document.getElementById('registration-form').style.display = + registrationClosed ? 'none' : 'block'; + document.getElementById('registration-closed').style.display = + registrationClosed ? 'block' : 'none'; + + const infoMessage = document.getElementById('info-message'); + infoMessage.textContent = registrationClosed + ? 'Please come back after the token resets.' + : 'A registration token will be emailed to you.'; + }); } // Update immediately and then every second - updateCountdown(); - setInterval(updateCountdown, 1000); + updateStatus(); + setInterval(updateStatus, 1000); </script> </body> </html> \ No newline at end of file