-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
63 lines (50 loc) · 1.72 KB
/
scripts.js
File metadata and controls
63 lines (50 loc) · 1.72 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const setupSection = document.getElementById("setup-section");
const editSection = document.getElementById("edit-section");
const apiKeyInput = document.getElementById("apiKeyInput");
const saveApiKeyButton = document.getElementById("saveApiKeyButton");
const editApiKeyInput = document.getElementById("editApiKeyInput");
const editApiKeyButton = document.getElementById("editApiKeyButton");
const saveEditApiKeyButton = document.getElementById("saveEditApiKeyButton");
function loadApiKey() {
chrome.storage.local.get("apiKey", (result) => {
const apiKey = result.apiKey;
if (apiKey) {
editApiKeyInput.value = apiKey;
setupSection.style.display = "none";
editSection.style.display = "block";
} else {
setupSection.style.display = "block";
editSection.style.display = "none";
}
});
}
saveApiKeyButton.addEventListener("click", () => {
const apiKey = apiKeyInput.value.trim();
if (!apiKey) {
alert("Please enter a valid API key.");
return;
}
chrome.storage.local.set({ apiKey }, () => {
alert("API key saved successfully!");
loadApiKey();
});
});
editApiKeyButton.addEventListener("click", () => {
editApiKeyInput.readOnly = false;
saveEditApiKeyButton.style.display = "block";
editApiKeyButton.style.display = "none";
});
saveEditApiKeyButton.addEventListener("click", () => {
const newApiKey = editApiKeyInput.value.trim();
if (!newApiKey) {
alert("Please enter a valid API key.");
return;
}
chrome.storage.local.set({ apiKey: newApiKey }, () => {
alert("API key updated successfully!");
editApiKeyInput.readOnly = true;
saveEditApiKeyButton.style.display = "none";
editApiKeyButton.style.display = "block";
});
});
loadApiKey();