// ==UserScript==
// @name    del.icio.us replace date
// @include http://del.icio.us/*
// @exclude http://del.icio.us/recent*
// ==/UserScript==

(function() {
    // http://d.hatena.ne.jp/higeorange/20070221/1172029913
    Date.prototype.format = function(str) {
        var date = {
            "%Y" : this.getFullYear(),
            "%M" : this.getMonth() + 1,
            "%D" : this.getDate(),
            "%W" : (["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"])[this.getDay()],
            "%h" : this.getHours(),
            "%m" : this.getMinutes(),
            "%s" : this.getSeconds()
        }
        return str.replace(
            /(%Y)|(%M)|(%D)|(%W)|(%h)|(%m)|(%s)/g,
            function(e) {
                if(e != "%Y" && e != "%W") {
                    return (date[e] < 10) ? "0" + date[e] : date[e];
                } else {
                    return date[e];
                }
            }
        );
    }

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

    for(var i=0,len=date.snapshotLength;i<len;i++) {
        date.snapshotItem(i).innerHTML = date.snapshotItem(i).getAttribute('title').replace(
            /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z/,
            function($0, $1, $2, $3, $4, $5, $6) {
                return ' ' + new Date(Date.UTC($1, $2-1, $3, $4, $5, $6)).format("%Y-%M-%D %h:%m");
            }
        );
    }
})();


