GitHub commit timestamps

Displays absolute time for commits (if less than 18 hours ago)

  1. // ==UserScript==
  2. // @name GitHub commit timestamps
  3. // @namespace http://rasmuswriedtlarsen.com
  4. // @version 0.3
  5. // @description Displays absolute time for commits (if less than 18 hours ago)
  6. // @match https://github.com/*
  7. // @copyright 2014, Rasmus Wriedt Larsen
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/sugar/1.3.9/sugar.min.js
  10. // ==/UserScript==
  11.  
  12. var msPrHour = 60 * 60 * 1000;
  13.  
  14. counter = 0
  15.  
  16. var updateTimes = function(event) {
  17. //console.log(counter++)
  18.  
  19. $("time.js-relative-date").each( function () {
  20. var commitTime = new Date ($(this).attr("datetime"));
  21. var diff = (Date.now() - commitTime);
  22.  
  23. newTitle = commitTime.format("{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}")
  24.  
  25. if ( diff < 18 * msPrHour)
  26. {
  27. var formattedTime = commitTime.format("{HH}:{mm}")
  28.  
  29. $(this).html(formattedTime);
  30. $(this).removeClass("js-relative-date");
  31. }
  32.  
  33. $(this).attr("title", newTitle)
  34. });
  35. };
  36.  
  37. // setInterval( function(){$('time').change();}, 5 * 1000 );
  38.  
  39. // $('time').change();
  40.  
  41. function init()
  42. {
  43. // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything
  44. if (!(document.documentElement instanceof HTMLElement))
  45. return;
  46.  
  47. updateTimes(null);
  48. // TODO: very hacky solution to updating when page reloads ...
  49. document.addEventListener("DOMNodeInserted", updateTimes, true);
  50. }
  51.  
  52. // In Chrome 18 the document might not be initialized yet
  53. if (document.documentElement)
  54. init();
  55. else
  56. window.setTimeout(init, 0);