forked from iSegaro/Gemini-Translate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
24 lines (22 loc) · 867 Bytes
/
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
document.addEventListener("DOMContentLoaded", () => {
// Fetch extension name and version from manifest.json
const manifest = chrome.runtime.getManifest();
document.getElementById(
"NameVersion"
).textContent = `${manifest.name} v${manifest.version}`;
// Retrieve the saved key (if it exists)
chrome.storage.sync.get("apiKey", (data) => {
if (data.apiKey) {
document.getElementById("apiKey").value = data.apiKey;
}
});
// Save the API key when the button is clicked
document.getElementById("saveApiKey").addEventListener("click", () => {
const apiKey = document.getElementById("apiKey").value.trim();
chrome.storage.sync.set({ apiKey }, () => {
const status = document.getElementById("status");
status.textContent = "API key saved.";
setTimeout(() => (status.textContent = ""), 2000);
});
});
});