bye-dude

百度拜拜。功能 1、搜索时排除百家号、CSDN; 2、阻止搜索框占位关键词推广;

目前為 2025-04-25 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         bye-dude
// @namespace    https://greasyfork.org/users/866159
// @version      0.0.3
// @description  百度拜拜。功能 1、搜索时排除百家号、CSDN; 2、阻止搜索框占位关键词推广;
// @author       Song
// @match        *://www.baidu.com
// @match        *://www.baidu.com/s?*
// @icon         https://www.baidu.com/favicon.ico
// @license MIT
// @grant        none
// ==/UserScript==
(function () {
    'use strict';


    // -(site:baijiahao.baidu.com)
    const excludeSites = ['baijiahao.baidu.com','csdn.net'];
    const ignoreWords = ['假期', '放假', '万年历'];

    function beforeSubmit() {
        const input = document.querySelector('#kw');
        input.addEventListener('focus', () => {
            let w = input.value;
            if (w.length > 7) {
                excludeSites.forEach(s => {
                    w = w.replaceAll(` -site:${s}`, '');
                });
                console.info('focus 处理后', w)
                input.value = w;
            } else {
                console.info('focus value', w.length, w)
            }
        });
        document.querySelector('#form')
            .addEventListener('submit', event => {
                const w = input.value;
                for (let word of ignoreWords) {
                    if (w.indexOf(word) > -1) {
                        return;
                    }
                }
                const sites = excludeSites.map(s => `-site:${s}`).filter(s => w.indexOf(s) < 0);
                if (sites.length > 0) {
                    input.value = w.trim() + ' ' + sites.join(' ');
                }
            }, {capture: true});
    }

    function clearPlace() {
        const input = document.querySelector('#kw');
        input.placeholder = '';
        Object.defineProperty(input, 'placeholder', {
            set(value) {
                console.info('prevent set placeholder to', value)
            },
            get() {
                return '';
            }
        })
    }

    clearPlace();
    beforeSubmit();
})();