One of the changes I made to this site when Blogger added some features a couple days ago was that I am now using on-site comments. To accommodate, the template was changed, removing my old Haloscan comment links. Haloscan had served me well, but it was time to move on.
The problem, now, is that all of that great discussion (I exaggerate just a bit) is lost in cyberspace.
Worry no more! Introducing the Old Comments Bookmarklet. With a single click of the mouse, links to old discussions appear next to every post. This automagical piece of Javascript works on Mozilla and Opera, and probably a few others that have not been tested. Sorry, Explorers, but I do not feel like debugging my code to work in a sub-par browser. Think of this as marketing, though if somebody actually does figure out how to fix it, I would probably accept a patch, or at least offer both versions.
For those of you that do indeed have standard-compliant browsers, all you have to do is add the Old Comments for Lenny's Weblog link to your bookmarks, and click it on any archive page.
Whoosh! With practically no effort on your part, you suddenly have an elegant link reading "Old Comments", even spaced properly with a '|'.This happens to be the first bookmarklet of any complexity that I have ever written. For those of you that care, here is the whitespaced and commented source code.
// (c) 2004, by Lenny Domnitser. GPL'd.
// select all divs
divs = document.getElementsByTagName('div');
// loop through all divs
for(var c = 0; c < divs.length; c++) {
// only keep divs that are posts (i.e. are the string "post" followed by numbers)
if(divs[c].hasAttribute('id') && divs[c].getAttribute('id').match(/^post\d+$/) != null) {
// the paragraph with the comment information is the third child node
var infoPara = divs[c].childNodes[3];
// comments are only for full posts (i.e. class == 'info'),
// not just lists of links (i.e. class == 'miniinfo')
if(infoPara.getAttribute('class') == 'info') {
// the post id. could have defined this before to save code space. too lazy to change.
var id = divs[c].getAttribute('id');
// create the link
var anchor = document.createElement('a');
// construct the haloscan URL based on the id (see couple of lines back)
anchor.setAttribute('href', 'http://www.haloscan.com/comments.php?user=ldrhcp&comment=' + id.substring(4, id.length));
// make it a popup
anchor.setAttribute('onclick', 'javascript:open(href, \'_blank\', \'width = 420, height = 500, resizable, scrollbars\'); return false');
// give it link text
anchor.appendChild(document.createTextNode('Old Comments'));
// add the spacer and the link to the paragraph
infoPara.appendChild(document.createTextNode(' | '));
infoPara.appendChild(anchor);
}
}
}