GitHub: Issue sort:updated-desc Button

Add top level button to sort both issues/pull requests by the most recently updated.

目前為 2016-01-27 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GitHub: Issue sort:updated-desc Button
  3. // @description Add top level button to sort both issues/pull requests by the most recently updated.
  4. // @author Chris H (Zren / Shade)
  5. // @icon https://github.com/favicon.ico
  6. // @namespace http://xshade.ca
  7. // @version 2
  8. // @include https://github.com*
  9. // ==/UserScript==
  10.  
  11. (function(uw){
  12. var $ = uw.$;
  13. var createElement = function(html) {
  14. var e = document.createElement('div');
  15. e.innerHTML = html;
  16. return e.firstChild;
  17. };
  18.  
  19. var blameUrlPattern = /^https:\/\/github.com\/[^\/]+\/[^\/]+\/(issues|pulls)/;
  20.  
  21. var main = function() {
  22. var m = blameUrlPattern.exec(document.location.href);
  23. if (!m)
  24. return;
  25. if (document.getElementById('sort-issues-recently-updated'))
  26. return;
  27.  
  28. Array.prototype.forEach.call(document.querySelectorAll('.table-list-header-toggle.right'), function(e) {
  29. var url = m[0] + '?q=sort%3Aupdated-desc';
  30. var html = '<div class="left"><a id="sort-issues-recently-updated" class="btn-link icon-only js-menu-target" role="button" aria-haspopup="true" style="padding-right: 15px; padding-left: 15px;" href="' + url + '">sort:recently-updated</a></div>';
  31. var a = createElement(html);
  32. e.insertBefore(a, e.firstChild);
  33. });
  34. };
  35.  
  36. main();
  37. $(document).on('pjax:end', main);
  38.  
  39. })(typeof unsafeWindow === 'undefined' ? window : unsafeWindow);