-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
27 lines (25 loc) · 1.1 KB
/
Copy pathoptions.js
File metadata and controls
27 lines (25 loc) · 1.1 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
const apiKeyInput = document.getElementById('apiKey');
const saveButton = document.getElementById('save');
const status = document.getElementById('status');
const languageInput = document.getElementById('language');
const textToSpeechCheckbox = document.getElementById('textToSpeech');
chrome.storage.sync.get(['geminiApiKey', 'language', 'textToSpeech'], ({ geminiApiKey, language, textToSpeech }) => {
if (geminiApiKey) apiKeyInput.value = geminiApiKey;
if (language) languageInput.value = language;
textToSpeechCheckbox.checked = !!textToSpeech;
});
saveButton.addEventListener('click', () => {
const key = apiKeyInput.value.trim();
if (!key) {
status.textContent = 'Please enter an API key.';
status.className = 'error';
return;
}
let lang = languageInput.value.trim();
if (!lang) lang = 'English';
chrome.storage.sync.set({ geminiApiKey: key, language: lang, textToSpeech: textToSpeechCheckbox.checked }, () => {
status.textContent = 'Saved!';
status.className = 'saved';
setTimeout(() => status.textContent = '', 2000);
});
});