/
bootstrap.js
61 lines (55 loc) · 2.2 KB
/
bootstrap.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
var storageChange="Google.com";
function convertURL(url){
if(storageChange=="Google.com"){
return url.replace("www.bing.com/search", "www.google.com/search");
}
if(storageChange=="DuckDuckGo.com"){
return url.replace("www.bing.com/search", "www.duckduckgo.com");
}
if(storageChange=="Ask.com"){
return url.replace(/.*:\/\/www.bing.com\/search/, "http://www.ask.com/web");
}
if(storageChange=="Yahoo.com"){
return url.replace("www.bing.com/search?q", "search.yahoo.com/search?p");
}
if(storageChange=="Aol.com"){
return url.replace(/.*:\/\/www.bing.com\/search/, "http://search.aol.com/aol/search");
}
if(storageChange=="Wow.com"){
return url.replace(/.*:\/\/www.bing.com/, "http://us.wow.com");
}
return url.replace("www.bing.com/search", "www.google.com/search");
}
chrome.storage.sync.get('search_engine', function (obj) {
console.log('myKey', obj);
storageChange=obj['search_engine'];
});
chrome.storage.onChanged.addListener(function(changes, namespace) {
storageChange = changes['search_engine']['newValue'];
console.log(storageChange);
});
chrome.webRequest.onBeforeRequest.addListener(function(details) {
console.log(storageChange);
return { redirectUrl: convertURL(details.url)};
}, {urls: ["*://www.bing.com/search*"]}, ["blocking"]);
// Redirect to welcome.html on install
chrome.runtime.onInstalled.addListener(function(details){
if(details.reason == "install"){
chrome.tabs.create({url: "html/options.html?newinstall=yes"});
}else if(details.reason == "update"){
var thisVersion = chrome.runtime.getManifest().version;
console.log("Updated from " + details.previousVersion + " to " + thisVersion + "!");
}
});
// Call the above function when the url of a tab changes.
chrome.tabs.onUpdated.addListener(startUpRedirect);
// Show page action icon in omnibar.
function startUpRedirect( tabId, changeInfo, tab ) {
console.log(tab);
var pattern = /www.bing.com\/search+/gi;
if(tab['url'].match(pattern)){
chrome.tabs.getSelected(null, function(tab){
chrome.tabs.update(tab.id, {url: convertURL(tab.url)});
});
}
};