GitHub搜索结果净化

This is a Tampermonkey script for filtering GitHub search results. You can specify users or repositories to block certain inappropriate display results, such as repositories from cirosantilli and wumaoland.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GitHub搜索结果净化
// @namespace
// @version      1.0.1
// @description  This is a Tampermonkey script for filtering GitHub search results. You can specify users or repositories to block certain inappropriate display results, such as repositories from cirosantilli and wumaoland.
// @author       yanyaoli
// @match        https://github.com/search*
// @grant        none
// @namespace https://greasyfork.org/users/1080143
// ==/UserScript==

(function() {
    'use strict';

    var blockList = ['cirosantilli', 'wumaoland', 'codin-stuffs', 'cheezcharmer', 'Dimples1337', 'Dujltqzv', 'gege-circle', 'PCL/', 'zhaohmng-outlook-com', 'zaohmeing', 'Daravai1234', 'candice531033938', 'jk-ice-cream', 'sky8964', 'pxvr-official', 'zpc1314521', 'jjzhang166', 'panbinibn'];

    function addPrefix(blockList) {
        return blockList.map(function(blockedItem) {
            if (blockedItem.includes('/')) {
                return '-repo:' + blockedItem;
            } else {
                return '-user:' + blockedItem;
            }
        });
    }

    blockList = addPrefix(blockList);

    function updateSearchQuery() {
        var searchParams = new URLSearchParams(window.location.search);
        var q = searchParams.get('q') || '';

        var searchTerms = q.split(' ');

        var isBlockListInQuery = blockList.every(function(blockedItem) {
            return searchTerms.includes(blockedItem);
        });

        if (!isBlockListInQuery) {
            q += ' ' + blockList.join(' ');
            searchParams.set('q', q);
            window.location.search = searchParams.toString();
        }
    }

    if (window.location.href.includes('/search')) {
        updateSearchQuery();
    }

    var searchForm = document.querySelector('form');
    if (searchForm) {
        searchForm.addEventListener('submit', function(event) {
            updateSearchQuery();
            location.reload();
            event.preventDefault();
        });
    }
})();