Greasy Fork

Greasy Fork is available in English.

Github显示具体Star数字

让Star/Fork等显示完整的数字

当前为 2019-12-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Github显示具体Star数字
// @namespace    http://tampermonkey.net/
// @homeurl      https://github.com/xiandanin/LardMonkeyScripts
// @homeurl      http://greasyfork.icu/zh-CN/scripts/391285
// @version      0.3
// @description  让Star/Fork等显示完整的数字
// @author       xiandan
// @match        https://github.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict'


    function extractNumber (str) {
        let reg = /\d+/
        let match = reg.exec(str)
        return parseInt(match ? match[0] : str)
    }

    function formatNumber (num) {
        return num.toString().replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, "$1,")
    }

    function applyNodeNumber () {
        // 过滤出需要设置 并且有详细数字的节点
        const socialCountNodes = document.querySelectorAll(".social-count")
        if (socialCountNodes && socialCountNodes.length > 0) {
            for (let i = 0; i < socialCountNodes.length; i++) {
                const node = socialCountNodes[i]
                let countStr = node.getAttribute("aria-label")
                if (countStr) {
                    if (/^\d+$/.test(node.innerText)) {
                        // 如果已经是纯数字
                    } else {
                        const countStr = node.getAttribute("aria-label")
                        node.innerText = formatNumber(extractNumber(countStr))
                    }
                }
            }
        }
    }


    const main = document.querySelector('#js-repo-pjax-container')
    const observer = new MutationObserver(function (mutations, observer) {
        applyNodeNumber()
    })
    observer.observe(main, {
        childList: true
    })
    applyNodeNumber()

})()