-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
26 lines (23 loc) · 955 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
console.log('popup.js loaded');
document.getElementById('translateBtn').addEventListener('click', () => {
const sourceLang = document.getElementById('sourceLang').value;
const targetLang = document.getElementById('targetLang').value;
const source = document.getElementById('source').value;
const text = document.getElementById('textToTranslate').value; // Add this line to get the text to translate
console.log('Sending message from popup:', { sourceLang, targetLang, source, text });
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
action: 'translate',
text: text,
sourceLang: sourceLang,
targetLang: targetLang,
source: source
}, response => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
} else {
console.log('Translation response:', response);
}
});
});
});