Spaces:
Running
Running
Download script.js from raysite/deepsite-companion: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/spaces/raysite/deepsite-companion/resolve/main/script.js
- Command line
-
hf download hf://spaces/raysite/deepsite-companion/script.js
-
curl -L -o script.js https://huggingface.co/spaces/raysite/deepsite-companion/resolve/main/script.js
3.56 kB
| // 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' | |
| }); | |
| }); | |
| }); |