Github-time-format-changer

Change Github time format.

目前為 2014-05-18 提交的版本,檢視 最新版本

  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. // @license MIT
  8. // @description Change Github time format.
  9. // @include https://github.com/*
  10. // @run-at document-end
  11. // @grant none
  12. // @require https://cdn.jsdelivr.net/momentjs/2.6.0/moment.min.js
  13. // ==/UserScript==
  14.  
  15. var $ = unsafeWindow.$;
  16. var toArray = Function.prototype.call.bind(Array.prototype.slice);
  17. var relative = /ago/i;
  18. function _update(body) {
  19. var times = body.getElementsByTagName("time");
  20. toArray(times).forEach(function (timeElement) {
  21. if (!relative.test(timeElement.textContent)) {
  22. timeElement.textContent = moment(timeElement.getAttribute("datetime")).fromNow();
  23. }
  24. });
  25. }
  26. function update(body) {
  27. requestAnimationFrame(function () {
  28. _update(body);
  29. });
  30. }
  31. $(document).on('pjax:end', function pjaxEnd() {
  32. update(document.body);
  33. });
  34. var addFilterHandler = function (evt) {
  35. var node = evt.target;
  36. update(node);
  37. };
  38. document.body.addEventListener('AutoPagerize_DOMNodeInserted', addFilterHandler, false);
  39. // MAIN =
  40. update(document.body);