-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
42 lines (36 loc) · 1.51 KB
/
options.js
File metadata and controls
42 lines (36 loc) · 1.51 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
// 保存処理
function saveApiKey() {
const apiKey = document.getElementById('apiKey').value;
// (補足) もし音声読み上げが不要、または
// このコンテキストで動作しない場合は、
// 以下の3行をコメントアウトまたは削除しても構いません。
try {
const utterance = new SpeechSynthesisUtterance('保存しました');
utterance.lang = 'ja-JP';
speechSynthesis.speak(utterance);
} catch (e) {
console.warn("Speech synthesis failed in options UI:", e.message);
}
chrome.storage.local.set({ geminiApiKey: apiKey }, () => {
const status = document.getElementById('status');
status.textContent = '保存しました!';
setTimeout(() => {
status.textContent = '';
// "open_in_tab": false の場合、window.close() で
// オプションUIを閉じることができます。
window.close();
}, 2000);
});
}
// DOM読み込み完了後にイベントリスナーを登録
document.addEventListener('DOMContentLoaded', () => {
const saveButton = document.getElementById('save');
// clickイベントだけで十分(キーボード操作も自動処理される)
saveButton.addEventListener('click', saveApiKey);
// 読み込み処理
chrome.storage.local.get(['geminiApiKey'], (result) => {
if (result.geminiApiKey) {
document.getElementById('apiKey').value = result.geminiApiKey;
}
});
});