Under The Hood: Blogger's New Labels

Being unable to help myself, I thought I'd have a quick peek at the label system.

The logical structure of the page (including "widgets" like archives, feeds etc) seem to be encoded in a strange markup and dumped in a giant string in the header. This string is the sole parameter of a function called "_WidgetManager._Init". This function is invoked on page load and is defined in this external script. At this point, my brain boggled and I needed a lie down.

The actual taglabel names and counts are not in the header object literals - they make an appearance via a plain old unordered list in the sidebar. In my view, this is not a good place to keep such crucial information. It should be out in the wider world, making itself useful and mingling with others of its ilk. (Perhaps this will be supported in Blogger's Atom API - but I don't see it.)

To that end, I knocked together a little fragment of (ugly, unsafe) code to extract the labels and counts into a JavaScript object and read it back to you:

javascript: var rexp=/search\?label=(\S+)/i; var cexp=/.*(\d).*/i; var labels={}; var links=document.links; for(var i=0; i<links.length;i++) if (l=rexp.exec(links[i].href)) if (!links[i].rel) labels[l[1]]=cexp.exec(links[i].nextSibling.nodeValue)[1]; for (var j in labels) alert(j+' ['+ labels[j]+']')

(load up a beta blog and copy/paste this code into your browser address bar to watch the magic unfold.)

Here's another code snippet to transform Google's labels into a form a little more familiar to delicious JSON feed users:

javascript: var rexp=/search\?label=(\S+)/i; var cexp=/.*(\d).*/i; var labels={}; var links=document.links; for(var i=0; i<links.length;i++) if (l=rexp.exec(links[i].href)) if (!links[i].rel) labels[l[1]]=cexp.exec(links[i].nextSibling.nodeValue)[1]; var str="if(typeof(Delicious) == 'undefined') Delicious = {}; Delicious.tags = {"; for (var j in labels) str+='"'+j+'":'+labels[j]+','; str+="};"; document.write(str);

Does that get your creative juices flowing?

Filed in: , , , ,

See also: