commit 3fc36559dad721614da9f6408b99c8503baa1a92 Author: Isaac Shoebottom Date: Tue Jun 28 00:36:01 2022 -0300 Initial Commit Basic implementation of search switcher extension. diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/SearchSwitch.iml b/.idea/SearchSwitch.iml new file mode 100644 index 0000000..b8f4056 --- /dev/null +++ b/.idea/SearchSwitch.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..1adbe87 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..16a949f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/background.js b/background.js new file mode 100644 index 0000000..ed1eb0a --- /dev/null +++ b/background.js @@ -0,0 +1,36 @@ +function switchSearch(tab) { + const bingSearch = "https://www.bing.com/search?q="; + const googleSearch = "https://www.google.com/search?q="; + const url = tab.url; + + let newURL; + let removeEngine; + let searchEnd; + let justSearch; + if (url.substring(0, bingSearch.length) === bingSearch) { + removeEngine = url.slice(bingSearch.length); + searchEnd = removeEngine.indexOf('&'); + justSearch = removeEngine.substring(0, searchEnd); + + newURL = googleSearch + justSearch + '&'; + + } + else if (url.substring(0, googleSearch.length) === googleSearch) { + removeEngine = url.slice(googleSearch.length); + searchEnd = removeEngine.indexOf('&'); + justSearch = removeEngine.substring(0, searchEnd); + + newURL = bingSearch + justSearch + '&'; + } + return newURL; +} + +chrome.action.onClicked.addListener((tab) => { + chrome.scripting.executeScript({ + target: {tabId: tab.id}, + func: switchSearch, + args: [tab] + }, async (redirect) => { + await chrome.tabs.update({url: redirect[0].result}); + } ); + }); \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..670207e --- /dev/null +++ b/manifest.json @@ -0,0 +1,14 @@ +{ + "name": "SearchSwitcher", + "version": "0.0.1", + "description": "Search switcher", + "manifest_version": 3, + "author": "Isaac Shoebottom", + "action": { + "default_title": "Switch Search" + }, + "permissions": ["activeTab", "tabs", "scripting"], + "background": { + "service_worker": "background.js" + } +} \ No newline at end of file