Add support for google and bing image searching
This commit is contained in:
parent
13f361a490
commit
6100a6ec82
@ -1,12 +1,16 @@
|
|||||||
function switchSearch(tab) {
|
function switchSearch(tab) {
|
||||||
const bingSearch = "https://www.bing.com/search?q=";
|
const bingSearch = "https://www.bing.com/search?q=";
|
||||||
const googleSearch = "https://www.google.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;
|
const url = tab.url;
|
||||||
|
|
||||||
let newURL;
|
let newURL;
|
||||||
let removeEngine;
|
let removeEngine;
|
||||||
let searchEnd;
|
let searchEnd;
|
||||||
let justSearch;
|
let justSearch;
|
||||||
|
//Handle bing searches
|
||||||
if (url.substring(0, bingSearch.length) === bingSearch) {
|
if (url.substring(0, bingSearch.length) === bingSearch) {
|
||||||
removeEngine = url.slice(bingSearch.length);
|
removeEngine = url.slice(bingSearch.length);
|
||||||
searchEnd = removeEngine.indexOf('&');
|
searchEnd = removeEngine.indexOf('&');
|
||||||
@ -15,6 +19,15 @@ function switchSearch(tab) {
|
|||||||
newURL = googleSearch + justSearch + '&';
|
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) {
|
else if (url.substring(0, googleSearch.length) === googleSearch) {
|
||||||
removeEngine = url.slice(googleSearch.length);
|
removeEngine = url.slice(googleSearch.length);
|
||||||
searchEnd = removeEngine.indexOf('&');
|
searchEnd = removeEngine.indexOf('&');
|
||||||
@ -22,6 +35,16 @@ function switchSearch(tab) {
|
|||||||
|
|
||||||
newURL = bingSearch + justSearch + '&';
|
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;
|
return newURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,4 +56,5 @@ chrome.action.onClicked.addListener((tab) => {
|
|||||||
}, async (redirect) => {
|
}, async (redirect) => {
|
||||||
await chrome.tabs.update({url: redirect[0].result});
|
await chrome.tabs.update({url: redirect[0].result});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
)
|
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "SearchSwitcher",
|
"name": "SearchSwitcher",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"description": "Search switcher",
|
"description": "Search switcher",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"author": "Isaac Shoebottom",
|
"author": "Isaac Shoebottom",
|
||||||
"action": {
|
"action": {
|
||||||
"default_title": "Switch Search"
|
"default_title": "Switch Search"
|
||||||
},
|
},
|
||||||
"permissions": ["activeTab", "tabs", "scripting"],
|
"permissions": ["activeTab", "scripting"],
|
||||||
"background": {
|
"background": {
|
||||||
"service_worker": "background.js"
|
"service_worker": "background.js"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user