GitHub Trending star 排序回归

调整 GitHub Trending 页, 数据排序逻辑

// ==UserScript==
// @name         GitHub Trending star 排序回归
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  调整 GitHub Trending 页, 数据排序逻辑
// @author       pozhu
// @include      https://github.com/trending*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    "use strict";
    [...document.getElementsByClassName("Box-row")]
        .map((item) => {
            const reg = /Built by\s+(.+) stars/g;
            const stars = reg.exec(item.innerText)[1].replace(",", "");
            return { stars, node: item };
        })
        .sort((a, b) => b.stars - a.stars)
        .forEach((item) => {
            item.node.parentNode.appendChild(item.node);
        });
})();