From 1f5f00f82ac627189785cb089b0b5103a3e98ccd Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Tue, 27 Sep 2022 19:29:16 -0300 Subject: [PATCH] Correct behavior on firefox --- v2/background.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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