Sort Github repos by popularity

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

目前为 2018-04-10 提交的版本。查看 最新版本

// ==UserScript==
// @name         Sort Github repos by popularity
// @namespace    http://tampermonkey.net/
// @license      MIT
// @version      0.1.2
// @description  Sort user's Github repositories by popularity (only applies to those visible on the current page)
// @author       joeytwiddle
// @match        https://github.com/*tab=repositories*
// @grant        none
// ==/UserScript==

setTimeout(function() {
  'use strict';

  if (document.location.search.split('&').some(x => x === "tab=repositories")) {
    // Proceed
  } else {
    // Wrong page
    return;
  }

  const container = document.querySelector('#user-repositories-list > ul');
  const reposNodeList = document.querySelectorAll('#user-repositories-list > ul > li');
  const repos = Array.prototype.slice.call(reposNodeList);

  //console.log("Repo count:", repos.length);

  repos.reverse().forEach(ul => {
    container.removeChild(ul);
  });

  repos.sort((a, b) => getPopularity(a) < getPopularity(b) ? +1 : -1);

  repos.forEach(ul => {
    container.appendChild(ul);
  });

  function getPopularity (li) {
    const starSvg = li.querySelector('[aria-label=star]');
    const textElem = starSvg && starSvg.nextSibling;
    const popularity = textElem && Number(textElem.textContent) || 0;
    //console.log("Popularity:", popularity);
    return popularity;
  }
}, 10);

QingJ © 2025

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