Github中文搜索净化

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

目前為 2024-08-03 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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
    });


})();