Let's start with a site search on Donationcoder for mouser in Google, you'd enter:
mouser site:donationcoder.com
After hitting Enter the URL becomes:
https://www.google.com/search?q=mouser+site%3Adonationcoder.com
Same search on Presearch gives a URL of:
https://engine.presearch.org/search?q=mouser+site%3Adonationcoder.com
Your original bookmarklet, (which is what a bookmark consisting of JavaScript is generally called):
javascript:q=%22%22+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt(%22Search%20terms%20[leave%20selection%20and%20box%20blank%20to%20list%20all%20pages]%20...%22).replace(/\s\+/g,%22%252B%22);if(q!=null)location=%22http://www.google.com/search?q=%22+q.replace(/\s+/g,%22+%22)+%22+site:%22+location.hostname;void(0);
Within it is the same format site search URL as for Google above, (%22 is HTML escaped ASCII for quote,
" - ignored for the purposes of simplified explanation):
http://www.google.com/search?q=%22+q.replace(/\s+/g,%22+%22)+%22+site:%22+location.hostname
You have code replacement for your entered search term:
q.replace(/\s+/g,%22+%22)
ie.
mouserAnd addition of the current site URL:
ie.
donationcoder.comThe format of the search terms is basically identical between Google and Presearch, shown above in the individuals URLs, this bit:
q=mouser+site%3Adonationcoder.com
The only difference is the base URL:
https://www.google.com/search?
Versus:
https://engine.presearch.org/search?
So it becomes a simple text replacement to switch from Google to Presearch, the same applies to the other search engines listed above, so the bookmarklet becomes:
javascript:q=%22%22+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt(%22Search%20terms%20[leave%20selection%20and%20box%20blank%20to%20list%20all%20pages]%20...%22).replace(/\s\+/g,%22%252B%22);if(q!=null)location=%22http://engine.presearch.org/search?q=%22+q.replace(/\s+/g,%22+%22)+%22+site:%22+location.hostname;void(0);
So no coding required, just observation
BTW, haven't bothered explaining the rest of the JavaScript involved because:
- it's not really relevant to the original query and,
- I'd have to read up to understand it also