Permalink
Browse files

Fix if chrome is not allowed to run in the background

  • Loading branch information...
kyleladd committed Aug 2, 2015
1 parent df632a7 commit c18ae146c9ec9b330b28361d21f6b4ef2b1a47a9
Showing with 41 additions and 22 deletions.
  1. +39 −21 js/bootstrap.js
  2. +2 −1 manifest.json
View
@@ -1,35 +1,39 @@
var storageChange="Google.com"
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)
var storageChange="Google.com";
function convertURL(url){
if(storageChange=="Google.com"){
return { redirectUrl: details.url.replace("www.bing.com/search", "www.google.com/search")};
return url.replace("www.bing.com/search", "www.google.com/search");
}
if(storageChange=="DuckDuckGo.com"){
return { redirectUrl: details.url.replace("www.bing.com/search", "www.duckduckgo.com")};
return url.replace("www.bing.com/search", "www.duckduckgo.com");
}
if(storageChange=="Ask.com"){
return { redirectUrl: details.url.replace(/.*:\/\/www.bing.com\/search/, "http://www.ask.com/web")};
return url.replace(/.*:\/\/www.bing.com\/search/, "http://www.ask.com/web");
}
if(storageChange=="Yahoo.com"){
return { redirectUrl: details.url.replace("www.bing.com/search?q", "search.yahoo.com/search?p")};
return url.replace("www.bing.com/search?q", "search.yahoo.com/search?p");
}
if(storageChange=="Aol.com"){
return { redirectUrl: details.url.replace(/.*:\/\/www.bing.com\/search/, "http://search.aol.com/aol/search")};
return url.replace(/.*:\/\/www.bing.com\/search/, "http://search.aol.com/aol/search");
}
if(storageChange=="Wow.com"){
return { redirectUrl: details.url.replace(/.*:\/\/www.bing.com/, "http://us.wow.com")};
return url.replace(/.*:\/\/www.bing.com/, "http://us.wow.com");
}
return { redirectUrl: details.url.replace("www.bing.com/search", "www.google.com/search")};
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
@@ -40,4 +44,18 @@ chrome.runtime.onInstalled.addListener(function(details){
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)});
});
}
};
View
@@ -12,7 +12,8 @@
"webRequest",
"webRequestBlocking",
"storage",
"background"
"background",
"tabs"
],
"background": {
"scripts": ["js/bootstrap.js"]

0 comments on commit c18ae14

Please sign in to comment.