del.icio.us に はてなブックマークカウンタを付けてみる。

誰かが作ってるとは思うけど。



// ==UserScript==
// @include http://del.icio.us/*
// ==/UserScript==

(function() {
    var base_uri   = 'http://b.hatena.ne.jp/entry/';
    var image_base = 'http://b.hatena.ne.jp/entry/image/';

    var post = document.evaluate(
        '//li[@class="post"]',
        document.body,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );

    for(var i=0,len=post.snapshotLength;i<len;i++) {
        var link_node_path;
        var insert_node_path;

        if(post.snapshotItem(i).getElementsByTagName('table')[0]) {
            link_node_path   = './table/tbody/tr/td/div/h4/a';
            insert_node_path = './table/tbody/tr/td/div/div[@class="meta"]';
        } else {
            link_node_path   = './h4/a';
            insert_node_path = './div[@class="meta"]'
        }

        var post_uri     = document.evaluate(
            link_node_path,
            post.snapshotItem(i),
            null,
            XPathResult.FIRST_ORDERED_NODE_TYPE,
            null
        ).singleNodeValue.href;

        var insert_node = document.evaluate(
            insert_node_path,
            post.snapshotItem(i),
            null,
            XPathResult.FIRST_ORDERED_NODE_TYPE,
            null
        ).singleNodeValue;

        var after_node = document.evaluate(
            './span[@class="date"]',
            insert_node,
            null,
            XPathResult.FIRST_ORDERED_NODE_TYPE,
            null
        ).singleNodeValue;

        var spn = document.createElement('span');
        spn.appendChild(document.createTextNode('... '));
        spn.setAttribute('style', 'margin-right:5px');

        var anc = document.createElement('a');
        anc.href = base_uri + escape(post_uri);

        var img = document.createElement('img');
        img.setAttribute('src', image_base + escape(post_uri));
        img.setAttribute('alt', 'hatebu_counter');
        img.setAttribute('style', 'border:0');

        anc.appendChild(img);
        spn.appendChild(anc)

        insert_node.insertBefore(spn, after_node);
    }
})();

修正 2/17 19:12

flickr の 写真があるとうまく動かないのを修正