File size: 25,716 Bytes
7a0ec44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e5cc99
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Local LLM Chat</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <style>
        :root {
            --primary: #6366f1;
            --primary-dark: #4f46e5;
            --bg: #0f172a;
            --text: #e2e8f0;
            --text-light: #94a3b8;
            --border: #1e293b;
        }

        .dark {
            --bg: #0f172a;
            --text: #e2e8f0;
            --text-light: #94a3b8;
            --border: #1e293b;
        }

        .light {
            --bg: #f9fafb;
            --text: #111827;
            --text-light: #6b7280;
            --border: #e5e7eb;
        }
        
        body {
            width: 400px;
            height: 600px;
            font-family: 'Inter', sans-serif;
            background-color: var(--bg);
            color: var(--text);
            transition: background-color 0.3s, color 0.3s;
        }
        
        .chat-container {
            height: calc(100% - 60px);
        }
        
        .message-user {
            background-color: var(--primary);
            color: white;
            border-radius: 12px 12px 0 12px;
        }
        
        .message-ai {
            background-color: #1e293b;
            border: 1px solid var(--border);
            border-radius: 12px 12px 12px 0;
        }

        .rounded-12px {
            border-radius: 12px !important;
        }

        .rounded-none {
            border-radius: 0 !important;
        }

        .rounded-full {
            border-radius: 9999px !important;
        }
        
        .typing-indicator span {
            display: inline-block;
            width: 8px;
            height: 8px;
            background-color: var(--primary);
            border-radius: 50%;
            margin: 0 2px;
            opacity: 0.4;
        }
        
        .typing-indicator span:nth-child(1) {
            animation: pulse 1s infinite;
        }
        
        .typing-indicator span:nth-child(2) {
            animation: pulse 1s infinite 0.2s;
        }
        
        .typing-indicator span:nth-child(3) {
            animation: pulse 1s infinite 0.4s;
        }
        
        @keyframes pulse {
            0%, 100% {
                opacity: 0.4;
                transform: scale(1);
            }
            50% {
                opacity: 1;
                transform: scale(1.2);
            }
        }
        
        .input-box {
            box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
            background-color: #1e293b;
        }

        .header-dark {
            background-color: #1e293b;
            border-color: #334155;
        }

        .modal-dark {
            background-color: #1e293b;
            color: #e2e8f0;
        }

        .modal-dark input,
        .modal-dark select {
            background-color: #334155;
            color: #e2e8f0;
            border-color: #475569;
        }

        .modal-dark .border-gray-200 {
            border-color: #334155;
        }
    </style>
</head>
<body class="flex flex-col">
    <header class="header-dark px-4 py-3 border-b border-gray-800 flex items-center justify-between sticky top-0 z-10">
        <div class="flex items-center space-x-2">
            <div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center">
                <i data-feather="cpu" class="text-indigo-500 w-4 h-4"></i>
            </div>
            <h1 class="font-semibold text-white">Local LLM</h1>
        </div>
        <div class="flex items-center space-x-2">
            <button id="settings-btn" class="p-1 rounded-full hover:bg-gray-700">
                <i data-feather="settings" class="w-5 h-5 text-white"></i>
            </button>
            <button id="clear-btn" class="p-1 rounded-full hover:bg-gray-700">
                <i data-feather="trash-2" class="w-5 h-5 text-white"></i>
            </button>
        </div>
    </header>

    <div class="chat-container overflow-y-auto flex-1 px-4 py-3 space-y-3" id="chat-messages">
        <div class="message-ai p-3 max-w-[80%]">
            <p class="text-sm">Hello! I'm your local AI assistant. How can I help you today?</p>
        </div>
    </div>

    <div class="input-box bg-white px-4 py-3 border-t border-gray-200 sticky bottom-0">
        <div class="flex items-center space-x-2">
            <input 
                type="text" 
                id="message-input" 
                placeholder="Type your message..." 
                class="flex-1 border border-gray-300 rounded-full px-4 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-sm bg-white text-gray-900"
                autocomplete="off"
            >
            <button id="send-btn" class="bg-indigo-500 hover:bg-indigo-600 text-white rounded-full p-2 transition-colors">
                <i data-feather="send" class="w-4 h-4"></i>
            </button>
        </div>
        <div class="flex items-center justify-between mt-2 text-xs text-gray-500">
            <div class="flex items-center space-x-2">
                <button id="model-selector" class="flex items-center space-x-1 hover:text-indigo-500">
                    <span>Ollama</span>
                    <i data-feather="chevron-down" class="w-3 h-3"></i>
                </button>
            </div>
            <div class="flex items-center space-x-2">
                <button id="api-settings" class="hover:text-indigo-500 flex items-center">
                    <i data-feather="link" class="w-3 h-3 mr-1"></i>
                    <span>API Settings</span>
                </button>
            </div>
        </div>
    </div>

    <!-- Settings Modal -->
    <div id="settings-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
        <div class="modal-dark bg-gray-900 rounded-lg w-full max-w-md mx-4">
            <div class="px-6 py-4 border-b border-gray-200 flex justify-between items-center">
                <h3 class="text-lg font-medium text-gray-900">Settings</h3>
                <button id="close-settings" class="text-gray-400 hover:text-gray-500">
                    <i data-feather="x" class="w-5 h-5"></i>
                </button>
            </div>
            <div class="px-6 py-4 space-y-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">AI Role</label>
                    <textarea id="ai-role" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-sm" placeholder="You are a helpful AI assistant..."></textarea>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Prompt Library</label>
                    <select id="prompt-library" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-sm">
                        <option value="">Select a prompt...</option>
                        <option value="creative">Creative Writer</option>
                        <option value="coder">Code Assistant</option>
                        <option value="analyst">Data Analyst</option>
                        <option value="tutor">Learning Tutor</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Ollama API URL</label>
                    <input type="text" id="api-url" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-sm" placeholder="http://localhost:11434">
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Default Model</label>
                    <select id="default-model" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-sm">
                        <option value="llama2">Llama 2</option>
                        <option value="mistral">Mistral</option>
                        <option value="gemma">Gemma</option>
                        <option value="phi">Phi</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Theme</label>
                    <select id="theme-selector" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-sm">
                        <option value="light">Light</option>
                        <option value="dark">Dark</option>
                        <option value="system">System</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Message Style</label>
                    <select id="message-style" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-sm">
                        <option value="rounded">Rounded</option>
                        <option value="square">Square</option>
                        <option value="bubble">Bubble</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Font Size</label>
                    <select id="font-size" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-sm">
                        <option value="small">Small</option>
                        <option value="medium">Medium</option>
                        <option value="large">Large</option>
                    </select>
                </div>
                <div class="flex items-center justify-between">
                    <label class="block text-sm font-medium text-gray-700 mb-1">Enable Markdown</label>
                    <label class="relative inline-flex items-center cursor-pointer">
                        <input type="checkbox" id="markdown-toggle" class="sr-only peer">
                        <div class="w-9 h-5 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-indigo-600"></div>
                    </label>
                </div>
                <div class="flex items-center justify-between">
                    <label class="block text-sm font-medium text-gray-700 mb-1">Enable Animations</label>
                    <label class="relative inline-flex items-center cursor-pointer">
                        <input type="checkbox" id="animations-toggle" class="sr-only peer">
                        <div class="w-9 h-5 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-indigo-600"></div>
                    </label>
                </div>
            </div>
            <div class="px-6 py-4 border-t border-gray-200 flex justify-end">
                <button id="save-settings" class="bg-indigo-500 hover:bg-indigo-600 text-white px-4 py-2 rounded-md text-sm font-medium">Save</button>
            </div>
        </div>
    </div>

    <script>
        feather.replace();
        
        // DOM Elements
        const messageInput = document.getElementById('message-input');
        const sendBtn = document.getElementById('send-btn');
        const chatMessages = document.getElementById('chat-messages');
        const settingsBtn = document.getElementById('settings-btn');
        const clearBtn = document.getElementById('clear-btn');
        const settingsModal = document.getElementById('settings-modal');
        const closeSettings = document.getElementById('close-settings');
        const saveSettings = document.getElementById('save-settings');
        const apiSettings = document.getElementById('api-settings');
        const modelSelector = document.getElementById('model-selector');
        
        // Apply dark theme by default
        document.documentElement.classList.add('dark');

        // Load settings from storage
        chrome.storage.sync.get([
            'apiUrl', 
            'defaultModel', 
            'theme',
            'messageStyle',
            'fontSize',
            'markdownEnabled',
            'animationsEnabled',
            'aiRole',
            'selectedPrompt'
        ], (result) => {
            if (result.apiUrl) document.getElementById('api-url').value = result.apiUrl;
            if (result.defaultModel) document.getElementById('default-model').value = result.defaultModel;
            if (result.theme) applyTheme(result.theme);
            if (result.messageStyle) document.getElementById('message-style').value = result.messageStyle;
            if (result.fontSize) document.getElementById('font-size').value = result.fontSize;
            if (result.markdownEnabled) document.getElementById('markdown-toggle').checked = result.markdownEnabled;
            if (result.animationsEnabled) document.getElementById('animations-toggle').checked = result.animationsEnabled;
            
            applyMessageStyle(result.messageStyle || 'rounded');
            applyFontSize(result.fontSize || 'medium');
        });
        
        // Event Listeners
        sendBtn.addEventListener('click', sendMessage);
        messageInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                sendMessage();
            }
        });
        
        settingsBtn.addEventListener('click', () => {
            settingsModal.classList.remove('hidden');
        });
        
        closeSettings.addEventListener('click', () => {
            settingsModal.classList.add('hidden');
        });
        
        saveSettings.addEventListener('click', () => {
            const apiUrl = document.getElementById('api-url').value;
            const defaultModel = document.getElementById('default-model').value;
            const theme = document.getElementById('theme-selector').value;
            const messageStyle = document.getElementById('message-style').value;
            const fontSize = document.getElementById('font-size').value;
            const markdownEnabled = document.getElementById('markdown-toggle').checked;
            const animationsEnabled = document.getElementById('animations-toggle').checked;
            const aiRole = document.getElementById('ai-role').value;
            const selectedPrompt = document.getElementById('prompt-library').value;
            
            chrome.storage.sync.set({ 
                apiUrl, 
                defaultModel, 
                theme,
                messageStyle,
                fontSize,
                markdownEnabled,
                animationsEnabled,
                aiRole,
                selectedPrompt
            }, () => {
                applyTheme(theme);
                applyMessageStyle(messageStyle);
                applyFontSize(fontSize);
                settingsModal.classList.add('hidden');
                showNotification('Settings saved successfully');
            });
        });
        
        clearBtn.addEventListener('click', () => {
            chatMessages.innerHTML = `
                <div class="message-ai p-3 max-w-[80%]">
                    <p class="text-sm">Hello! I'm your local AI assistant. How can I help you today?</p>
                </div>
            `;
        });
        
        apiSettings.addEventListener('click', () => {
            settingsModal.classList.remove('hidden');
        });
        
        // Functions
        function sendMessage() {
            const message = messageInput.value.trim();
            if (!message) return;
            
            // Get AI role and selected prompt
            chrome.storage.sync.get(['aiRole', 'selectedPrompt'], (result) => {
                let fullMessage = message;
                
                if (result.aiRole) {
                    fullMessage = `${result.aiRole}\n\n${message}`;
                }
                
                if (result.selectedPrompt) {
                    const prompts = {
                        'creative': 'You are a creative writer. Respond with imaginative and vivid descriptions.',
                        'coder': 'You are a coding assistant. Respond with clean, efficient code examples.',
                        'analyst': 'You are a data analyst. Respond with clear, structured analysis.',
                        'tutor': 'You are a learning tutor. Explain concepts clearly with examples.'
                    };
                    fullMessage = `${prompts[result.selectedPrompt]}\n\n${fullMessage}`;
                }
                
                // Add user message to chat
                addMessage(message, 'user');
                messageInput.value = '';
            
            // Show typing indicator
            const typingIndicator = document.createElement('div');
            typingIndicator.className = 'typing-indicator p-3 max-w-[80%]';
            typingIndicator.innerHTML = `
                <div class="flex space-x-1">
                    <span></span>
                    <span></span>
                    <span></span>
                </div>
            `;
            chatMessages.appendChild(typingIndicator);
            chatMessages.scrollTop = chatMessages.scrollHeight;
            
            // Get API settings
            chrome.storage.sync.get(['apiUrl', 'defaultModel'], async (result) => {
                const apiUrl = result.apiUrl || 'http://localhost:11434';
                const model = result.defaultModel || 'llama2';
                
                try {
                    // Call Ollama API
                    const response = await fetch(`${apiUrl}/api/generate`, {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json'
                        },
                        body: JSON.stringify({
                            model: model,
                            prompt: fullMessage,
                            stream: false
                        })
                    });
                    
                    if (!response.ok) {
                        throw new Error(`API request failed: ${response.status}`);
                    }
                    
                    const data = await response.json();
                    
                    // Remove typing indicator
                    chatMessages.removeChild(typingIndicator);
                    
                    // Add AI response to chat
                    addMessage(data.response, 'ai');
                } catch (error) {
                    console.error('Error:', error);
                    chatMessages.removeChild(typingIndicator);
                    addMessage(`Error: ${error.message}`, 'ai');
                }
            });
        }
        
        function addMessage(text, sender) {
            const messageDiv = document.createElement('div');
            messageDiv.className = `message-${sender} p-3 max-w-[80%] ${sender === 'user' ? 'ml-auto' : ''}`;
            
            // Check if markdown is enabled
            chrome.storage.sync.get(['markdownEnabled'], (result) => {
                if (result.markdownEnabled) {
                    // Simple markdown parsing (bold, italic, links)
                    text = text.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
                    text = text.replace(/\*(.*?)\*/g, '<em>$1</em>');
                    text = text.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2" class="text-indigo-400 hover:underline" target="_blank">$1</a>');
                }
                
                messageDiv.innerHTML = `<p class="text-sm">${text}</p>`;
                chatMessages.appendChild(messageDiv);
                
                // Check if animations are enabled
                chrome.storage.sync.get(['animationsEnabled'], (result) => {
                    if (result.animationsEnabled) {
                        messageDiv.style.opacity = '0';
                        messageDiv.style.transform = 'translateY(10px)';
                        messageDiv.style.transition = 'all 0.3s ease';
                        setTimeout(() => {
                            messageDiv.style.opacity = '1';
                            messageDiv.style.transform = 'translateY(0)';
                        }, 10);
                    }
                });
                
                chatMessages.scrollTop = chatMessages.scrollHeight;
            });
        }

        function applyMessageStyle(style) {
            const messages = document.querySelectorAll('.message-user, .message-ai');
            
            messages.forEach(msg => {
                msg.classList.remove('rounded-12px', 'rounded-none', 'rounded-full');
                
                switch(style) {
                    case 'rounded':
                        msg.classList.add('rounded-[12px]');
                        break;
                    case 'square':
                        msg.classList.add('rounded-none');
                        break;
                    case 'bubble':
                        msg.classList.add('rounded-full');
                        break;
                }
            });
        }

        function applyFontSize(size) {
            const messages = document.querySelectorAll('.message-user p, .message-ai p');
            
            messages.forEach(msg => {
                msg.classList.remove('text-xs', 'text-sm', 'text-base');
                
                switch(size) {
                    case 'small':
                        msg.classList.add('text-xs');
                        break;
                    case 'medium':
                        msg.classList.add('text-sm');
                        break;
                    case 'large':
                        msg.classList.add('text-base');
                        break;
                }
            });
        }
        
        function applyTheme(theme) {
            if (theme === 'system') {
                theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
            }
            
            document.documentElement.classList.remove('light', 'dark');
            document.documentElement.classList.add(theme);
            
            // Update UI elements based on theme
            const header = document.querySelector('header');
            const modal = document.querySelector('#settings-modal > div');
            
            if (theme === 'dark') {
                header.classList.add('header-dark');
                header.classList.remove('bg-white');
                modal.classList.add('modal-dark');
                modal.classList.remove('bg-white');
            } else {
                header.classList.remove('header-dark');
                header.classList.add('bg-white');
                modal.classList.remove('modal-dark');
                modal.classList.add('bg-white');
            }
        }

        function showNotification(message) {
            const notification = document.createElement('div');
            notification.className = 'fixed bottom-4 right-4 bg-green-600 text-white px-4 py-2 rounded-md text-sm shadow-lg';
            notification.textContent = message;
            document.body.appendChild(notification);
            
            setTimeout(() => {
                notification.classList.add('opacity-0', 'transition-opacity', 'duration-300');
                setTimeout(() => {
                    document.body.removeChild(notification);
                }, 300);
            }, 3000);
        }

        // Load prompt library and AI role
        document.getElementById('prompt-library').addEventListener('change', function() {
            if (this.value) {
                document.getElementById('ai-role').value = '';
            }
        });

        document.getElementById('ai-role').addEventListener('input', function() {
            if (this.value) {
                document.getElementById('prompt-library').value = '';
            }
        });

        // Load saved role and prompt
        chrome.storage.sync.get(['aiRole', 'selectedPrompt'], (result) => {
            if (result.aiRole) {
                document.getElementById('ai-role').value = result.aiRole;
            }
            if (result.selectedPrompt) {
                document.getElementById('prompt-library').value = result.selectedPrompt;
            }
        });
    </script>
</body>
</html>