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 hidden or 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jehrenzweig-captionhealth check @cmccormack 's reply above. The script doesn't work on New Tab page; you need to press
shift + enter
.