Commit 02d2f40a8e5936c67b0c64a17b1f1a089e10d67f
1 parent
a0e7e624
Exists in
master
Sends the selected text to popup script
Showing
2 changed files
with
28 additions
and
8 deletions
Show diff stats
app/main.js
1 | 1 | document.addEventListener("DOMContentLoaded", function(event) { |
2 | - var $player = document.getElementById('canvas'); | |
2 | + var $player = document.getElementById('canvas'); | |
3 | 3 | |
4 | - $player.width = window.innerWidth; | |
5 | - $player.height = window.innerHeight; | |
6 | -}); | |
7 | 4 | \ No newline at end of file |
5 | + if ( $player ) { | |
6 | + $player.width = window.innerWidth; | |
7 | + $player.height = window.innerHeight; | |
8 | + } | |
9 | + | |
10 | +}); | |
11 | + | |
12 | +chrome.runtime.onMessage.addListener( | |
13 | + function(request, sender, sendResponse) { | |
14 | + console.log(request.selectedText); | |
15 | + }); | ... | ... |
background.js
1 | 1 | var popup = undefined; |
2 | +var port = undefined; | |
2 | 3 | |
4 | +// Creates the context menu to translate texts | |
3 | 5 | chrome.contextMenus.create({ |
4 | 6 | id: 'translate_contextmenu', |
5 | 7 | title: 'Traduzir \'%s\' para LIBRAS', |
... | ... | @@ -8,24 +10,34 @@ chrome.contextMenus.create({ |
8 | 10 | if ( chrome.runtime.lastError ) console.log(chrome.runtime.lastError.message); |
9 | 11 | }); |
10 | 12 | |
11 | -chrome.contextMenus.onClicked.addListener( function () { | |
12 | - console.log(popup); | |
13 | +// Listening the event click | |
14 | +chrome.contextMenus.onClicked.addListener( function (info) { | |
15 | + // Creates the window if it exists | |
13 | 16 | if ( popup === undefined ) { |
14 | 17 | chrome.windows.create({ |
15 | 18 | url: "app/window.html", |
16 | 19 | top: 10, |
17 | 20 | left: 10, |
21 | + width: 600, | |
22 | + height: 600, | |
18 | 23 | type: "popup" |
19 | 24 | }, function (w) { |
20 | 25 | popup = w; |
26 | + | |
27 | + chrome.runtime.sendMessage({selectedText: info.selectionText}); | |
21 | 28 | }); |
22 | 29 | } else { |
23 | - chrome.windows.update(popup.id, {focused: true}); | |
30 | + chrome.windows.update(popup.id, {focused: true}, function () { | |
31 | + chrome.runtime.sendMessage({selectedText: info.selectionText}); | |
32 | + }); | |
24 | 33 | } |
25 | 34 | }); |
26 | 35 | |
36 | +// Frees variable if the popup doesn't to exist anymore | |
27 | 37 | chrome.windows.onRemoved.addListener( function (windowId) { |
28 | 38 | if (windowId == popup.id) { |
29 | 39 | popup = undefined; |
30 | 40 | } |
31 | -}); | |
32 | 41 | \ No newline at end of file |
42 | +}); | |
43 | + | |
44 | +chrome.runtime.sendMe | |
33 | 45 | \ No newline at end of file | ... | ... |