-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
43 lines (39 loc) · 1.27 KB
/
options.js
File metadata and controls
43 lines (39 loc) · 1.27 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
function saveOptions() {
var model = document.getElementById("gpt-model").value;
chrome.storage.sync.set(
{
model: model,
},
function () {
var status = document.getElementById("status");
status.textContent = "Options saved.";
setTimeout(function () {
status.textContent = "";
}, 500);
}
);
}
const restoreOptions = () => {
chrome.storage.sync.get({ model: "gpt-4" }, (items) => {
document.getElementById("gpt-model").value = items.model;
});
};
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("OpenAIAPIKeyForm");
chrome.storage.sync.get("apiKey", function (data) {
document.getElementById("apiKey").value = data.apiKey || "";
});
form.addEventListener("submit", function (event) {
event.preventDefault();
const apiKey = document.getElementById("apiKey").value;
chrome.storage.sync.set({ openaiApiKey: apiKey }, function () {
var status = document.getElementById("status");
status.textContent = "Options saved.";
setTimeout(function () {
status.textContent = "";
}, 500);
});
});
});
document.addEventListener("DOMContentLoaded", restoreOptions);
document.getElementById("save").addEventListener("click", saveOptions);