-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
59 lines (53 loc) · 1.48 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
enabled = true;
/** GOOGLE **/
chrome.webRequest.onBeforeRequest.addListener(function(details) {
if (enabled && (details.url.indexOf("&tbs=li:1") == -1)) {
var url = details.url + "&tbs=li:1";
chrome.browserAction.setBadgeText({text: "OK"});
return {
redirectUrl: url
};
}
}, {
urls: [
"http://*/search?*",
"https://*/search?*"
],
types: ["main_frame"]
},
["blocking"]
);
/** DUCKDUCKGO **/
chrome.webRequest.onBeforeRequest.addListener(function(details) {
if ((details.url.indexOf("%2B") == -1) && enabled) {
var url = details.url.replace(/\+/g, "+%2B").replace(/\%20/g, "%20%2B").replace(/\/\?q\=/g, "/?q=%2B");
chrome.browserAction.setBadgeText({text: "OK"});
return {
redirectUrl: url
};
}
}, {
urls: [
"*://www.duckduckgo.com/?q=*",
"*://duckduckgo.com/?q=*"
],
types: ["main_frame"]
},
["blocking"]
);
/** Remove the browseraction badge text if the tab changes **/
chrome.tabs.onActivated.addListener(function(activeInfo) {
chrome.browserAction.setBadgeText({text: ""});
});
/** Allow the extension to be toggled at will **/
chrome.browserAction.onClicked.addListener(function() {
if (enabled) {
enabled = false;
chrome.browserAction.setIcon({path:"icons/sic-disabled.png"});
chrome.browserAction.setTitle({ "title": "Enable Search Verbatim (sic)"});
} else {
enabled = true;
chrome.browserAction.setIcon({path:"icons/sic-19.png"});
chrome.browserAction.setTitle({ "title": "Disable Search Verbatim (sic)"});
}
});