remove Top repositories

去除Top repositories中不属于自己的仓库

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         remove Top repositories
// @version      1.0.0
// @namespace    https://github.com/girl-dream
// @description  去除Top repositories中不属于自己的仓库
// @author       骑着老王闯天下
// @license      The Unlicense
// @match        https://github.com/
// @icon         https://github.com/favicon.ico
// @grant        none
// ==/UserScript==


(function () {
    'use strict'
    let RepositoriesDom = document.querySelector('.dashboard-sidebar')
    let userName = RepositoriesDom.querySelector('.Button-label').lastChild.textContent
    if (!userName) return

    function run(ul) {
        for (let i = ul.length - 1; i >= 0; i--) {
            if (!ul[i].getElementsByTagName("a")[1].textContent.includes(userName)) {
                ul[i].remove()
            }
        }
    }
    let timer = setInterval(() => {
        let ul = RepositoriesDom.querySelector('.list-style-none').children
        if (ul.length > 0) {
            clearInterval(timer)
            run(ul)

            let temp = ul.length
            let a = RepositoriesDom.querySelector('.js-repos-container').getElementsByTagName("button")[0]
            a.addEventListener("click", () => {
                let timer = setInterval(() => {
                    let ul = RepositoriesDom.querySelector('.list-style-none').children
                    if (ul.length > temp) {
                        clearInterval(timer)
                        run(ul)
                    }
                })
            })
        }
    }, 500)
})();