Sort Github repos by popularity

Sort user's Github repositories by popularity (only applies to those visible on the current page)

  1. // ==UserScript==
  2. // @name Sort Github repos by popularity
  3. // @namespace http://tampermonkey.net/
  4. // @license MIT
  5. // @version 0.1.4
  6. // @description Sort user's Github repositories by popularity (only applies to those visible on the current page)
  7. // @author joeytwiddle
  8. // @include https://github.com/*tab=repositories*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. if (document.location.search.split(/[&?]/).some(x => x === "tab=repositories")) {
  16. // Proceed
  17. } else {
  18. // Wrong page
  19. return;
  20. }
  21.  
  22. const container = document.querySelector('#user-repositories-list > ul');
  23. const reposNodeList = document.querySelectorAll('#user-repositories-list > ul > li');
  24. const repos = Array.prototype.slice.call(reposNodeList);
  25.  
  26. //console.log("Repo count:", repos.length);
  27.  
  28. repos.reverse().forEach(ul => {
  29. container.removeChild(ul);
  30. });
  31.  
  32. repos.sort((a, b) => getPopularity(a) < getPopularity(b) ? +1 : -1);
  33.  
  34. repos.forEach(ul => {
  35. container.appendChild(ul);
  36. });
  37.  
  38. function getPopularity (li) {
  39. const starSvg = li.querySelector('[aria-label=star]');
  40. const textElem = starSvg && starSvg.nextSibling;
  41. const popularity = textElem && Number(textElem.textContent.replace(/,/g, '')) || 0;
  42. //console.log("Popularity:", popularity);
  43. return popularity;
  44. }
  45. }());

QingJ © 2025

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