-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
100 lines (84 loc) · 3.09 KB
/
popup.js
File metadata and controls
100 lines (84 loc) · 3.09 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
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
// Popup script for configuration
document.addEventListener('DOMContentLoaded', async () => {
const simpleModelSelect = document.getElementById('simpleModel');
const codingModelSelect = document.getElementById('codingModel');
const openRouterApiKeyInput = document.getElementById('openRouterApiKey');
const apiKeyInput = document.getElementById('apiKey');
const saveBtn = document.getElementById('saveBtn');
const statusDiv = document.getElementById('status');
// Load saved settings
const settings = await chrome.storage.sync.get([
'simpleModel',
'codingModel',
'openRouterApiKey',
'apiKey',
'aiProvider' // For backward compatibility
]);
if (settings.simpleModel) {
simpleModelSelect.value = settings.simpleModel;
} else if (settings.aiProvider) {
// Migrate old settings
simpleModelSelect.value = settings.aiProvider;
}
if (settings.codingModel) {
codingModelSelect.value = settings.codingModel;
}
if (settings.openRouterApiKey) {
openRouterApiKeyInput.value = settings.openRouterApiKey;
}
if (settings.apiKey) {
apiKeyInput.value = settings.apiKey;
}
// Save settings
saveBtn.addEventListener('click', async () => {
const simpleModel = simpleModelSelect.value;
const codingModel = codingModelSelect.value;
const openRouterApiKey = openRouterApiKeyInput.value.trim();
const apiKey = apiKeyInput.value.trim();
// Validation
if (!simpleModel && !codingModel) {
showStatus('Please select at least one model', 'error');
return;
}
// Check if OpenRouter models are selected but no OpenRouter API key
const openRouterModels = [
'DeepSeek', 'GPT-5 Pro', 'Claude Sonnet 4.5', 'Qwen3 Coder Plus',
'GLM', 'Grok 4 Fast', 'GPT-5 Codex', 'Qwen3 Coder Flash'
];
const needsOpenRouterKey = openRouterModels.includes(simpleModel) ||
openRouterModels.includes(codingModel);
if (needsOpenRouterKey && !openRouterApiKey) {
showStatus('OpenRouter API key required for selected models', 'error');
return;
}
// Check if legacy providers are selected but no legacy API key
const needsLegacyKey = simpleModel === 'groq' || simpleModel === 'gemini' ||
codingModel === 'groq' || codingModel === 'gemini';
if (needsLegacyKey && !apiKey) {
showStatus('API key required for Groq/Gemini', 'error');
return;
}
try {
await chrome.storage.sync.set({
simpleModel: simpleModel,
codingModel: codingModel,
openRouterApiKey: openRouterApiKey,
apiKey: apiKey,
aiProvider: simpleModel // For backward compatibility
});
showStatus('Settings saved successfully!', 'success');
} catch (error) {
showStatus('Error saving settings: ' + error.message, 'error');
}
});
function showStatus(message, type) {
statusDiv.textContent = message;
statusDiv.className = 'status ' + type;
statusDiv.style.display = 'block';
if (type === 'success') {
setTimeout(() => {
statusDiv.style.display = 'none';
}, 3000);
}
}
});