Greasy Fork

百度查询链接自动添加关键词' -robin'

为百度搜索链接自动添加" -robin"后缀,可屏蔽大部分百度推广

目前为 2025-01-16 提交的版本。查看 最新版本

// ==UserScript==
// @name         百度查询链接自动添加关键词' -robin'
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  为百度搜索链接自动添加" -robin"后缀,可屏蔽大部分百度推广
// @author       leeannm
// @match        https://www.baidu.com/s?*
// @match        https://www.baidu.com/*/s?*
// @match        https://m.baidu.com/s?*
// @match        https://m.baidu.com/*/s?*
// @license       MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 获取当前URL
    var currentUrl = window.location.href;

    // 检查URL是否包含wd参数
    if (currentUrl.includes('wd=') || currentUrl.includes('word=')) {
        var wdParamIndex = 0;
        if (currentUrl.includes('wd=')) {
            // 获取wd参数的值
            wdParamIndex = currentUrl.indexOf('wd=') + 3;
        }
        else {
            // 获取word参数的值
            wdParamIndex = currentUrl.indexOf('word=') + 5;
        }
        var wdValueEndIndex = currentUrl.indexOf('&', wdParamIndex) !== -1 ? currentUrl.indexOf('&', wdParamIndex) : currentUrl.length;
        var wdValue = currentUrl.substring(wdParamIndex, wdValueEndIndex);

        // 检查wd值是否以"%20-robin"或" -robin"结尾
        if (!wdValue.endsWith('%20-robin')&&!wdValue.endsWith(' -robin')) {
            // 添加" -robin"后缀
            var newWdValue = wdValue + ' -robin';

            // 构建新的URL
            var newUrl = currentUrl.substring(0, wdParamIndex) + newWdValue + currentUrl.substring(wdValueEndIndex);

            // 重定向到新的URL
            window.location.href = newUrl;
        }
    }
})();