Twitter Search Bookmarklet

Throughout the day, I’m likely to search Twitter a number of times. Being the lazy person that I am, I got sick of opening a new tab, typing search.twitter.com, hitting enter, waiting for the page, then typing my term and waiting for results. I already have a couple of other bookmarklets that I use all the time (one for loading up a Google Map, one for jumping to a PHP function name in the online reference), so I figured I’d knock up something to search Twitter. I’m using Firefox on a Mac, YMMV.

  1. Bookmark any page (seriously, any page).
  2. Put that bookmark into your Bookmarks Toolbar.
  3. Right click it and select Properties
  4. Change the Name to something like “Search Twitter”
  5. Change the Location to this (copy and paste it):
    javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0));if(!s.length){s=prompt('Search%20Twitter:','');}if(s){document.location.href='http://search.twitter.com/search?q='+escape(s);}else{void(0);}
  6. Save Changes

That’s it. Now click that link in your Bookmark Toolbar and it’ll prompt you for a search string. Enter anything and hit OK. If you happen to have some text on the page selected, it’ll automatically search for that text. Voila – Twitter Search.