Kevin O.
Kevin O.

Reputation: 79

Need javascript bookmarklet assistance

I have zero javascript experience but have a task which I believe can be massively sped up through the use of a bookmarklet for Firefox/Chrome. I've been searching for a few hours but without luck for any basic tutorials that would give me the help I need.

In short, I'm looking to create a bookmarklet that will search the site I'm on (i.e. stackoverflow.com) for specific, hard coded text. I repeat these searches often hundreds of times per day and am trying to find a way to speed up the process.

I usually search for a single keyword but sometimes in combination, i.e.: nonprofit OR foundation OR grantmaker (and sometimes include the filetype:pdf modifier).

If anyone can point me in the right direction oor show me a basic snippet of code for this type of search I would greatly appreciate it!

Upvotes: 0

Views: 127

Answers (2)

JKirchartz
JKirchartz

Reputation: 18042

javascript:window.open("http://google.com/?q=site:"+document.domain); will dump you over to google searching on the current domain...

Upvotes: 0

David Hedlund
David Hedlund

Reputation: 129832

It could look something like this:

javascript:var s = 'test'; window.open('http://www.google.com/search?q=' + encodeURI(s + ' site:' + location.hostname), 'bookmarklet')

Where the s variable is your predefined search query. The query could be formed in any manner that Google tolerates, including the filetype: keyword. Clicking the bookmarklet would open a new window/tab with a search for the given query, within the site you're browsing.

Upvotes: 1

Related Questions