Sort Github repos by popularity

Sort user's Github repositories by popularity

Stan na 10-04-2018. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Sort Github repos by popularity
// @namespace    http://tampermonkey.net/
// @license      MIT
// @version      0.1
// @description  Sort user's Github repositories by popularity
// @author       joeytwiddle
// @match        https://github.com/*?tab=repositories
// @grant        none
// ==/UserScript==

setTimeout(function() {
    'use strict';

    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.sort((a, b) => {
        return getPopularity(a) < getPopularity(b) ? +1 : -1;
    });

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

    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;
    }
}, 1000);