Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const mobileMenu = document.querySelector('.mobile-menu');
+ const navLinks = document.querySelector('.nav-links');
+ const providerSelect = document.getElementById('provider');
+ const customEndpoint = document.querySelector('.custom-endpoint');
+ const aiSettings = document.getElementById('ai-settings');
+ const sendBtn = document.getElementById('send-btn');
+ const userInput = document.getElementById('user-input');
+ const messages = document.querySelector('.messages');
+
+ // Mobile menu toggle
+ mobileMenu.addEventListener('click', () => {
+ navLinks.classList.toggle('active');
+ });
+
+ // Show/hide custom endpoint based on provider selection
+ providerSelect.addEventListener('change', (e) => {
+ if (e.target.value === 'custom') {
+ customEndpoint.classList.remove('hidden');
+ } else {
+ customEndpoint.classList.add('hidden');
+ }
+ });
+
+ // Save AI settings
+ aiSettings.addEventListener('submit', (e) => {
+ e.preventDefault();
+ const formData = {
+ provider: providerSelect.value,
+ apiKey: document.getElementById('api-key').value,
+ endpoint: document.getElementById('endpoint').value
+ };
+ localStorage.setItem('aiSettings', JSON.stringify(formData));
+ alert('Settings saved successfully!');
+ });
+
+ // Load saved settings
+ const loadSettings = () => {
+ const saved = localStorage.getItem('aiSettings');
+ if (saved) {
+ const settings = JSON.parse(saved);
+ providerSelect.value = settings.provider;
+ document.getElementById('api-key').value = settings.apiKey;
+ document.getElementById('endpoint').value = settings.endpoint;
+ if (settings.provider === 'custom') {
+ customEndpoint.classList.remove('hidden');
+ }
+ }
+ };
+ loadSettings();
+
+ // Handle chat message sending
+ sendBtn.addEventListener('click', async () => {
+ const message = userInput.value.trim();
+ if (!message) return;
+
+ // Add user message to chat
+ const userMsg = document.createElement('div');
+ userMsg.className = 'message user-message';
+ userMsg.textContent = message;
+ messages.appendChild(userMsg);
+
+ // Clear input
+ userInput.value = '';
+
+ // Simulate AI response (replace with actual API call)
+ const aiMsg = document.createElement('div');
+ aiMsg.className = 'message ai-message';
+ aiMsg.textContent = 'This is a simulated AI response. Implement actual API calls using the saved settings.';
+ setTimeout(() => messages.appendChild(aiMsg), 1000);
+ });
+
+ // Allow sending message with Enter key
+ userInput.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter' && !e.shiftKey) {
+ e.preventDefault();
+ sendBtn.click();
+ }
+ });
+ });