Update templates/index.html
This commit is contained in:
parent
c3e69417a6
commit
cee4dde978
1 changed files with 11 additions and 19 deletions
|
@ -26,44 +26,36 @@
|
|||
|
||||
<p class="info-text">
|
||||
<span id="info-message">A registration token will be emailed to you.</span><br>
|
||||
Token resets at: <span id="countdown" class="countdown">--:--:--</span> UTC
|
||||
Token resets in: <span id="countdown" class="countdown">--:--:--</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Configuration values provided by the server
|
||||
const TOKEN_RESET_HOUR = {{ token_reset_time_utc }}; // e.g., 0 for midnight UTC
|
||||
const DOWNTIME_MINUTES = {{ downtime_before_token_reset }}; // e.g., 30 minutes
|
||||
|
||||
function updateCountdown() {
|
||||
const now = new Date();
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setUTCHours(24, 0, 0, 0);
|
||||
|
||||
// Calculate next reset time
|
||||
const resetTime = new Date();
|
||||
resetTime.setUTCHours(TOKEN_RESET_HOUR, 0, 0, 0);
|
||||
if (now > resetTime) {
|
||||
resetTime.setDate(resetTime.getDate() + 1);
|
||||
}
|
||||
// Registration closes 15 minutes before midnight UTC
|
||||
const registrationCloseTime = new Date(tomorrow);
|
||||
registrationCloseTime.setUTCMinutes(-15);
|
||||
|
||||
// Calculate when registration should close
|
||||
const downtimeStart = new Date(resetTime);
|
||||
downtimeStart.setMinutes(downtimeStart.getMinutes() - DOWNTIME_MINUTES);
|
||||
const timeUntilReset = tomorrow - now;
|
||||
const isRegistrationOpen = now < registrationCloseTime;
|
||||
|
||||
// Update form visibility based on whether we're in downtime
|
||||
const isRegistrationOpen = now < downtimeStart;
|
||||
// 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 registration status
|
||||
// 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.';
|
||||
|
||||
// Always show countdown to reset time (not downtime)
|
||||
const timeUntilReset = resetTime - now;
|
||||
// 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');
|
||||
|
|
Loading…
Add table
Reference in a new issue