Spaces:
Running
Running
File size: 2,458 Bytes
6f29905 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | // Initialize real-time features (simulated for demo)
document.addEventListener('DOMContentLoaded', () => {
// Simulate online status updates
setInterval(() => {
const statusIndicators = document.querySelectorAll('.status-indicator');
statusIndicators.forEach(indicator => {
// Randomly change some statuses for demo purposes
if (Math.random() > 0.8) {
indicator.classList.toggle('bg-green-500');
indicator.classList.toggle('bg-gray-500');
}
});
}, 5000);
// Handle chat functionality
const chatForm = document.querySelector('.chat-form');
if (chatForm) {
chatForm.addEventListener('submit', (e) => {
e.preventDefault();
const input = chatForm.querySelector('input');
if (input.value.trim()) {
// In a real app, this would send to a server
addMessageToChat('You', input.value, true);
input.value = '';
// Simulate reply after 1-3 seconds
setTimeout(() => {
const replies = [
"That's interesting! Tell me more.",
"I feel the same way!",
"What are you up to today?",
"Would you like to meet in the virtual world?",
"๐"
];
const randomReply = replies[Math.floor(Math.random() * replies.length)];
addMessageToChat('Virtual Friend', randomReply, false);
}, 1000 + Math.random() * 2000);
}
});
}
});
function addMessageToChat(sender, message, isUser) {
const chatMessages = document.querySelector('.chat-messages');
if (chatMessages) {
const messageDiv = document.createElement('div');
messageDiv.className = `flex ${isUser ? 'justify-end' : 'justify-start'} mb-3`;
messageDiv.innerHTML = `
<div class="${isUser ? 'bg-pink-600' : 'bg-indigo-700'} rounded-lg px-4 py-2 max-w-xs lg:max-w-md">
<div class="text-xs font-semibold ${isUser ? 'text-pink-200' : 'text-indigo-200'}">${sender}</div>
<div class="mt-1">${message}</div>
</div>
`;
chatMessages.appendChild(messageDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
} |