-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
40 lines (38 loc) · 1.33 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
browser.contextMenus.create({
id: "log-selection",
title: "Search Wikipedia",
contexts: ["selection"]
});
browser.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId == "log-selection") {
var selectedText = info.selectionText;
browser.storage.local.get({
"language": "en",
"tabBehaviour": "new",
"tabActive": "yes"
},
function(item) {
var language = item.language;
var tabBehaviour = item.tabBehaviour;
var tabActive = item.tabActive;
https://nl.wikipedia.org/wiki/wiki.html?search=
var url = "https://" + language + ".wikipedia.org/wiki/wiki.html?search=" + encodeURIComponent(selectedText);
if (tabBehaviour == "new") {
if (tabActive == "no") {
chrome.tabs.create({
url: url,
active: false
});
} else {
chrome.tabs.create({
url: url
});
}
} else {
chrome.tabs.update({
url: url
});
}
});
};
});