Spaces:
Running
Running
| // Main application script | |
| document.addEventListener('DOMContentLoaded', () => { | |
| console.log('ChatVite initialized'); | |
| // Initialize all feather icons | |
| const replaceFeatherIcons = () => { | |
| if (window.feather) { | |
| feather.replace(); | |
| } else { | |
| setTimeout(replaceFeatherIcons, 100); | |
| } | |
| }; | |
| replaceFeatherIcons(); | |
| // Handle authentication state | |
| const checkAuthState = () => { | |
| const currentUser = sessionStorage.getItem('currentUser'); | |
| if (currentUser && window.location.pathname.endsWith('index.html')) { | |
| window.location.href = 'chat.html'; | |
| } else if (!currentUser && !window.location.pathname.endsWith('index.html')) { | |
| window.location.href = 'index.html'; | |
| } | |
| }; | |
| checkAuthState(); | |
| // Handle logout | |
| document.addEventListener('click', (e) => { | |
| if (e.target.closest('[data-logout]')) { | |
| sessionStorage.removeItem('currentUser'); | |
| sessionStorage.removeItem('isAdmin'); | |
| window.location.href = 'index.html'; | |
| } | |
| }); | |
| }); | |