// Smooth scroll for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); document.addEventListener('DOMContentLoaded', function() { // Check for saved API key const savedApiKey = localStorage.getItem('deepseek_api_key'); if (!savedApiKey) { document.querySelector('custom-api-key-modal').setAttribute('open', 'true'); } // Handle send request button document.getElementById('send-request').addEventListener('click', async function() { const apiKey = localStorage.getItem('deepseek_api_key'); if (!apiKey) { document.querySelector('custom-api-key-modal').setAttribute('open', 'true'); return; } const requestBody = document.getElementById('request-body').value; const responsePlaceholder = document.getElementById('response-placeholder'); const responseContent = document.getElementById('response-content'); try { // Show loading state responsePlaceholder.innerHTML = `

Processing your request...

`; feather.replace(); responsePlaceholder.classList.remove('hidden'); responseContent.classList.add('hidden'); // Parse JSON to validate const jsonBody = JSON.parse(requestBody); // Make API call const response = await fetch('https://api.deepseek.com/v1/chat/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` }, body: requestBody }); const data = await response.json(); // Display response responseContent.textContent = JSON.stringify(data, null, 2); responsePlaceholder.classList.add('hidden'); responseContent.classList.remove('hidden'); } catch (error) { responsePlaceholder.innerHTML = `

Error: ${error.message}

`; feather.replace(); } }); }); // Theme toggle functionality function toggleDarkMode() { const html = document.documentElement; if (html.classList.contains('dark')) { html.classList.remove('dark'); localStorage.setItem('theme', 'light'); } else { html.classList.add('dark'); localStorage.setItem('theme', 'dark'); } }