Spaces:
Running
Running
| document.addEventListener('DOMContentLoaded', () => { | |
| // Shared initialization logic | |
| console.log('WhisperLink app initialized'); | |
| // Animation trigger for elements with fade-in class | |
| const fadeElements = document.querySelectorAll('.fade-in'); | |
| fadeElements.forEach((el, index) => { | |
| el.style.animationDelay = `${index * 0.1}s`; | |
| }); | |
| // WebSocket connection for real-time updates | |
| const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; | |
| const socket = new WebSocket(protocol + window.location.host + '/ws'); | |
| socket.onmessage = (event) => { | |
| const data = JSON.parse(event.data); | |
| if (data.type === 'new_message') { | |
| showToast(`New message received in ${data.link}`); | |
| } | |
| }; | |
| function showToast(message) { | |
| const toast = document.createElement('div'); | |
| toast.className = 'fixed bottom-4 right-4 bg-indigo-600 text-white px-4 py-2 rounded-lg shadow-lg z-50 fade-in'; | |
| toast.textContent = message; | |
| document.body.appendChild(toast); | |
| setTimeout(() => { | |
| toast.classList.add('opacity-0', 'transition-opacity', 'duration-300'); | |
| setTimeout(() => toast.remove(), 300); | |
| }, 3000); | |
| } | |
| }); |