Friday, August 22, 2008

Bookmarklets

Bookmarklets is a little javascript code you can put directly into your firefox/IE "bookmarks(favorites)". So when you select the bookmark, it will execute the code and enhance your functionality of the browser. Bookmarklets have been around since IE4, and I find them quite handy. There are bookmarklets to autofill forms, to cut-and-paste, to select text and bring up a search engine and several other uses. I recently created a bookmarklet to rid myself of the annoyance when some sites use redirects, which causes either the form to appear as illustrated, or the firewall to block the site entirely.


The link appears as:
Notice that the actual link I want to read is a URL parameter and is percent encoded. Now I have to fill out this form every time I need to read an article on LSJ. Clicking on the Bookmarklet helps me grab the actual link which is:

For IE the easiest to create this bookmarklet is by adding a dummy bookmark (like this web page), then edit its properties:
Click on "Favorites", then RIGHT-CLICK on the link you added and select "properties" from the context menu.
In the "properties" window, click on "General" Tab. Now change the name of the bookmark to "UNESCAPE". Next, click on the "Web Document" tab and paste the following code for URL:
javascript:void(pos=location.href.search("=http%253A"));
if(pos=-1)void(pos=location.href.search("=http%"));
if(pos>-1)location.href=
unescape(unescape(location.href.slice(pos+1)))
Note the entire code is the url address, so it should be in a single line and without any spaces in between it. Now click on "Apply" and you will see a message:
"The protocol javascript does not have a registered program".
Click "Yes" to keep it anyway. Click OK, and then "Yes" again. Congratulations, you just made your first bookmarklet.