topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday September 18, 2021, 3:13 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Looking for alternative script to search site  (Read 4709 times)

dantheman

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 727
  • Be good if you can!
    • View Profile
    • Donate to Member
Looking for alternative script to search site
« on: March 29, 2021, 10:06 AM »
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
  • **
  • default avatar
  • Posts: 10,953
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #1 on: March 29, 2021, 11:45 AM »
We'd probably need to know a bit more about this script.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,531
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #2 on: March 29, 2021, 11:46 AM »
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.

dantheman

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 727
  • Be good if you can!
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #3 on: March 29, 2021, 12: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

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


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,531
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #5 on: March 29, 2021, 06: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 [Select]
  1. 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 [Select]
  1. 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 [Select]
  1. 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 [Select]
  1. 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:

https://engine.presearch.org/search?q=thought+site%3Adonationcoder.com
« Last Edit: March 29, 2021, 07:03 PM by 4wd »

dantheman

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 727
  • Be good if you can!
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #6 on: March 29, 2021, 07:19 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.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,531
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #7 on: March 29, 2021, 09:28 PM »
Let's start with a site search on Donationcoder for mouser in Google, you'd enter:
Code: Text [Select]
  1. mouser site:donationcoder.com

After hitting Enter the URL becomes:
Code: Text [Select]
  1. https://www.google.com/search?q=mouser+site%3Adonationcoder.com

Same search on Presearch gives a URL of:
Code: Text [Select]
  1. 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 [Select]
  1. 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: Text [Select]
  1. 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: Text [Select]
  1. q.replace(/\s+/g,%22+%22)
ie. mouser
And addition of the current site URL:
Code: Text [Select]
  1. 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: Text [Select]
  1. q=mouser+site%3Adonationcoder.com

The only difference is the base URL:
Code: Text [Select]
  1. https://www.google.com/search?
Versus:
Code: Text [Select]
  1. 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 [Select]
  1. 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 :P
« Last Edit: March 30, 2021, 02:19 AM by 4wd »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 10,953
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #8 on: March 30, 2021, 11:28 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.

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

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 727
  • Be good if you can!
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #9 on: March 30, 2021, 02: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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,531
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #10 on: March 30, 2021, 06: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:
https://   www.google.com          /search?q=mouser+site%3Adonationcoder.com  (Google - original)
https://   engine.presearch.org    /search?q=mouser+site%3Adonationcoder.com  (Presearch)

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:
  • 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.
  • www.google.com is google.com in the bookmarklet.

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

dantheman

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 727
  • Be good if you can!
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #11 on: March 30, 2021, 06: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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,531
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #12 on: March 30, 2021, 07:02 PM »
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.

dantheman

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 727
  • Be good if you can!
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #13 on: March 30, 2021, 07:33 PM »
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

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 727
  • Be good if you can!
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #14 on: April 15, 2021, 07:48 AM »
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.n...and-precise-results/

dantheman

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 727
  • Be good if you can!
    • View Profile
    • Donate to Member
Re: Looking for alternative script to search site
« Reply #15 on: June 11, 2021, 08:07 AM »
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

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

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