Hacker News Date Tooltips

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

当前为 2016-09-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. // @namespace https://github.com/chocolateboy/userscripts
  7. // @version 0.0.1
  8. // @license GPL: http://www.gnu.org/copyleft/gpl.html
  9. // @include https://news.ycombinator.com/*
  10. // @require https://code.jquery.com/jquery-3.1.0.min.js
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.0/moment.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. var DELTA = 1, UNIT = 2;
  19.  
  20. var 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. var match = ago.match(/^(\d+)\s+(\w+)\s+ago$/);
  26. var date;
  27.  
  28. if (match) {
  29. date = moment().subtract(match[DELTA], match[UNIT]).format('YYYY-MM-DD');
  30. }
  31.  
  32. return date;
  33. }
  34.  
  35. $(DATES).each(function () {
  36. var $this = $(this);
  37. var ago = $.trim($this.text());
  38. var date = isoDate(ago);
  39.  
  40. if (date) {
  41. $this.attr('title', date);
  42. }
  43. });

QingJ © 2025

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