diff --git a/v2/background.js b/v2/background.js index b3a15b1..6c29bd4 100644 --- a/v2/background.js +++ b/v2/background.js @@ -1,22 +1,26 @@ function switchSearch(tab) { - const bingSearch = "https://www.bing.com/search?q="; - const googleSearch = "https://www.google.com/search?q="; + const bingSearch = "https://www.bing.com/search?"; + const googleSearch = "https://www.google.com/search?"; - const bingImageSearch = "https://www.bing.com/images/search?q=" + const bingImageSearch = "https://www.bing.com/images/search?" const googleImageSearchSubstring = "&tbm=isch"; const url = tab.url; let newURL; let removeEngine; + let searchStart; let searchEnd; let justSearch; //Handle bing searches + //This is the way it should be done, TODO: Refactor rest of methods to be like this if (url.substring(0, bingSearch.length) === bingSearch) { removeEngine = url.slice(bingSearch.length); - searchEnd = removeEngine.indexOf('&'); - justSearch = removeEngine.substring(0, searchEnd); + searchStart = removeEngine.indexOf('&q=') + 3; + justSearch = removeEngine.substring(searchStart); + searchEnd = justSearch.indexOf('&'); + justSearch = justSearch.substring(0, searchEnd); - newURL = googleSearch + justSearch + '&'; + newURL = googleSearch + 'q=' +justSearch + '&'; } //Handle Google image searches