window.onload = function() { const storedName = localStorage.getItem('userName'); if (!storedName) { document.getElementById('overlay').style.display = 'block'; document.getElementById('namePrompt').style.display = 'block'; const nameInput = document.getElementById('userName'); const doneButton = document.getElementById('doneButton'); doneButton.disabled = true; nameInput.addEventListener('input', () => { doneButton.disabled = nameInput.value.trim() === ''; }); return; } showToast(`Hey, ${storedName}! Welcome back to Waves!`, 'success', 'wave'); const greetingElement = document.getElementById('greeting'); if (greetingElement) { updateGreeting(storedName); } }; function submitName() { const name = document.getElementById('userName').value.trim(); if (!name) return; localStorage.setItem('userName', name); updateGreeting(name); document.getElementById('namePrompt').classList.add('fade-out'); showToast(`Hey, ${name}! Welcome to Waves!`, 'success', 'wave'); setTimeout(() => { document.getElementById('namePrompt').style.display = 'none'; document.getElementById('overlay').style.display = 'none'; }, 300); } function updateGreeting(name) { const { text, icon } = getGreeting(); const el = document.getElementById('greeting'); if (el) { el.innerHTML = `${icon} ${text}, ${name}!`; el.style.opacity = 1; } } function showToast(message, type = 'success', iconType = 'wave') { const toast = document.createElement('div'); toast.className = `toast show ${type}`; const icons = { success: '', error: '', info: '', warning: '', wave: '' }; toast.innerHTML = `${icons[iconType] || icons.wave}${message} `; const progressBar = document.createElement('div'); progressBar.className = 'progress-bar'; toast.appendChild(progressBar); const closeBtn = document.createElement('button'); closeBtn.className = 'toast-close'; closeBtn.innerHTML = ''; closeBtn.addEventListener('click', () => { toast.classList.add('hide'); setTimeout(() => toast.remove(), 500); }); toast.appendChild(closeBtn); document.body.appendChild(toast); setTimeout(() => { toast.classList.add('hide'); setTimeout(() => toast.remove(), 500); }, 3000); } function getGreeting() { const now = new Date(); const hour = now.getHours(); const day = now.getDay(); const options = []; if (hour >= 5 && hour < 12) { options.push( { text: 'Good morning, sunshine', icon: '' }, { text: 'Here’s to a bright morning', icon: '' }, { text: 'Morning vibes only', icon: '' }, { text: 'Your day starts here', icon: '' } ); } else if (hour < 17) { options.push( { text: 'Good afternoon', icon: '' }, { text: 'Hope your day is going well', icon: '' }, { text: 'Keep up the pace', icon: '' }, { text: 'Stay on track today', icon: '' } ); } else if (hour < 21) { options.push( { text: 'Good evening', icon: '' }, { text: 'Time to unwind', icon: '' }, { text: 'Evening’s here—relax', icon: '' }, { text: 'Breathe and recharge', icon: '' } ); } else { options.push( { text: 'Good night', icon: '' }, { text: 'Rest well', icon: '' }, { text: 'Sweet dreams', icon: '' }, { text: 'See you tomorrow', icon: '' } ); } if (day === 4) { options.push( { text: 'Thursday mode: engaged', icon: '' }, { text: 'Almost Friday', icon: '' }, { text: 'Keep going', icon: '' } ); } if (day === 0 || day === 6) { options.push( { text: 'Happy weekend', icon: '' }, { text: 'Enjoy some downtime', icon: '' } ); } else { options.push( { text: 'You’ve got this', icon: '' }, { text: 'One step at a time', icon: '' }, { text: 'Summer is coming', icon: '' } ); } return options[Math.floor(Math.random() * options.length)]; }