-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpopup.js
30 lines (28 loc) · 915 Bytes
/
popup.js
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
document.addEventListener('DOMContentLoaded', () => {
const saveButton = document.getElementById('saveApiKey');
const apiKeyInput = document.getElementById('apiKey');
const status = document.getElementById('status');
// Load the saved API key
chrome.storage.sync.get('apiKey', (data) => {
if (data.apiKey) {
apiKeyInput.value = data.apiKey;
}
});
// Save the API key when the button is clicked
saveButton.addEventListener('click', () => {
const apiKey = apiKeyInput.value.trim();
if (apiKey) {
chrome.storage.sync.set({ apiKey }, () => {
status.textContent = 'API Key saved!';
status.className = 'success';
setTimeout(() => {
status.textContent = '';
status.className = '';
}, 2000);
});
} else {
status.textContent = 'Please enter a valid API Key.';
status.className = 'error';
}
});
});