-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
32 lines (28 loc) · 962 Bytes
/
popup.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
document.addEventListener('DOMContentLoaded', () => {
const apiKeyInput = document.getElementById('apiKey');
const summarizeButton = document.getElementById('summarize');
// Load the API key from chrome.storage.local
chrome.storage.local.get(['geminiApiKey'], (result) => {
if (result.geminiApiKey) {
apiKeyInput.value = result.geminiApiKey;
}
});
// Save the API key when it changes
apiKeyInput.addEventListener('change', () => {
const apiKey = apiKeyInput.value.trim();
chrome.storage.local.set({ geminiApiKey: apiKey });
});
summarizeButton.addEventListener('click', () => {
const apiKey = apiKeyInput.value.trim();
if (!apiKey) {
alert('Please enter a valid Gemini API key.');
return;
}
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {
action: 'processStories',
apiKey: apiKey
});
});
});
});