Github:time-format-changer

Change Github time format.

Fra 18.05.2014. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @id github.com-ff599db1-47d8-b14f-83b4-3e345f6d67e3@http://efcl.info/
  3. // @name Github:time-format-changer
  4. // @version 1.0
  5. // @namespace http://efcl.info/
  6. // @author azu
  7. // @description Change Github time format.
  8. // @include https://github.com/*
  9. // @run-at document-end
  10. // @require https://cdn.jsdelivr.net/momentjs/2.6.0/moment.min.js
  11. // ==/UserScript==
  12.  
  13. var $ = unsafeWindow.$;
  14. var toArray = Function.prototype.call.bind(Array.prototype.slice);
  15. var relative = /ago/i;
  16. function _update(body){
  17. var times = body.getElementsByTagName("time");
  18. toArray(times).forEach(function(timeElement){
  19. if(!relative.test(timeElement.textContent)){
  20. timeElement.textContent = moment(timeElement.getAttribute("datetime")).fromNow();
  21. }
  22. });
  23. }
  24. function update(body){
  25. requestAnimationFrame(function(){ _update(body); });
  26. }
  27. $(document).on('pjax:end', function pjaxEnd() {
  28. update(document.body);
  29. });
  30. var addFilterHandler = function(evt){
  31. var node = evt.target;
  32. update(node);
  33. }
  34. document.body.addEventListener('AutoPagerize_DOMNodeInserted', addFilterHandler, false);
  35. // MAIN =
  36. update(document.body);