Thursday, June 29, 2006

Bookmarklet for one-click tagging in del.icio.us

One click "read later" del.icio.us bookmarklet.

I often come across webpages that i want to read later, but I don't really have time to tag and describe each of them properly. So have a del.icio.us tag called xyzpdq (some people use 'toread' or 'to_read' or 'unread' etc.) that i use to tag pages to be read when i have more time. But even that takes longer than I want it to. I have to click on the "post to del.icio.us" bookmarklet, then click in the "tags" box, then type "xyzpdq," and then click save. Too much work. It should be easier. I mean, all I want to do is mark it to be read later, right?

I looked all over the web but couldn't find a bookmarklet that did this in a single click. Some came close, but usually required an additional click or two at least, and that's exactly what i was trying to avoid. Others automatically tagged the page with del.icio.us's suggested tags, and I don't like the idea of using tags that aren't my own or that I might disagree with.

So I've put together a bookmarklet that accomplishes my goal with ONE CLICK. I just click on it and continue working while del.icio.us does it's thing in the background. Basically, when I click on the bookmarklet, a window pops up behind the current browser window (so it doesn't get in your way), posts the page to my del.icio.us account with the 'xyzpdq' tag, and then closes the popup window a few seconds later, all without any additional input from me. I freaking love this bookmarklet!!

You can customize it by replacing xyzpdq in the code with a tag (or tags, separated by spaces) of your choice.

And you could have several of these bookmarklets if you wanted to. I often want to mark pages that I think my boyfriend, Fishy, would find interesting. So I could have a 2nd bookmarklet where I've replaced 'xyzpdq' with 'for:Fishy'sUserName'. Or with any other specific tag or tags you use frequently.

Here's a bookmarklet you can add to your toolbar (don't forget to change USERNAME to your own username):

bookmarklet

Here's the actual code snippet, broken into multiple lines for easier reading:

javascript:void(child_win=open('http://del.icio.us/api/posts/add?
tags=xyzpdq&
user=USERNAME&description='+encodeURIComponent
(document.title)+'&url=
'+window.location.href,'delicious','toolbar=no,
width=500,height=150'));setTimeout
(%22child_win.close()%22,5000);
window.replace(-1);


Understanding:

It assumes you're already logged into del.icio.us. Otherwise you should be prompted to do so.

If you have previously tagged the page, this bookmarklet will replace all of the tags for that page with the xyzpdq tag. If this is a concern to you, you can add (without the quotes) "&replace=no" right after the xyzpdq and before the word 'description', which will cause del.icio.us not to change your existing tags for that page and not to add the xyzpdq tag. I would much prefer to simply append xyzpdq onto any existing list of tags, but i can't figure out how to do that, so if anyone else does, please lemme know.

The popup window closes 5 seconds after it opens. That's just a safeguard built in to allow enough time to contact the del.icio.us server, but i've never had problems even when I didn't have the delay built-in. You can adjust the delay time by changing the number 5000 at the end of the code. (5000=5 seconds, 10000=10 seconds, 500 = a half second, etc.) Since the popup window is behind your active browser window, it really doesn't matter that it's hanging there a few seconds before disappearing.

This bookmarklet was inspired in part by the lazy sheep bookmarklet, which is worth checking out, although it really doesn't do what i wanted it to, and it has the additional disadvantage of relying on a third-party server. But I did examine the javascript when I was creating the oneclick bookmarklet

disclaimer: i do not know javascript. I pieced this together (with some additional help from Fishy) from other bookmarklets out there. I've only tested it on Firefox 1.5.0.4, but I don't see why it shouldn't work with other browsers.

I hope you find it as useful as I do!

No comments: