Last active
June 21, 2024 15:33
-
-
Save cmccormack/8c468d74aa2d22e7ef7812ffbe732ce2 to your computer and use it in GitHub Desktop.
Google Chrome Search Engine with multiple search strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @desc this snippet will allow multiple arguments to a search query in Google Chrome | |
* examples include https://www.reddit.com/r/%s/search?q=%s | |
* @author Chris McCormack [email protected] | |
* @required Google Chrome. Replace all values in brackets ([]) with valid entries. | |
* To add to Chrome, go to Settings > Search [Manage search engines...] > Other search engines. | |
* At the bottom of this section, there are three required fields: | |
* [Add a new search engine] [Keyword] [URL with %s in place of query] | |
* - Add a new search engine: Descriptive name of your search | |
* - Keyword: used to trigger search. | |
* Example: typing maps.google.com then hitting [tab] or [space] replaces the search bar with a Google Maps search. | |
* - URL with %s in place of query: This is where the javascript code below is entered. | |
*/ | |
/** Javascript code broken out with comments: */ | |
javascript: | |
var search='%s'; // '%s' is the search string provided in the Omnibox | |
url='[URL including at least one %s]'; // example https://www.reddit.com/r/%s/search?q=%s | |
query=''; // leave blank | |
urlsegments=url.split('%s'); | |
searchsegments=search.split('[string separator]'); // replace with separator (ex: ';', ' ', ',') | |
for(i=0; i<searchsegments.length; i++) query+=urlsegments[i]+searchsegments[i]; | |
query+=urlsegments[urlsegments.length - 1]; // appends the remaining url if any | |
location.replace(query); | |
/** Short version without comments: */ | |
javascript: var search='%s'; url='[URL including at least one %s]'; query=''; urlsegments=url.split('%s'); searchsegments=search.split('[string separator]'); for(i=0; i<searchsegments.length; i++) query+=urlsegments[i]+searchsegments[i]; query+=urlsegments[urlsegments.length - 1]; location.replace(query); | |
/** Example code using a reddit search including subreddit name and search query. | |
* In this example, 'rs' was used as the keyword. Typing 'rs[space]' then 'news syria' | |
* returns the top results from the past year for 'syria' from reddit.com/r/news. | |
*/ | |
javascript: var search='%s'; url='https://www.reddit.com/r/%s/search?q=%s&sort=top&restrict_sr=on&t=year'; query=''; urlsegments=url.split('%s'); searchsegments=search.split(' '); for(i=0; i<searchsegments.length; i++) query+=urlsegments[i]+searchsegments[i]; query+=urlsegments[urlsegments.length - 1]; location.replace(query); |
Hi @cmccormack. Recently I have been using Microsoft Edge (based on Chromium) and found out that it supports this script very well! Don't need to shift-enter or all that stuff. I wonder how the search engine implementation in Edge is different from Chrome, Brave etc.? Can you please have a look into it if you have some free time?
Doesn't seem to work in the latest version of Chrome (126.x.x.x
)-- not as written, anyway.
@jehrenzweig-captionhealth check @cmccormack 's reply above. The script doesn't work on New Tab page; you need to press shift + enter
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I found this script while searching for something like this. After some testing I got it to work. Just 1 'feature request' I guess. Would it be possible to add support for strings containing a space?
Nevermind, I realised as I was typing that I could change the separator to anything I want. So for others: I changed
search.split(' ')
tosearch.split('"')
. So now I can type aaa"bbb bbb"ccc to use 3 strings.