Sort Github repos by popularity

Sort user's Github repositories by popularity

目前為 2018-04-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);