B++

移除必应搜索页面莫名其妙的推荐、底部栏、侧边栏、麦克风、优化搜索等,去除网页logo,改成双列搜索结果,百度贴吧自动正确跳转

目前為 2025-03-23 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         B++
// @namespace    Bing Plus Plus
// @version      1
// @description  移除必应搜索页面莫名其妙的推荐、底部栏、侧边栏、麦克风、优化搜索等,去除网页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);
    };
})();