-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
61 lines (48 loc) · 1.32 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
49
50
51
52
53
54
55
56
57
58
59
60
61
browser.browserAction.onClicked.addListener(function (tab) {
//get current url
var tabUrl = tab.url;
//get the proxy link stored
browser.storage.local.get({
link: '',
}, function(items) {
//verify if the proxy link is set
if(items.link != ""){
//create a new url
var myNewUrl = items.link + tabUrl;
//Update the current url to the proxyed url
browser.tabs.update(tab.id, {url: myNewUrl});
}else{
//if not set, take the user to the error page
browser.tabs.create({
url : "errorPage.html",
active : true
});
}
});
});
openWithProxy = function(word){
var query = word.linkUrl;
//get the proxy link stored
browser.storage.local.get({
link: '',
}, function(items) {
//verify if the proxy link is set
if(items.link != ""){
//create a new url
var myNewUrl = items.link + query;
//create a new tab with the proxyed url
browser.tabs.create({url: myNewUrl});
}else{
//if not set, take the user to the error page
browser.tabs.create({
url : "errorPage.html",
active : true
});
}
});
};
browser.contextMenus.create({
title: "Proxy it for me!",
contexts:["link"], // ContextType
onclick: openWithProxy // A callback function
});