} update() { this.x += this.vx; this.y += this.vy; if (this.x < 0 || this.x > canvas.width) this.vx *= -1; if (this.y < 0 || this.y > canvas.height) this.vy *= -1; } draw() { ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2); ctx.fillStyle = 'rgba(100, 100, 100, 0.3)'; ctx.fill(); } } const particles = []; for (let i = 0; i < 100; i++) { particles.push(new Particle()); } function animate() { ctx.clearRect(0, 0, canvas.width, canvas.height); particles.forEach(particle => { particle.update(); particle.draw(); }); // Draw connections particles.forEach((p1, i) => { particles.slice(i + 1).forEach(p2 => { const dx = p1.x - p2.x; const dy = p1.y - p2.y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance < 150) { ctx.beginPath(); ctx.moveTo(p1.x, p1.y); ctx.lineTo(p2.x, p2.y); ctx.strokeStyle = `rgba(100, 100, 100, ${0.2 * (1 - distance / 150)})`; ctx.lineWidth = 0.5; ctx.stroke(); } }); }); requestAnimationFrame(animate); } animate(); // App logic const API_URL = 'http://187.124.37.137:8080/api'; let currentEmail = ''; let emails = []; let refreshInterval; async function login() { const email = document.getElementById('emailInput').value.trim(); const password = document.getElementById('passwordInput').value.trim(); if (!email || !password) { alert('Please enter email and password'); return; } try { const response = await fetch(`${API_URL}/login`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }) }); const data = await response.json(); if (response.ok && data.success) { currentEmail = email; document.getElementById('currentEmail').textContent = email; document.getElementById('loginView').classList.add('hidden'); document.getElementById('appView').classList.remove('hidden'); loadEmails(); refreshInterval = setInterval(loadEmails, 10000); } else { alert(data.error || 'Login failed'); } } catch (error) { console.error('Login error:', error); alert('Connection error. Please try again.'); } } async function register() { const email = document.getElementById('emailInput').value.trim(); const password = document.getElementById('passwordInput').value.trim(); if (!email || !password) { alert('Please enter email and password'); return; } if (password.length < 6) { alert('Password must be at least 6 characters'); return; } try { const response = await fetch(`${API_URL}/register`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }) }); const data = await response.json(); if (response.ok && data.success) { alert('Account created! You can now sign in.'); } else { alert(data.error || 'Registration failed'); } } catch (error) { console.error('Register error:', error); alert('Connection error. Please try again.'); } } function logout() { clearInterval(refreshInterval); currentEmail = ''; document.getElementById('emailInput').value = ''; document.getElementById('appView').classList.add('hidden'); document.getElementById('loginView').classList.remove('hidden'); } function backToList() { document.getElementById('detailView').classList.add('hidden'); document.getElementById('listView').classList.remove('hidden'); } async function loadEmails() { const username = currentEmail.split('@')[0]; const domain = currentEmail.split('@')[1] || 'azurehub.store'; try { const response = await fetch(`${API_URL}/emails/${username}?domain=${domain}`); const data = await response.json(); emails = data.messages || []; displayEmails(); } catch (error) { console.error('Error loading emails:', error); } } function displayEmails() { const container = document.getElementById('emailList'); if (emails.length === 0) { container.innerHTML = `
No messages
New emails will appear here
`; return; } container.innerHTML = emails.map(email => `
${escapeHtml(email.subject || 'No subject')}
`).join(''); } async function viewEmail(id) { try { const response = await fetch(`${API_URL}/email/${id}`); const email = await response.json(); document.getElementById('emailDetail').innerHTML = `
${escapeHtml(email.subject || 'No subject')}
From: ${escapeHtml(email.sender)}
To: ${escapeHtml(email.recipient)}
Date: ${email.date}
${escapeHtml(email.body)}
`; document.getElementById('listView').classList.add('hidden'); document.getElementById('detailView').classList.remove('hidden'); } catch (error) { console.error('Error:', error); } } function formatDate(dateStr) { const date = new Date(dateStr); const now = new Date(); const diff = now - date; const hours = Math.floor(diff / 3600000); if (hours < 1) return 'Just now'; if (hours < 24) return `${hours}h ago`; return date.toLocaleDateString(); } function escapeHtml(text) { const div = document.createElement('div'); div.textContent = text; return div.innerHTML; }