-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
41 lines (30 loc) · 1.01 KB
/
background.js
File metadata and controls
41 lines (30 loc) · 1.01 KB
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
var menuItem = {
"id" : "genius",
"title": "genius",
"contexts":["selection"]
};
chrome.contextMenus.create(menuItem);
$(document).ajaxError(function(e, xhr, settings, exception) {
chrome.tabs.query({active : true,currentWindow : true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {todo: "404 Error"});
});
});
chrome.contextMenus.onClicked.addListener(function(clickedData){
if(clickedData.menuItemId == "genius" && clickedData.selectionText){
//chrome.tts.speak(clickedData.selectionText,{'rate':0.8});
chrome.storage.sync.get('lan', function(o){
var url = "https://googledictionaryapi.eu-gb.mybluemix.net/?define=";
url += escape(clickedData.selectionText);
if(o.lan){
url+="&lang="+o.lan;
}else{
url+= "&lang=en";
}
$.get(url, function (data, status) {
chrome.tabs.query({active : true,currentWindow : true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {todo: "display meaning", wordData:data});
});
});
});
}
});