DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Looking for alternative script to search site  (Read 15,168 times)

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Looking for alternative script to search site
« on: March 29, 2021, 03:06 PM »
Have a script in my bookmarks to search a site, but it always uses Google.

Is there a way to have one that can use another search engine?

Startpage, DuckDuckGo, Presearch, Qwant are some of my favorite alternatives.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: Looking for alternative script to search site
« Reply #1 on: March 29, 2021, 04:45 PM »
We'd probably need to know a bit more about this script.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Looking for alternative script to search site
« Reply #2 on: March 29, 2021, 04:46 PM »
Without seeing the script it's a bit hard to comment but you should be able to change any occurrence of google.com to qwant.com, (my default search engine), I believe the query format is similar.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #3 on: March 29, 2021, 05:39 PM »
Thought about after and then the day got going...

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);

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #4 on: March 29, 2021, 07:10 PM »
Did try to replace Google.com with Qwant.com and it doesn't work.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Looking for alternative script to search site
« Reply #5 on: March 29, 2021, 11:28 PM »
Did try to replace Google.com with Qwant.com and it doesn't work.

Qwant doesn't use the search keyword:

Code: ( javascript)
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.qwant.com/?q=%22+q.replace(/\s+/g,%22+%22)+%22+site:%22+location.hostname;void(0);

Neither does DDG:

Code: ( javascript)
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://duckduckgo.com/?q=%22+q.replace(/\s+/g,%22+%22)+%22+site:%22+location.hostname;void(0);

Startpage different again:

Code: ( javascript)
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://startpage.com/sp/search?q=%22+q.replace(/\s+/g,%22+%22)+%22+site:%22+location.hostname;void(0);

Presearch:

Code: ( javascript)
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);

Just input the search into an engine and use the relevant part of the URL:

Quote
https://engine.presearch.org/search?q=thought+site%3Adonationcoder.com
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: March 30, 2021, 12:03 AM by 4wd »

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #6 on: March 30, 2021, 12:19 AM »
@4wd - would it be too much to illustrate Presearch as example?  :-[

Re-read your post at least 4 times...

Wish i was a coder!

The little html i learned years ago, is long gone.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Looking for alternative script to search site
« Reply #7 on: March 30, 2021, 02:28 AM »
Let's start with a site search on Donationcoder for mouser in Google, you'd enter:
Code: (generic)
mouser site:donationcoder.com

After hitting Enter the URL becomes:
Code: (generic)
https://www.google.com/search?q=mouser+site%3Adonationcoder.com

Same search on Presearch gives a URL of:
Code: (generic)
https://engine.presearch.org/search?q=mouser+site%3Adonationcoder.com

Your original bookmarklet, (which is what a bookmark consisting of JavaScript is generally called):
Code: (JavaScript)
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):
Code: (generic)
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:
Code: (generic)
q.replace(/\s+/g,%22+%22)
ie. mouser
And addition of the current site URL:
Code: (generic)
location.hostname
ie. donationcoder.com

The format of the search terms is basically identical between Google and Presearch, shown above in the individuals URLs, this bit:
Code: (generic)
q=mouser+site%3Adonationcoder.com

The only difference is the base URL:
Code: (generic)
https://www.google.com/search?
Versus:
Code: (generic)
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:

Code: (javascript)
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:
  1. it's not really relevant to the original query and,
  2. I'd have to read up to understand it also :P
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: March 30, 2021, 07:19 AM by 4wd »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: Looking for alternative script to search site
« Reply #8 on: March 30, 2021, 04:28 PM »
@4wd - would it be too much to illustrate Presearch as example?  :-[

Re-read your post at least 4 times...

Wish i was a coder!

The little html i learned years ago, is long gone.

Basically, after you do a search on the platform, look at the format of the search terms. They should tell you how to format your url in your script. That's what @4wd is illustrating.

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #9 on: March 30, 2021, 07:04 PM »
So basically, if Presearch is selected, then this is the part i would use
%22http://engine.presearch.org/search?q=%22+q.replace(/\s+/g,%22+%22)
to replace Google's?

Did use 4wd's last script and it isn't responding.

(btw - thanks for the sweat out brushing up on the coding language 4wd!
Illustration is much appreciated too and hope other newbies will find it helpful).

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Looking for alternative script to search site
« Reply #10 on: March 30, 2021, 11:00 PM »
NOTE: This was all written on a tablet, tables would have looked better but editing on a tablet is painful to say the least. (It actually looks better in Preview than Posted.)

So basically, if Presearch is selected, then this is the part i would use
%22http://engine.presearch.org/search?q=%22+q.replace(/\s+/g,%22+%22)
to replace Google's?

Not even that much, google.com -> engine.presearch.org, everything else is the same.

Don't look at the JavaScript, look at example search URLs from the search engines themselves:
Code
https://   www.google.com          /search?q=mouser+site%3Adonationcoder.com  (Google - original)
https://   engine.presearch.org    /search?q=mouser+site%3Adonationcoder.com  (Presearch)

Code
https://   www.google.com/search     ?q=mouser+site%3Adonationcoder.com  (Google - original)
https://   qwant.com/                ?q=mouser+site%3Adonationcoder.com  (Qwant)
https://   duckduckgo.com/           ?q=mouser+site%3Adonationcoder.com  (DDG)
https://   startpage.com/sp/search   ?q=mouser+site%3Adonationcoder.com  (Startpage)

The second section in each case is the minimum that needs changing.
All other sections of test searches on the engines are identical.

NOTES:
  1. I removed unnecessary crap from the example URLs, eg. setting strings, tracking, etc, so all are the minimum that are required for them to work.
  2. www.google.com is google.com in the bookmarklet.

Quote
Did use 4wd's last script and it isn't responding.

I tested all four of the ones I changed and they all worked for me. The Presearch version in the last post was a copy/paste of the previous, which was copy/paste out of my browser, (Opera).
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #11 on: March 30, 2021, 11:30 PM »
@4wd - thanks again, you have been more than patient!!

First try was with Vivaldi (still doesn't work after third verification).

Just tested with Firefox and your script works just fine there.  :)

Wonder why initial Google script works with Vivaldi but not yours?  :huh:

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Looking for alternative script to search site
« Reply #12 on: March 31, 2021, 12:02 AM »
First try was with Vivaldi (still doesn't work after third verification).

Just tried the Presearch one above in Vivaldi, (Vivaldi 2.9.1699.4 (Official Build) (64-bit)), and it worked OK - had to double-click the bookmarklet.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #13 on: March 31, 2021, 12:33 AM »
2.9.2218.49 here.

The odd thing is.
Tried on Brave browser with both Google and Presearch and neither worked.
Then went over to M$ Edge and both went well.  :(
Btw, both Brave and M$ Edge already have a functioning version of the "Google" script.
I'm just stymied about this incoherence.

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #14 on: April 15, 2021, 12:48 PM »
Think i might start studying DuckDuckGo's ways of searching as it is a cross-browser option.

Ghacks just tickled my curiosity:
https://www.ghacks.net/2021/04/15/how-to-use-duckduckgo-instead-of-google-and-other-sites-to-get-faster-and-precise-results/

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #15 on: June 11, 2021, 01:07 PM »
Not satisfied with not being able to get Presearch to work with Vivaldi... decided to finally take my chance and posted issue over there.

Turns out, one person had same issue as me.
Worked fine with other browsers except Vivaldi.  :mad:

So, final response came in with a modified JS:
javascript:q=window.getSelection().toString();if(!q)q=prompt("Search%20terms");if(q!=null)location="https://engine.presearch.org/search?q="+q+"+site:"+location.hostname;


And it works fine now with Vivaldi!  :Thmbsup: :-*

dantheman

  • Be good if you can!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 743
Re: Looking for alternative script to search site
« Reply #16 on: June 11, 2021, 05:52 PM »
@4wd - huge thank you for your enduring patience!  :)

Turns out to also be a Vivaldi bug in need of some fixin'.

Original address: https://www.donationcoder.com/forum/index.php?topic=51251.0