-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent-script.js
38 lines (35 loc) · 1.01 KB
/
content-script.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
function appendPopup(message) {
// TODO: Work with popup
var d = document.createElement("div");
d.innerText = message;
document.body.appendChild(d);
}
document.addEventListener('mouseup', function(event) {
var sel = window.getSelection().toString();
if (sel.length) {
chrome.runtime.sendMessage({
'code': 'find-for-content',
'selected': sel,
'title': document.title,
'url': window.location.href
}, function(result) {
// Asynchronous result doesn't come directly
// appendPopup(result.species);
});
}
});
chrome.runtime.sendMessage({
'code': 'find-for-content',
'selected': window.getSelection().toString(),
'title': document.title,
'url': window.location.href
}, function(result) {
// Asynchronous result doesn't come directly
// appendPopup(result.species);
});
// Asynchronous result handler
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.type == 'result-for-content') {
appendPopup(request.species);
}
});