Hacker News Date Tooltips

Deobfuscate the "n days ago" dates on Hacker News with YYYY-MM-DD tooltips

Versione datata 23/09/2016. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name          Hacker News Date Tooltips
// @description   Deobfuscate the "n days ago" dates on Hacker News with YYYY-MM-DD tooltips
// @author        chocolateboy
// @copyright     chocolateboy
// @namespace     https://github.com/chocolateboy/userscripts
// @version       0.0.1
// @license       GPL: http://www.gnu.org/copyleft/gpl.html
// @include       https://news.ycombinator.com/*
// @require       https://code.jquery.com/jquery-3.1.0.min.js
// @require       https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.0/moment.min.js
// @grant         GM_log
// ==/UserScript==

// XXX note: the unused grant is a workaround for a Greasemonkey bug:
// https://github.com/greasemonkey/greasemonkey/issues/1614

var DELTA = 1, UNIT = 2;

var DATES = $('html').attr('op') == 'user' ?
    'table:eq(-1) tr:eq(1) td:eq(-1)' :
    'span.age a';

function isoDate (ago) {
    var match = ago.match(/^(\d+)\s+(\w+)\s+ago$/);
    var date;

    if (match) {
        date = moment().subtract(match[DELTA], match[UNIT]).format('YYYY-MM-DD');
    }

    return date;
}

$(DATES).each(function () {
    var $this = $(this);
    var ago   = $.trim($this.text());
    var date  = isoDate(ago);

    if (date) {
        $this.attr('title', date);
    }
});