Hacker News Date Tooltips

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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
// @version       1.1.0
// @namespace     https://github.com/chocolateboy/userscripts
// @license       GPL: https://www.gnu.org/copyleft/gpl.html
// @include       https://news.ycombinator.com/*
// @require       https://cdn.jsdelivr.net/npm/[email protected]/dist/cash.min.js
// @require       https://unpkg.com/[email protected]/dayjs.min.js
// @grant         GM_log
// ==/UserScript==

const DATES = 'span.age a'
const DELTA = 1, UNIT = 2

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

    return match
        ? dayjs().subtract(match[DELTA], match[UNIT]).format('YYYY-MM-DD')
        : null
}

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

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