-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
31 lines (26 loc) · 961 Bytes
/
options.js
File metadata and controls
31 lines (26 loc) · 961 Bytes
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
const browser = typeof chrome !== "undefined" ? chrome : undefined;
// Elements
const apiKeyInput = document.getElementById('apiKey');
const saveBtn = document.getElementById('saveBtn');
const statusText = document.getElementById('status');
// Load the saved API key when the options page is opened
document.addEventListener('DOMContentLoaded', () => {
browser.storage.local.get(['groqApiKey'], (result) => {
if (result.groqApiKey) {
apiKeyInput.value = result.groqApiKey;
}
});
});
// Save the API key when the button is clicked
saveBtn.addEventListener('click', () => {
const apiKey = apiKeyInput.value.trim();
browser.storage.local.set({ groqApiKey: apiKey }, () => {
// Show a success message
statusText.textContent = '✅ Settings saved successfully!';
statusText.style.color = '#34a853';
// Clear the message after 3 seconds
setTimeout(() => {
statusText.textContent = '';
}, 3000);
});
});