github显示仓库信息

Add ⌛creation date/🍴forks/📁 repo size to repo search result page,code search page and repo detail page.

当前为 2022-11-12 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         github-repo-info
// @name:zh-CN   github显示仓库信息
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Add ⌛creation date/🍴forks/📁 repo size to repo search result page,code search page and repo detail page.
// @description:zh-cn 向仓库搜索页,代码搜索页,仓库主页添加 ⌛创建时间/🍴fork数/📁文件大小显示
// @author       CXXN008
// @match        *://github.com/*/*
// @match        *://github.com/search*
// @source       https://github.com/CXXN008/github-repo-info
// @icon         https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant        window.onurlchange
// @license      MIT
// ==/UserScript==



'use strict';
// github free rates are limited to 5000 / hour ,if u get some errors in console , try https://github.com/settings/tokens -> Generate new token & paste here
const API_TOKEN = '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'
const STYLE = ``

const PAGE_SELECTOR = { 'search': 'li.repo-list-item> div > div> div > a.v-align-middle', 'repo': 'strong.mr-2 > a:nth-child(1)', 'code': '.Link--secondary' }

let hasLoaded = false

const getPageType = (urlParams) => {
    const q = urlParams.get("q")?.toLocaleLowerCase();
    const type = urlParams.get("type")?.toLocaleLowerCase();
    if (q) {
        if (type === 'code') {
            return 'code'
        } else {
            return 'search'
        }
    } else {
        return 'repo'
    }
}

const fireUp = () => {

    // console.log(c)
    const params = {
        "headers": {
            "authorization": `token ${API_TOKEN}`,
        }
    }

    const pageType = getPageType(new URLSearchParams(location.search))
    // console.log(pageType)
    document.querySelectorAll(PAGE_SELECTOR[pageType]).forEach(async e => {
        const p = e.parentElement
        let span = p.querySelector(`#my-span-tag`)
        if (span === null) {
            span = document.createElement('span')
            span.id = 'my-span-tag'
            span.style = STYLE
            span.innerText = '... ...'
            p.append(span)
        }

        const j = (await (await fetch(`https://api.github.com/repos${e.getAttribute('href')}`, params)).json())

        const date = j.created_at.split('T')[0]
        const size = (j.size / 1024).toFixed(2)
        const forks = j.forks_count

        span.innerText = `/⌛${date}/🍴${forks}/📁${size}MB`




    })
}

window.onurlchange = (c) => {
    if (!hasLoaded) {
        hasLoaded = true
        return
    }
    fireUp()
}

fireUp()