GitHub 隐藏 Copilot

在 GitHub 上隐藏愚蠢的 Copilot

当前为 2025-05-18 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GitHub No Copilot
// @name:zh-CN   GitHub 隐藏 Copilot
// @description  Hiding Silly Copilot in GitHub
// @description:zh-CN 在 GitHub 上隐藏愚蠢的 Copilot
// @author       人民的勤务员 <[email protected]>
// @namespace    https://github.com/ChinaGodMan/UserScripts
// @supportURL   https://github.com/ChinaGodMan/UserScripts/issues
// @homepageURL  https://github.com/ChinaGodMan/UserScripts
// @license      MIT
// @match        https://github.com/*
// @icon        https://raw.githubusercontent.com/ChinaGodMan/UserScriptsHistory/main/scriptsIcon/github-commit-viewer.png
// @grant        none
// @compatible   chrome
// @compatible   firefox
// @compatible   edge
// @compatible   opera
// @compatible   safari
// @compatible   kiwi
// @compatible   qq
// @compatible   via
// @compatible   brave
// @version      2025.5.19.1
// @created      2025-05-19 02:19:24
// ==/UserScript==
/**
 * File: github-no-copilot.user.js
 * Project: UserScripts
 * File Created: 2025/05/19,Monday 02:19:25
 * Author: 人民的勤务员@ChinaGodMan ([email protected])
 * -----
 * Last Modified: 2025/05/19,Monday 03:27:16
 * Modified By: 人民的勤务员@ChinaGodMan ([email protected])
 * -----
 * License: MIT License
 * Copyright © 2024 - 2025 ChinaGodMan,Inc
 */

//! 删除顶部的 Copilot
const FUCK_HEAD_COPILOT = true

//! 删除文件右上角的 Copilot
const FUCK_FILE_COPILOT = true

//!https://github.com/dashboard 对话框
const style = document.createElement('style')
style.textContent = `
h2.my-2 {
        display: none !important;
    }
#dashboard > div > div.copilotPreview__container > copilot-dashboard-entrypoint {
    display: none !important;
}
`
document.head.appendChild(style)

function remove() {
    // 无需确认的元素
    const selectors = [
        //dashboard 同上css
        '.copilotPreview__container',

        //dashboard 同上css
        '.copilot-dashboard-entrypoint',

        // 侧边栏
        'a[data-analytics-event*="COPILOT"]'
    ]
    selectors.forEach(selector => {
        document.querySelectorAll(selector).forEach(element => element.remove())
    })

    // 可自定义开启或者关闭的元素
    const ButtonGroup = document.querySelector('#repos-sticky-header [class*=\'ButtonGroup\']')
    const CopilotChat = document.querySelector('.AppHeader-CopilotChat')
    if (FUCK_FILE_COPILOT && ButtonGroup) ButtonGroup.style.display = 'none'
    if (FUCK_HEAD_COPILOT && CopilotChat) CopilotChat.style.display = 'none'

}

new MutationObserver(remove).observe(document.body, {
    childList: true,
    subtree: true
})