URL Unescape bookmarklet

Recently in troubleshooting bad links and dangerous querystring params on the site I work on for my day job, I’ve repeatedly had to unescape url encoded strings.  I can never remember what the codes mean, so I inevitably google for url escaping and trying to piece together what I’m looking at.

After a few rounds of this I decided that automating this task would be a fun little javascript exercise and would save me time (eventually). Enter my first bookmarklet, the

Unescape

bookmarklet.

It looks for selected text in the window and unescapes that. If there isn’t any selected it prompts you for something to unescape. Tested in Safari/Windows, Chrome, and Firefox 4. Also sort of works in IE, but I had to add some hackery around the selection for IE, and if IE security settings prevent the prompt() call without approval the first click of the bookmarklet returns null. I may be missing something in the javascript, so suggestions for improvement are welcome, especially around the IE handling.  An expanded version of the bookmarklet can be found in this gist.

Enjoy!!

UPDATE

I found the problem with my javascript that necessitated the hacky handling in IE, and much to my surprize (not) IE was actually sort of doing the right thing.

If you look at the edit history of the gist you can see what I was doing was essentially alerting the unescaped version of the anonymous function I had created. Firefox and the other browsers decided that I really meant to use the results of the function and not the function itself and helpfully evaled the function and used the returned value. IE took me at my word and altered the function object assigned to the sel variable. Once I corrected the code to make sure that the was calling the funciton and using its returned value, all the hackery I had to do to get IE to work went away.

Updated bookmarklet code above.

Oh, and it also occurs to me that this wasn’t my first bookmarklet – I created a day of the year bookmarklet a while back that I’ll post here sometime.