auto append string to google (or live or yahoo or altavista) websearches

in Ideas and script requests
Subscribe to auto append string to google (or live or yahoo or altavista) websearches 21 posts, 5 voices



Good To Too Scriptwright

I frequently "get to" enter


-2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008

or


-2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007

it'd be great to have a user script to do at least one on a toggle basis for the big four search engines

 
znerp Scriptwright

For Google this would be easy enough by doing this..

searchString = "-2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008 "
if (location.search.indexOf(searchString) == -1)
  location.search += "&q=" + searchString

I don't use the other search engines at all but I imagine something similar should work.

 
JoeSimmons Scriptwright

http://userscripts.org/scripts/show/40931

 
Good To Too Scriptwright
Thanks that's great!


.. but it doesn't work for searches initiated from CTRL-K (search bar in toolbar)


because it's looking for a button?

f.addEventListener('submit', function(e)


http://www.google.com/search?q=blend+kittens&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a


in addition to CTRL+K support would you also have it remove

&aq=t&rls=org.mozilla:en-US:official&client=firefox-a


 
znerp Scriptwright

The whole script seems excessive to me. It really would be much simpler to go with what I said...

// ==UserScript==
// @name           Append String to Google search
// @include        http://www.google.com/search?q=*
// ==/UserScript==

searchString = "-2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008 "
if (location.search.indexOf(searchString) == -1)
  location.search += "&q=" + searchString
 
Good To Too Scriptwright
warning: contains some stream of consciousness ... at least I'm conscious

@znerp

How could his q matching be changed to use

// f.elements.namedItem('q').value += filter;
// something else to pickup q and value and append fitler?


....
aside: wow, thanks, I never realized until I tried it seconds ago that the google search url could contain TWO &q= and google would build one search string into the search field
....


the JoeSimmons userscript relies on getElementsByName and button mashing so I'm left wondering how to integrate your &q=filter append into his function f/e or to append the filter to the existing &q as his does -- keep yours but add toggle

apparently it's beyond me (currently)


my use of your bits has a tiny iterate infinitely problem

http://userscripts.org/scripts/show/41010


 
znerp Scriptwright

I'd have to look at Joe's code to work out your first question, which I may do in a while.

With respect to your second question though, it's a small oversight on my part. Change the if-condition to this...

if (location.search.indexOf(encodeURI(searchString)) == -1)
 
Good To Too Scriptwright

excellent, thank you! =D

[1]
To assist my understanding of string replacement how would you modify it such that it only appends the filter if the original search contained the term 'xdate'?
(and also removes the term 'xdate')

I'm crafting my reply to my other thread, http://userscripts.org/topics/20707 , expanding my understanding of this topic.

edit:

[2]
Also how would your userscript need to be modified so that it would not append the filter to the search string each time it was submitted? when I modify the existing search and hit submit there are two sets of filters.. which isn't a problem really since they are "must not contain" but it does eventually clutter the page

 
JoeSimmons Scriptwright

I updated mine so that if the script is set to 'on' in the userscript commands, it will append the filter to an existing search meaning you can search from your toolbar. I added the 'xdate' thing; it wont add the filter unless xdate is in the query then it removes 'xdate' and adds the filter.

 
znerp Scriptwright

Sorry, I seem to have missed this earlier.

[1]
To assist my understanding of string replacement how would you modify it such that it only appends the filter if the original search contained the term 'xdate'?
(and also removes the term 'xdate')

If my understanding of what you want is correct, then you can do this..

if (location.search.indexOf("xdate") > -1)
  location.search = location.search.replace("xdate", searchString)

[2]
Also how would your userscript need to be modified so that it would not append the filter to the search string each time it was submitted? when I modify the existing search and hit submit there are two sets of filters.. which isn't a problem really since they are "must not contain" but it does eventually clutter the page

I can't see why that would be the case.

 
Good To Too Scriptwright

> I can't see why that would be the case.

http://userscripts.org/scripts/review/41010

submit search via CTRL+K
append secondsearch to google search field and submit
append thirdsearch to google search field and submit
append fourthsearch to google search field and submit

http://img520.imageshack.us/my.php?image=afterf...

There were no results in your selected language(s). Showing worldwide web results for apple -2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008 secondsearch -2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008 thirdsearch -2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008 fourthsearch -2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008.

it's merely a curiosity

 
znerp Scriptwright

Ok, I see. It seems that google sometimes makes the spaces into %20 and sometimes into +. There's probably a better way, but this should sort that..

searchString = "-2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008 "
if (location.search.indexOf(encodeURI(searchString)) == -1 &&
    location.search.indexOf(searchString.replace(/\s/g, '+')) == -1)
  location.search += "&q=" + searchString
 
Good To Too Scriptwright

@JoeSimmons

in a temporary, fresh firefox profile, searching google with "xdate clowns" resulted in this in the google search field:

x -2000 -2001 -2002 -2003 -2004 -2005 -2006 -2007 -2008date clowns

 
Good To Too Scriptwright

@ znerp

with your modifications have you tried submitting a search to google and on the resulting page mashing submit a second time changing nothing?

 
Good To Too Scriptwright

(you guys are awesome)

 
znerp Scriptwright
with your modifications have you tried submitting a search to google and on the resulting page mashing submit a second time changing nothing?

You keep saying mashing but I have no idea what you mean by that. I followed the steps you listed above, and the code I just posted worked fine for that..

submit search via CTRL+K
append secondsearch to google search field and submit
append thirdsearch to google search field and submit
append fourthsearch to google search field and submit

 
JoeSimmons Scriptwright

No... lol you use xdate after the search term... like "clowns xdate"

 
Aquilax Scriptwright


aside: wow, thanks, I never realized until I tried it seconds ago that the google search url could contain TWO &q= and google would build one search string into the search field

Any url can contains infinite parameters with the same name, this is because at the beginning the submitted forms generated a different parameter for each input, then to spare space they were joint together and separated with a comma.


<input type="checkbox" name="q" value="first">
<input type="checkbox" name="q" value="second">

//Old way to submit the form's parameters: q=first&q=second
//New way to submit the form's parameters: q=first,second
//Also if all the browsers nowadays use the new way to submit the parameters the old way is still supported by most web servers

 
Avindra V.G. Scriptwright

@Aquilax

I didn't know comma separated url arguments was a standard. Thanks for the tip!

 
Good To Too Scriptwright

@ znerp

> You keep saying mashing

mash, v.
transitive: To click a button with fervor or fury.
;)

.
.

@ JoeSimmons

Thanks. Any idea why it does not work as expected with a search intiated from CTRL+K?

.
.

userscript not enabled: search initiated from CTRL+K

http://www.google.com/search?q=kay+xdate&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

.
userscript enabled: search initiated from CTRL+K

http://www.google.com/search?q=k+-2000+-2001+-2002+-2003+-2004+-2005+-2006+-2007+-2008ay+xdate&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

.
.
userscript not enabled: search initiated from google.com

http://www.google.com/search?hl=en&q=kay+xdate&btnG=Google+Search&aq=f&oq=

.
userscript enabled: search initiated from google.com

http://www.google.com/search?hl=en&q=kay++-2000+-2001+-2002+-2003+-2004+-2005+-2006+-2007+-2008&aq=f&oq=kay+xdate

.
.
search: kay xdate

 
JoeSimmons Scriptwright

Works fine for me, did you update the script?

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel