Sort Github repos by popularity

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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

(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.replace(/,/g, '')) || 0;
    //console.log("Popularity:", popularity);
    return popularity;
  }
}());