-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
44 lines (41 loc) · 1.37 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
// 保存選項到 chrome.storage
function saveOptions() {
const apiKey = document.getElementById('apiKey').value;
const aiModel = document.getElementById('aiModel').value;
const targetLanguage = document.getElementById('targetLanguage').value;
const enableExtension = document.getElementById('enableExtension').checked;
chrome.storage.sync.set(
{
apiKey: apiKey,
aiModel: aiModel,
targetLanguage: targetLanguage,
enableExtension: enableExtension
},
function() {
const status = document.getElementById('status');
status.textContent = '選項已保存。';
setTimeout(function() {
status.textContent = '';
}, 2000);
}
);
}
// 當頁面加載時,使用預設值恢復選項狀態
function restoreOptions() {
chrome.storage.sync.get(
{
apiKey: '',
aiModel: 'gpt-4o-mini',
targetLanguage: 'zh-TW',
enableExtension: true
},
function(items) {
document.getElementById('apiKey').value = items.apiKey;
document.getElementById('targetLanguage').value = items.targetLanguage;
document.getElementById('aiModel').value = items.aiModel;
document.getElementById('enableExtension').checked = items.enableExtension;
}
);
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);