-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
48 lines (40 loc) · 1.24 KB
/
background.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
39
40
41
42
43
44
45
46
47
48
// For later Firefox integration
var browser = chrome || browser;
console.log( "browser:", browser);
// Right click on page
function onContextCLick( info, tab ) {
browser.tabs.query({
"active": true,
"currentWindow": true
}, function (tabs) {
browser.tabs.sendMessage( tabs[0].id, {
"action": "readSelectedText",
"selectedText": info.selectionText
});
});
};
// Icon clicked in toolbar
function onIconClick( info, tab ) {
browser.tabs.query({
"active": true,
"currentWindow": true
}, function (tabs) {
browser.tabs.sendMessage( tabs[0].id, {
// "action": "readFullPage"
"action": "openTickerText"
});
});
};
// Write this in an expandable way in case we want to move beyond selection
var contexts = ["selection"];
for (var i = 0; i < contexts.length; i++) {
var context = contexts[i];
var title = "Read Selected Text";
var id = browser.contextMenus.create({
"title": title,
"contexts": [context],
"onclick": onContextCLick
});
}
// Handle clicking on the toolbar icon
browser.browserAction.onClicked.addListener( function( tab ) { onIconClick(); });