Add manifest v2 extension

This commit is contained in:
Isaac Shoebottom 2022-09-27 18:40:42 -03:00
parent 03de07c043
commit 42602cc2a4
4 changed files with 72 additions and 1 deletions

View File

@ -9,5 +9,7 @@
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="@types/chrome" level="application" /> <orderEntry type="library" name="@types/chrome" level="application" />
<orderEntry type="library" name="@types/firefox" level="application" />
<orderEntry type="library" name="@types/jquery" level="application" />
</component> </component>
</module> </module>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="JavaScriptLibraryMappings"> <component name="JavaScriptLibraryMappings">
<file url="PROJECT" libraries="{@types/chrome}" /> <file url="PROJECT" libraries="{@types/chrome, @types/firefox, @types/jquery}" />
<includedPredefinedLibrary name="HTTP Response Handler" />
</component> </component>
</project> </project>

53
v2/background.js Normal file
View File

@ -0,0 +1,53 @@
function switchSearch(tab) {
const bingSearch = "https://www.bing.com/search?q=";
const googleSearch = "https://www.google.com/search?q=";
const bingImageSearch = "https://www.bing.com/images/search?q="
const googleImageSearchSubstring = "&tbm=isch";
const url = tab.url;
let newURL;
let removeEngine;
let searchEnd;
let justSearch;
//Handle bing searches
if (url.substring(0, bingSearch.length) === bingSearch) {
removeEngine = url.slice(bingSearch.length);
searchEnd = removeEngine.indexOf('&');
justSearch = removeEngine.substring(0, searchEnd);
newURL = googleSearch + justSearch + '&';
}
//Handle Google image searches
else if (url.indexOf(googleImageSearchSubstring) > googleSearch.length) {
removeEngine = url.slice(googleSearch.length);
searchEnd = removeEngine.indexOf('&');
justSearch = removeEngine.substring(0, searchEnd);
newURL = bingImageSearch + justSearch + '&';
}
//Handle Google searches
else if (url.substring(0, googleSearch.length) === googleSearch) {
removeEngine = url.slice(googleSearch.length);
searchEnd = removeEngine.indexOf('&');
justSearch = removeEngine.substring(0, searchEnd);
newURL = bingSearch + justSearch + '&';
}
//Handle bing image searches
else if (url.substring(0, bingImageSearch.length) === bingImageSearch) {
removeEngine = url.slice(bingImageSearch.length)
searchEnd = removeEngine.indexOf('&');
justSearch = removeEngine.substring(0, searchEnd);
newURL = googleSearch + justSearch + googleImageSearchSubstring + '&';
}
return newURL;
}
chrome.browserAction.onClicked.addListener((tab) => {
chrome.tabs.update({url: switchSearch(tab)}).then(r => console.log(r))
}
)

15
v2/manifest.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "SearchSwitcher",
"version": "0.0.2",
"description": "Search switcher",
"manifest_version": 2,
"author": "Isaac Shoebottom",
"browser_action": {
"default_title": "Switch Search"
},
"permissions": ["activeTab", "scripting"],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}