Spaces:
Running
Running
File size: 3,564 Bytes
e486748 136c60b 46a4236 136c60b 46a4236 e486748 136c60b e486748 | 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | // Theme toggle functionality
document.addEventListener('DOMContentLoaded', () => {
// Check for saved theme preference
if (localStorage.getItem('color-theme') === 'dark' || (!('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
// Initialize tooltips
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
});
// Voice command processing
document.addEventListener('voiceCommand', (e) => {
const command = e.detail.text.toLowerCase();
console.log('Voice command:', command);
// Basic command handling
if (command.includes('home') || command.includes('go home')) {
window.location.href = '/';
} else if (command.includes('about')) {
window.location.href = '/about';
} else if (command.includes('modes')) {
window.location.href = '/modes';
} else if (command.includes('chat')) {
window.location.href = '/chat';
} else if (command.includes('settings') || command.includes('preferences')) {
// Handle settings command
console.log('Settings command received');
}
// You can add more command handling here
});
// Chat functionality
document.addEventListener('DOMContentLoaded', () => {
const chatContainer = document.getElementById('chat-container');
const messageInput = document.getElementById('message-input');
const sendButton = document.getElementById('send-button');
if (sendButton && messageInput) {
const sendMessage = () => {
const message = messageInput.value.trim();
if (message) {
// Add user message
const userBubble = document.createElement('chat-bubble');
userBubble.setAttribute('type', 'sent');
userBubble.textContent = message;
chatContainer.appendChild(userBubble);
// Clear input
messageInput.value = '';
// Simulate MJ response after delay
setTimeout(() => {
const mjBubble = document.createElement('chat-bubble');
mjBubble.setAttribute('type', 'received');
mjBubble.textContent = getMJResponse(message);
chatContainer.appendChild(mjBubble);
chatContainer.scrollTop = chatContainer.scrollHeight;
}, 1000);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
};
sendButton.addEventListener('click', sendMessage);
messageInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') sendMessage();
});
}
});
function getMJResponse(message) {
const responses = [
"I understand what you're saying. Can you tell me more about that?",
"That's an interesting point. How does that make you feel?",
"I'd be happy to help with that. What specific aspect are you curious about?",
"Thanks for sharing that with me. What else is on your mind?",
"I'm here to listen. Would you like to explore this topic further?"
];
return responses[Math.floor(Math.random() * responses.length)];
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
}); |