-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
37 lines (33 loc) · 1.05 KB
/
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
33
34
35
36
37
function update_selected(msg) {
document.getElementById("selected").innerHTML = msg;
}
function update_translated(msg) {
document.getElementById("translate").innerHTML = msg;
}
function GetValueofField(fieldName) {
return document.getElementById(fieldName).value;
}
document.addEventListener('DOMContentLoaded', function() {
var clickme = document.getElementById('search');
// onClick's logic below:
clickme.addEventListener("click", function(e) {
update_selected("Please enter word");
update_translated("...");
chrome.runtime.sendMessage({
code: 'find-from-popup',
selected: GetValueofField("selected")
}, function(result) {
// Asynchronous result doesn't come directly
// debugger;
// update_selected(result.name);
// update_translated(result.species);
});
});
});
// Asynchronous result handler
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.type == 'result-for-popup') {
update_selected(request.name);
update_translated(request.species);
}
});