-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
29 lines (27 loc) · 1014 Bytes
/
options.js
File metadata and controls
29 lines (27 loc) · 1014 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
document.addEventListener('DOMContentLoaded', () => {
const openRouterApiKeyInput = document.getElementById('openrouter-api-key');
const saveButton = document.getElementById('save-btn');
const statusDiv = document.getElementById('status');
// Load the saved API key when the options page opens
chrome.storage.sync.get(['openRouterApiKey'], (result) => {
if (result.openRouterApiKey) {
openRouterApiKeyInput.value = result.openRouterApiKey;
}
});
// Save the API key
saveButton.addEventListener('click', () => {
const openRouterApiKey = openRouterApiKeyInput.value;
if (openRouterApiKey) {
chrome.storage.sync.set({ openRouterApiKey: openRouterApiKey }, () => {
statusDiv.textContent = 'API key saved!';
statusDiv.style.color = 'green';
setTimeout(() => {
statusDiv.textContent = '';
}, 2000);
});
} else {
statusDiv.textContent = 'Please enter an API key.';
statusDiv.style.color = 'red';
}
});
});