-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathhacker_news_date_tooltips.user.js
More file actions
34 lines (29 loc) · 1 KB
/
Copy pathhacker_news_date_tooltips.user.js
File metadata and controls
34 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// ==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/cash-dom@8.1.0/dist/cash.min.js
// @require https://unpkg.com/dayjs@1.10.4/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)
}
})