-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
43 lines (36 loc) · 1.46 KB
/
options.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
31
32
33
34
35
36
37
38
39
40
41
42
43
document.addEventListener("DOMContentLoaded", function () {
const apiKeyInput = document.getElementById("api-key");
const saveButton = document.getElementById("save-key");
const statusDiv = document.getElementById("status");
// Load API key from storage
chrome.storage.sync.get(['geminiApiKey'], function(result) {
if (result.geminiApiKey) {
apiKeyInput.value = result.geminiApiKey;
}
});
// Save API key when button is clicked
saveButton.addEventListener("click", function() {
const key = apiKeyInput.value.trim();
if (!key) {
showStatus("Please enter a valid API key", true);
return;
}
chrome.storage.sync.set({ geminiApiKey: key }, function() {
showStatus("API key saved successfully!", false);
// Verify the key was saved
chrome.storage.sync.get(['geminiApiKey'], function(result) {
console.log("API key saved:", result.geminiApiKey ? "Yes" : "No");
});
});
});
// Helper function to show status messages
function showStatus(message, isError) {
statusDiv.textContent = message;
statusDiv.className = isError ? "status error" : "status saved";
// Clear the message after 3 seconds
setTimeout(() => {
statusDiv.textContent = "";
statusDiv.className = "status";
}, 3000);
}
});