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');
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';
}
const generalGreetings = [
{ text: 'Welcome aboard', icon: '', suffix: '!' },
{ text: 'Hii', icon: '', suffix: '!!' },
{ text: 'Hope you enjoy Waves', icon: '', suffix: ' <3' },
{ text: 'Consider joining our Discord (discord.gg/ire)', icon: '', suffix: '!' },
{ text: 'How you doing today', icon: '', suffix: '?' }
];
const timeGreetings = [];
timeGreetings.push(
{ text: 'Good morning, sunshine', icon: '', suffix: ' :D' },
{ text: 'Here’s to a bright morning', icon: '', suffix: '.' },
{ text: 'Enjoy your morning', icon: '', suffix: '!' },
{ text: 'Your day starts here', icon: '', suffix: ' !' }
);
timeGreetings.push(
{ text: 'Good afternoon', icon: '', suffix: '!' },
{ text: 'Hope your day is going well', icon: '', suffix: '.' },
{ text: 'Keep up the pace', icon: '', suffix: '!' },
{ text: 'Stay on track today', icon: '', suffix: '.' }
);
timeGreetings.push(
{ text: 'Good evening', icon: '', suffix: '!' },
{ text: 'Time to unwind', icon: '', suffix: '.' },
{ text: 'Evening’s here—relax', icon: '', suffix: '.' },
{ text: 'Breathe and recharge', icon: '', suffix: '…' }
);
timeGreetings.push(
{ text: 'Good night', icon: '', suffix: '!' },
{ text: 'Rest well', icon: '', suffix: '.' },
{ text: 'Sweet dreams', icon: '', suffix: '!' },
{ text: 'See you tomorrow', icon: '', suffix: '!' }
);
function getGreeting() {
const now = new Date();
const hour = now.getHours();
let pool = [];
if (hour >= 5 && hour < 12) {
pool = timeGreetings.slice(0, 4);
} else if (hour < 17) {
pool = timeGreetings.slice(4, 8);
} else if (hour < 21) {
pool = timeGreetings.slice(8, 12);
} else {
pool = timeGreetings.slice(12, 16);
}
if (Math.random() < 0.5) {
pool = generalGreetings;
}
const choice = pool[Math.floor(Math.random() * pool.length)];
return { text: choice.text, icon: choice.icon, suffix: choice.suffix };
}
function updateGreeting(name) {
const { text, icon, suffix } = getGreeting();
const el = document.getElementById('greeting');
if (!el) return;
if (text === 'Hope you enjoy Waves') {
el.innerHTML = `${icon} ${text}, ${name}${suffix}`;
} else {
el.innerHTML = `${icon} ${text}, ${name}${suffix}`;
}
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);
}