-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
49 lines (47 loc) · 1.74 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
37
38
39
40
41
42
43
44
45
46
47
48
49
document.addEventListener('DOMContentLoaded', () => {
const promptFormat = document.getElementById('promptFormat');
const chatID = document.getElementById('chatID');
const saveButton = document.getElementById('save');
const currentPromptFormat = document.getElementById('currentPromptFormat');
const currentChatID = document.getElementById('currentChatID');
const focusExistingTab = document.getElementById('focusExistingTab');
// Load saved values
chrome.storage.local.get(['promptFormat', 'chatID', 'focusExistingTab'], (data) => {
if (data.promptFormat) {
promptFormat.value = data.promptFormat;
currentPromptFormat.innerText = data.promptFormat;
} else {
const defaultPromptFormat = 'Explain <prompt>'; // Default value
promptFormat.value = defaultPromptFormat;
currentPromptFormat.innerText = defaultPromptFormat;
}
if (data.chatID) {
chatID.value = data.chatID;
currentChatID.innerText = data.chatID;
}
if (data.focusExistingTab !== undefined) {
focusExistingTab.checked = data.focusExistingTab;
} else {
focusExistingTab.checked = false; // Default value
}
});
// Save the user's choice
saveButton.addEventListener('click', () => {
if (!promptFormat.value.includes('<prompt>')) {
alert('Please include <prompt> in your custom format.');
return;
}
chrome.storage.local.set(
{
promptFormat: promptFormat.value,
chatID: chatID.value,
focusExistingTab: focusExistingTab.checked
},
() => {
currentPromptFormat.innerText = promptFormat.value;
currentChatID.innerText = chatID.value;
alert('Settings saved');
}
);
});
});