Skip to content

Instantly share code, notes, and snippets.

@timwhitlock
Created August 9, 2010 14:00
Show Gist options
  • Save timwhitlock/515450 to your computer and use it in GitHub Desktop.
Save timwhitlock/515450 to your computer and use it in GitHub Desktop.
improved dictionary.com bookmarklet
// source
void ( function(){
try {
var s = window.getSelection();
var q = s ? s.toString().replace(/(^\W+|\W+$)/g,'') : '';
if( ! q ){
q = prompt('Enter a word to look up');
if( ! q ){
return;
}
}
var u = 'http://dictionary.reference.com/search?r=1&q='+encodeURIComponent(q);
window.open(u);
}
catch( Er ){
alert( 'Oops:\n'+Er.message );
}
} )();
// compressed and encoded for href/bookmarklet
javascript:void%20(function(){try{var%20b=window.getSelection(),a=b?b.toString().replace(/(^\W+|\W+$)/g,''):'';if(!a){a=prompt('Enter%20a%20word%20to%20look%20up');if(!a)return}var%20c='http://dictionary.reference.com/search?r=1&q='+encodeURIComponent(a);window.open(c)}catch(d){alert('Oops:\n'+d.message)}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment