A generic JavaScript template to extend Google Chrome's custom search engines functionality with Tampermonkey.
Google Chrome has pretty good methods of customizing your search in the address bar, to do customized search. However, this only works with searches that take the url as imput and have a single plaintext payload. This is a template for making a Tampermonkey script that runs with a payload in the url, that can be combined with Chrome's custom search to do custom searches on a non-url based site search, by filling the text box.
You could also theorhetically use stuff like this to fill a form or perform complex actions from your address bar, but that's neither here nor there.
- Install Chrome & the Tampermonkey plugin.
- Visit the site you'd like to do search on, preferably on a page where the search bar is clear and obvious.
- Copy that site's url.
- Click the three dots in the top right corner of chrome, then click 'Settings'.
- Find the setting labeled 'Manage search engines and site search'
- In the section labeled 'site search', click 'add'.
- Fill in the form, 'Search engine' is the name of the site whose search you'll be using, and 'shortcut' is what you want to type in the address bar to search on that site.
- For url, paste the url you copied and then add '?tmpayload=*'
- Return to the tab where you had the website to search.
- Right click on the Extensions icon (the puzzle piece)
- Click on Tampermonkey, then click 'create a new script...'
- Replace the text in the text editor with the body of template.js
- Replace YourURL.here with the url of the site you'd like to search.
- Go back to the tab of your site, right click and inspect element on the search bar. Find the id attribute. (Note: if it doesn't have an id attribute you're going to have to use another method to
- Paste that in the area labelled "Paste Search Bar ID Here"
- Inspect element on the search button and paste it in the area labelled "Paste Click Button ID Here"
- Optional: Add advanced search terms by doing inspect element and pasting them into the search_term_id_dict in the same fashion
- Save the Tampermonkey script
- You're now ready to test that the script functions!