Hacker News Date Tooltips

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

当前为 2021-02-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hacker News Date Tooltips
  3. // @description Deobfuscate the "n days ago" dates on Hacker News with YYYY-MM-DD tooltips
  4. // @author chocolateboy
  5. // @copyright chocolateboy
  6. // @version 1.1.0
  7. // @namespace https://github.com/chocolateboy/userscripts
  8. // @license GPL: https://www.gnu.org/copyleft/gpl.html
  9. // @include https://news.ycombinator.com/*
  10. // @require https://cdn.jsdelivr.net/npm/cash-dom@8.1.0/dist/cash.min.js
  11. // @require https://unpkg.com/dayjs@1.10.4/dayjs.min.js
  12. // @grant GM_log
  13. // ==/UserScript==
  14.  
  15. const DATES = 'span.age a'
  16. const DELTA = 1, UNIT = 2
  17.  
  18. function isoDate (ago) {
  19. const match = ago.match(/^(\d+)\s+(\w+)\s+ago$/)
  20.  
  21. return match
  22. ? dayjs().subtract(match[DELTA], match[UNIT]).format('YYYY-MM-DD')
  23. : null
  24. }
  25.  
  26. $(DATES).each(function () {
  27. const $this = $(this)
  28. const ago = $this.text().trim()
  29. const date = isoDate(ago)
  30.  
  31. if (date) {
  32. $this.attr('title', date)
  33. }
  34. })

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址