Initial Commit
Basic implementation of search switcher extension.
This commit is contained in:
commit
3fc36559da
5
.idea/.gitignore
vendored
Normal file
5
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
13
.idea/SearchSwitch.iml
Normal file
13
.idea/SearchSwitch.iml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="@types/chrome" level="application" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/jsLibraryMappings.xml
Normal file
6
.idea/jsLibraryMappings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptLibraryMappings">
|
||||||
|
<file url="PROJECT" libraries="{@types/chrome}" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/SearchSwitch.iml" filepath="$PROJECT_DIR$/.idea/SearchSwitch.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
36
background.js
Normal file
36
background.js
Normal file
@ -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});
|
||||||
|
} );
|
||||||
|
});
|
14
manifest.json
Normal file
14
manifest.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user