window.onload = function() { const storedName = localStorage.getItem('userName'); const path = window.location.pathname; 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; } const welcomeMsg = getWelcomeMessage(storedName); const iconType = getIconType(path); showToast(welcomeMsg, 'success', iconType); 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'); const path = window.location.pathname; setTimeout(() => { document.getElementById('namePrompt').style.display = 'none'; document.getElementById('overlay').style.display = 'none'; }, 300); } function getWelcomeMessage(name) { const path = window.location.pathname; if (path === '/g') { return `Have fun playing games, ${name}!`; } else if (path === '/a') { return `Enjoy our collection of apps, ${name}!`; } else { return `Welcome back, ${name}!`; } } function getIconType(path) { if (path === '/g') return 'game'; if (path === '/a') return 'apps'; return 'wave'; } function updateGreeting(name) { const { text, icon } = getGreeting(); const el = document.getElementById('greeting'); if (el) { if (text === 'Hope you enjoy Waves') { el.innerHTML = `${icon} ${text}, ${name} <3`; } else { 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: '', game: '', apps: '', }; 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 timeGreetings = []; const generalGreetings = [ { text: 'Welcome aboard', icon: '' }, { text: 'Let’s do something great', icon: '' }, { text: 'Hope you enjoy Waves', icon: '' }, { text: 'Time to explore', icon: '' }, { text: 'Let’s roll', icon: '' }, { text: 'Consider joining our Discord (discord.gg/ire)', icon: '' }, { text: 'The adventure continues', icon: '' } ]; if (hour >= 5 && hour < 12) { timeGreetings.push( { text: 'Good morning, sunshine', icon: '' }, { text: 'Here’s to a bright morning', icon: '' }, { text: 'Enjoy your morning', icon: '' }, { text: 'Your day starts here', icon: '' } ); } else if (hour < 17) { timeGreetings.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) { timeGreetings.push( { text: 'Good evening', icon: '' }, { text: 'Time to unwind', icon: '' }, { text: 'Evening’s here—relax', icon: '' }, { text: 'Breathe and recharge', icon: '' } ); } else { timeGreetings.push( { text: 'Good night', icon: '' }, { text: 'Rest well', icon: '' }, { text: 'Sweet dreams', icon: '' }, { text: 'See you tomorrow', icon: '' } ); } const useGeneral = Math.random() < 0.5; const pool = useGeneral ? generalGreetings : timeGreetings; return pool[Math.floor(Math.random() * pool.length)]; }