-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
56 lines (48 loc) · 1.66 KB
/
Copy pathpopup.js
File metadata and controls
56 lines (48 loc) · 1.66 KB
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
// Popup script for QuixAnswer settings
document.addEventListener('DOMContentLoaded', async () => {
const apiKeyInput = document.getElementById('apiKey');
const openerPositionSelect = document.getElementById('openerPosition');
const modelSelect = document.getElementById('model');
const saveBtn = document.getElementById('saveBtn');
const status = document.getElementById('status');
// Load saved API key
const result = await chrome.storage.local.get(['apiKey', 'openerPosition', 'model']);
if (result.apiKey) {
apiKeyInput.value = result.apiKey;
}
if (result.openerPosition) {
openerPositionSelect.value = result.openerPosition;
} else {
openerPositionSelect.value = 'middle';
}
modelSelect.value = result.model || 'llama-3.3-70b-versatile';
// Save settings
saveBtn.addEventListener('click', async () => {
const apiKey = apiKeyInput.value.trim();
const openerPosition = openerPositionSelect.value;
const model = modelSelect.value;
if (!apiKey) {
showStatus('Please enter an API key', 'error');
return;
}
if (!apiKey.startsWith('gsk_')) {
showStatus('Invalid Groq API key format (should start with gsk_)', 'error');
return;
}
try {
await chrome.storage.local.set({ apiKey, openerPosition, model });
showStatus('Settings saved successfully!', 'success');
} catch (error) {
showStatus('Error saving settings', 'error');
}
});
function showStatus(message, type) {
status.textContent = message;
status.className = `status ${type}`;
if (type === 'success') {
setTimeout(() => {
status.style.display = 'none';
}, 3000);
}
}
});