CSDN搜索结果屏蔽器

自动隐藏搜索引擎中的CSDN结果并显示统计信息

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         CSDN搜索结果屏蔽器
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  自动隐藏搜索引擎中的CSDN结果并显示统计信息
// @author       GNEH
// @match        *://www.baidu.com/s*
// @match        *://www.google.com/search*
// @match        *://cn.bing.com/search*
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 创建统计面板
    const createStatsPanel = () => {
        const panel = document.createElement('div');
        panel.style = `
            position: fixed;
            right: 20px;
            bottom: 20px;
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 15px;
            border-radius: 5px;
            z-index: 9999;
            font-family: Arial, sans-serif;
        `;
        panel.innerHTML = `
            <div id="csdn-stats">隐藏CSDN结果:<span id="count">0</span> 条</div>
            <div id="csdn-links" style="margin-top:10px;max-height:200px;overflow-y:auto"></div>
        `;
        document.body.appendChild(panel);
        return {count: panel.querySelector('#count'), links: panel.querySelector('#csdn-links')};
    };

    // 检测并隐藏CSDN结果
    const processResults = (container, stats) => {
        let hiddenCount = 0;
        const csdnLinks = [];
        
        // 遍历搜索结果项
        container.querySelectorAll('.result, .g, .b_algo').forEach(item => {
            // 百度搜索结果判断
            const isBaidu = item.querySelector('.c-container') !== null;
            // 谷歌/Bing结果判断
            const isGoogle = item.querySelector('.tF2Cxc, .b_algo') !== null;
            
            // 检测CSDN特征
            const isCSDN = (isBaidu && item.querySelector('.c-color-gray')?.textContent.includes('CSDN')) ||
                          (isGoogle && item.querySelector('h3')?.textContent.includes('CSDN')) ||
                          item.querySelector('a')?.href.includes('csdn.net');

            if (isCSDN) {
                hiddenCount++;
                const link = item.querySelector('a')?.href;
                if (link) csdnLinks.push(link);
                item.style.display = 'none';
            }
        });

        // 更新统计面板
        stats.count.textContent = hiddenCount;
        stats.links.innerHTML = csdnLinks.map(link => 
            `<a href="${link}" target="_blank" style="display:block;color:#4CAF50;margin:5px 0">${link}</a>`
        ).join('');
    };

    // 主执行函数
    const init = () => {
        const statsPanel = createStatsPanel();
        const observer = new MutationObserver((mutations) => {
            document.querySelectorAll('.result, .g, .b_algo').forEach(container => {
                processResults(container, statsPanel);
            });
        });

        // 初始处理
        document.querySelectorAll('.result, .g, .b_algo').forEach(container => {
            processResults(container, statsPanel);
        });

        // 监听动态加载内容
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    };

    // 延迟执行避免冲突
    setTimeout(init, 1000);
})();