B++

Remove the random recommendations, bottom bar, sidebar, microphone, and search optimization from the Bing search page. Remove the website logo and switch to a dual-column search result layout. Automatically redirect to the correct Baidu Tieba page. 移除必应搜索页面莫名其妙的推荐、底部栏、侧边栏、麦克风、优化搜索等,去除网页logo,改成双列搜索结果,百度贴吧自动正确跳转

当前为 2025-03-23 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         B++
// @namespace    Bing Plus Plus
// @version      1.01
// @description  Remove the random recommendations, bottom bar, sidebar, microphone, and search optimization from the Bing search page. Remove the website logo and switch to a dual-column search result layout. Automatically redirect to the correct Baidu Tieba page. 移除必应搜索页面莫名其妙的推荐、底部栏、侧边栏、麦克风、优化搜索等,去除网页logo,改成双列搜索结果,百度贴吧自动正确跳转
// @author       Yog-Sothoth
// @match        https://*.bing.com/search*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 移除元素的函数
    function removeElement(selector) {
        const elements = document.querySelectorAll(selector);
        elements.forEach(element => element.remove());
    }

    // 修正贴吧链接的函数
    function replace() {
        let as = document.querySelectorAll('#b_content .b_algo h2 a');
        let as2 = document.querySelectorAll('#b_content .b_algo .b_tpcn .tilk');

        for (let i = 0; i < as.length; i++) {
            let url = as[i].getAttribute('href');
            let new_url = url.replace(/jump2\.bdimg|jump\.bdimg/, 'tieba.baidu');
            as[i].setAttribute('href', new_url);
            as2[i].setAttribute('href', new_url);
        }
    }

    // 注入双列CSS
    const css = `
        #b_context { display: none; } /* 隐藏 Bing 侧边栏 */
        #b_content { padding: 30px 15px !important; } /* 调整 Bing 内容区域的内边距 */
        #b_results { display: flex; flex-wrap: wrap; width: 100% !important; } /* 让 Bing 结果区域使用流式布局,支持换行,并统一宽度 */
        #b_results > li { width: 40%; margin-right: 50px; } /* 调整 Bing 搜索结果项的宽度与间距 */
        .b_pag, .b_ans { width: 100% !important; } /* 让分页和答案区域宽度适应 */
        #b_results .ContentItem { display: inline-flex; flex-wrap: wrap; width: 40%; } /* 文章项 inline-flex 布局,支持换行,并设置宽度 */
        #b_results .MainContent_Sub_Left_MainContent { max-width: 100% !important; } /* 让主内容区域的最大宽度适应全屏 */
    `;

    // 使用 GM_addStyle 添加样式
    GM_addStyle(css);

    // 列出要删除的元素的类名和 ID
    const elementsToRemove = [
        '.b_ans', '.b_ans .b_mop', '.b_vidAns', '.b_rc_gb_sub',
        '.b_rc_gb_sub_section', '.b_rc_gb_scroll', '.b_msg',
        '.b_canvas', '.b_footer', '.b_phead_sh_link', '.b_sh_btn-io',
        '#id_mobile', '[aria-label="更多结果"]', '.b_algoRCAggreFC', '.b_factrow b_twofr', '[id^="mic_"]',
        '[class="tpic"]', '[class="b_vlist2col b_deep"]', '[class="b_deep b_moreLink "]','.b_algo b_vtl_deeplinks','[class="tab-head HeroTab"]','[class="tab-menu tab-flex"]','[class="b_deepdesk"]','.b_caption a[target="_blank"]','[class^="b_algo b_algoBorder b_rc_gb_template b_rc_gb_template_bg_"]'
    ];

    // 创建一个 MutationObserver 来监听 DOM 变化
    const observer = new MutationObserver(() => {
        elementsToRemove.forEach(removeElement); // 每次 DOM 变化时移除指定元素
    });

    // 配置并启动观察器,监听整个文档的子元素变化
    observer.observe(document.body, {
        childList: true,    // 监听子节点变化
        subtree: true       // 监听整个树形结构
    });

    // 初始加载时移除指定的元素
    elementsToRemove.forEach(removeElement);

    // 初始调用替换链接函数
    replace();

    // 监听历史记录的变化,替换链接
    var _pushState = window.history.pushState;
    window.history.pushState = function() {
        replace();
        console.log('History changed');
        return _pushState.apply(this, arguments);
    };
})();