Hacker News Date Tooltips

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

当前为 2018-04-24 提交的版本,查看 最新版本

  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. // @namespace https://github.com/chocolateboy/userscripts
  7. // @version 1.0.0
  8. // @license GPL: http://www.gnu.org/copyleft/gpl.html
  9. // @include https://news.ycombinator.com/*
  10. // @require https://code.jquery.com/jquery-3.3.1.min.js
  11. // @require https://unpkg.com/dayjs@1.5.11/dist/dayjs.min.js
  12. // @grant GM_log
  13. // ==/UserScript==
  14.  
  15. // XXX note: the unused grant is a workaround for a Greasemonkey bug:
  16. // https://github.com/greasemonkey/greasemonkey/issues/1614
  17.  
  18. const DELTA = 1, UNIT = 2
  19.  
  20. const DATES = $('html').attr('op') === 'user' ?
  21. 'table:eq(-1) tr:eq(1) td:eq(-1)' :
  22. 'span.age a'
  23.  
  24. function isoDate (ago) {
  25. const match = ago.match(/^(\d+)\s+(\w+)\s+ago$/)
  26. let date
  27.  
  28. if (match) {
  29. date = dayjs().subtract(match[DELTA], match[UNIT]).format('YYYY-MM-DD')
  30. }
  31.  
  32. return date
  33. }
  34.  
  35. $(DATES).each(function () {
  36. const $this = $(this)
  37. const ago = $.trim($this.text())
  38. const date = isoDate(ago)
  39.  
  40. if (date) {
  41. $this.attr('title', date)
  42. }
  43. })

QingJ © 2025

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