-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
36 lines (33 loc) · 1.21 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
const saveOptions = () => {
const apiKey = document.getElementById('apiKey').value;
const promptQuestion = document.getElementById('promptQuestion').value;
const maxLength = document.getElementById('maxLength').value;
const status = document.getElementById('status');
chrome.storage.sync.set({
apiKey: apiKey,
promptQuestion: promptQuestion,
maxLength: maxLength,
}, function () {
status.innerHTML = 'Options saved.';
status.classList.remove('d-none');
setTimeout(function () {
status.innerHTML = '';
status.classList.add('d-none');
}, 2000);
});
}
const restoreOptions = () => {
chrome.storage.sync.get({
apiKey: '',
promptQuestion: 'Summarize the following text',
maxLength: 5000,
}, function (items) {
document.getElementById('apiKey').value = items.apiKey;
document.getElementById('promptQuestion').value = items.promptQuestion;
document.getElementById('maxLength').value = items.maxLength;
});
}
document.addEventListener('DOMContentLoaded', function () {
restoreOptions();
document.getElementById('save').addEventListener('click', saveOptions);
});