-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
44 lines (38 loc) · 1.19 KB
/
options.js
File metadata and controls
44 lines (38 loc) · 1.19 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
document.addEventListener("DOMContentLoaded", async () => {
const apiKeyInput = document.getElementById("apiKey");
const saveBtn = document.getElementById("saveBtn");
const clearBtn = document.getElementById("clearBtn");
const toast = document.getElementById("toast");
// Load existing key
const { apiKey } = await chrome.storage.sync.get("apiKey");
if (apiKey) {
apiKeyInput.value = apiKey;
}
function showToast(message, type) {
toast.textContent = message;
toast.className = "toast " + type;
setTimeout(() => {
toast.className = "toast";
}, 3000);
}
saveBtn.addEventListener("click", async () => {
const key = apiKeyInput.value.trim();
if (!key) {
showToast("Please enter an API key.", "error");
return;
}
await chrome.storage.sync.set({ apiKey: key });
showToast("API key saved successfully!", "success");
});
clearBtn.addEventListener("click", async () => {
apiKeyInput.value = "";
await chrome.storage.sync.remove("apiKey");
showToast("API key cleared.", "success");
});
// Save on Enter
apiKeyInput.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
saveBtn.click();
}
});
});