Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const calculateButton = document.getElementById('calculate');
+ const averageTimeElement = document.getElementById('averageTime');
+ const waitTimeElement = document.getElementById('waitTime');
+ const expectedTimeElement = document.getElementById('expectedTime');
+
+ // Set default last update time to current time
+ const lastUpdateInput = document.getElementById('lastUpdate');
+ const now = new Date();
+ const formattedDateTime = now.toISOString().slice(0, 16);
+ lastUpdateInput.value = formattedDateTime;
+
+ calculateButton.addEventListener('click', calculateWaitTime);
+
+ function calculateWaitTime() {
+ const yourNumber = parseInt(document.getElementById('yourNumber').value);
+ const currentNumber = parseInt(document.getElementById('currentNumber').value);
+ const lastUpdate = new Date(document.getElementById('lastUpdate').value);
+
+ if (!yourNumber || !currentNumber || !lastUpdate) {
+ alert('Please fill in all fields');
+ return;
+ }
+
+ if (yourNumber < currentNumber) {
+ alert('Your number should be greater than or equal to the current number');
+ return;
+ }
+
+ const now = new Date();
+ const timeDifferenceMinutes = (now - lastUpdate) / (1000 * 60);
+ const numbersDifference = currentNumber - parseInt(localStorage.getItem('lastNumber') || currentNumber);
+
+ // Calculate average time per number
+ let averageTimePerNumber;
+ if (numbersDifference > 0) {
+ averageTimePerNumber = timeDifferenceMinutes / numbersDifference;
+ } else {
+ averageTimePerNumber = parseFloat(localStorage.getItem('averageTime')) || 5; // Default 5 minutes
+ }
+
+ // Store current values for future calculations
+ localStorage.setItem('lastNumber', currentNumber);
+ localStorage.setItem('averageTime', averageTimePerNumber);
+
+ // Calculate estimated wait time
+ const numbersAhead = yourNumber - currentNumber;
+ const estimatedWaitMinutes = numbersAhead * averageTimePerNumber;
+
+ // Calculate expected service time
+ const expectedTime = new Date(now.getTime() + estimatedWaitMinutes * 60000);
+
+ // Update display
+ averageTimeElement.textContent = `${averageTimePerNumber.toFixed(1)} minutes`;
+ waitTimeElement.textContent = `${Math.round(estimatedWaitMinutes)} minutes`;
+ expectedTimeElement.textContent = formatTime(expectedTime);
+
+ // Animate results
+ document.querySelectorAll('.result-card').forEach(card => {
+ card.style.animation = 'none';
+ card.offsetHeight; // Trigger reflow
+ card.style.animation = 'fadeIn 0.5s ease-out';
+ });
+ }
+
+ function formatTime(date) {
+ return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
+ }
+ });
+
+ // Add some CSS animations
+ const style = document.createElement('style');
+ style.textContent = `
+ @keyframes fadeIn {
+ from { opacity: 0; transform: translateY(10px); }
+ to { opacity: 1; transform: translateY(0); }
+ }
+ `;
+ document.head.appendChild(style);