Github中文搜索净化

Github中文搜索净化,屏蔽特定用户群

当前为 2024-08-03 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Github中文搜索净化
// @namespace    http://danke666.top/
// @version      1.5
// @author       DanKe
// @description  Github中文搜索净化,屏蔽特定用户群
// @match        https://github.com/search*
// @match        https://github.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 定义要检测和删除的用户名列表
    const usernamesToRemove = [
        'cirosantilli', //我去你妈了个表就是你这私人东西祸害环境
        'tjqJ62cESiHPj6DdR6vXDAcPp',
        'Bellum45',
        'Daravai1234',
        'cheezcharmer',
        'chinese-dictatorship',
        'Daravai1234',
        'b0LBwZ7r5HOeh6CBMuQIhVu3-s-random-fork',
        'random-fork',
        'zpc1314521',
        'jjzhang166',
        '1lixia',
        'panbinibn',
        'zaohmeing',
        'zhaohmng-outlook-com',
        'pxvr-official',
    ];

    function addBlockedNotice() {
        const resultsList = document.querySelector('div[data-testid="results-list"]');
        if (resultsList) {
            const notice = document.createElement('div');
            notice.style.cssText = 'text-align: center; padding: 10px; margin: 10px; background-color: #f9f9f9; border: 1px solid #e1e4e8;';
            notice.textContent = '已屏蔽不受欢迎的仓库';
            resultsList.appendChild(notice);
        }
    }

    function removeElementsWithUsername() {
        const resultsList = document.querySelector('div[data-testid="results-list"]');
        if (resultsList) {
            const userElements = resultsList.querySelectorAll('.Box-sc-g0xbh4-0');
            let hasRemoved = false;
            userElements.forEach(element => {
                const usernameElement = element.querySelector('a[href^="/"]');
                if (usernameElement) {
                    const username = usernameElement.getAttribute('href').split('/')[1];
                    if (usernamesToRemove.includes(username)) {
                        element.remove();
                        hasRemoved = true;
                    }
                }
            });
            if (hasRemoved) {
                addBlockedNotice();
            }
        }
    }

    function observerCallback(mutationsList, observer) {
        for(const mutation of mutationsList) {
            if (mutation.type === 'childList') {
                removeElementsWithUsername();
            }
        }
    }

    const observer = new MutationObserver(observerCallback);

    function init() {
        const resultsList = document.querySelector('div[data-testid="results-list"]');
        if (resultsList) {
            removeElementsWithUsername();
            observer.observe(resultsList, {
                childList: true,
                subtree: true
            });
        }
    }

    // 尝试在页面加载后立即初始化
    window.onload = init;

    // 设置一个定时器,每2秒执行一次removeElementsWithUsername函数
    setInterval(removeElementsWithUsername, 2000);

    // 对于动态内容,使用MutationObserver来持续监听DOM变化
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });


})();