// ==UserScript==
// @name        del.icio.us Thumbnails
// @description add thumbnails del.icio.us post 
// @include     http://del.icio.us/*
// @exclued     http://del.icio.us/help/*
// ==/UserScript==

(function () {
    var template = [
        '<table border="0" cellpadding="0" cellspacing="0">',
            '<tr>',
                '<td style="padding-right: 1em">',
                    '<a href="#{link}" rel="nofollow">',
                        '<img src="#{link}" width="75" height="75" border="0" alt="#{title}" />',
                    '</a>',
                '</td>',
                '<td><div>',
                    '<h4 class="desc"><a href="#{link}" rel="nofollow">#{title}</a>',
                    '<em class="flickr-thumbnai-hook"></em> </h4>',
                    '#{commands}',
                    '#{meta}',
                '</div></td>',
            '</tr>',
        '</table>'
    ].join('');

    var entry = document.evaluate('//li[@class="post"]', document, null ,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    var content = {};
    for(var i = 0, item, len = entry.snapshotLength; i < len; i++) {
        item = entry.snapshotItem(i);
        content.link = item.getElementsByTagName('a')[0].href;
        if(content.link.match(/(jpe?g|png|gif)$/i)) {
            content.title = item.getElementsByTagName('a')[0].innerHTML;
            content.commands = item.getElementsByTagName('div')[0].outerHTML;
            content.meta = item.getElementsByTagName('div')[1].outerHTML;

            item.innerHTML = template.replace(/#{(\w+)}/g, function($0, $1) {
                return content[$1];
            });
        }
    }
})();
