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-11-01 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name B++
// @name:zh-CN B艹:必应搜索页面大修
// @name:en B++: Bing Search Page Overhaul
// @namespace Bing Plus Plus
// @version 2.7
// @description:zh-CN 移除必应搜索页面大量元素,去除网页 logo,改成双列瀑布流结果,百度贴吧自动正确跳转,自动连续到下一页
// @description:en Remove a large number of elements on the Bing search page, remove the webpage logo, change to a two-column waterfall layout for the results, ensure Baidu Tieba automatically redirects correctly, and automatically continue to the next page.
// @author Yog-Sothoth
// @match https://*.bing.com/search*
// @grant GM_addStyle
// @license MIT
// @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,改成双列搜索结果,百度贴吧自动正确跳转
// ==/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);
        }
    }

    const css = `
        #b_context { display: none; }
        #b_content { padding: 30px 15px !important; }
        #b_results { display: flex; flex-wrap: wrap; width: 100% !important; }
        #b_results > li { width: 45%; margin-right: 50px; }
        .b_pag, .b_ans { width: 100% !important; }
        #b_results .ContentItem { display: inline-flex; flex-wrap: wrap; width: 40%; }
        #b_results .MainContent_Sub_Left_MainContent { max-width: 100% !important; }
    `;
    GM_addStyle(css);

    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_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"]',
        '[class^="b_algo b_algoBorder b_rc_gb_template b_rc_gb_template_bg_"]',
        '[class="sc_rf"]', '[class="b_algospacing"]', '#b_pole',
        '.b_caption.b_rich', '.b_ad.b_adMiddle', '.b_ad.b_adBottom',
        '.b_imagePair.wide_wideAlgo .inner', '.b_imagePair.wide_wideAlgo[rel="dns-prefetch"]','[class="b_results_eml"]','[class="b_slidebar"]','[class="b_inline_ajax_rs"]','[class="b_ad b_adTop"]'
    ];

    function updateClassForBAlgoElements() {
        const bContent = document.getElementById('b_results');
        if (bContent) {
            Array.from(bContent.children).forEach(element => {
                if (element.classList.contains('b_algo') && element.classList.contains('b_rc_gb_template')) {
                    element.classList.remove(...[...element.classList].filter(cls => cls.startsWith('b_rc_gb_template_bg_')));
                    element.classList.add('b_algo');
                }
            });
        }
    }

    (function cleanCurrentUrl() {
        const urlObj = new URL(window.location.href);
        const params = urlObj.searchParams;
        const keepParams = new Set(['q', 'first']);

        for (const key of [...params.keys()]) {
            if (!keepParams.has(key)) {
                params.delete(key);
            }
        }

        const newUrl = urlObj.origin + urlObj.pathname + urlObj.search;
        window.history.replaceState(null, '', newUrl);
    })();

    function processBingSearchPage() {
        const urlParams = new URLSearchParams(window.location.search);
        let first = parseInt(urlParams.get('first'), 10) || 1;
        const query = urlParams.get('q');
        const resultsContainer = document.getElementById('b_results');

        if (first === 1) fetchResults(5);

        let isFetching = false;

        window.addEventListener('scroll', () => {
            if ((window.innerHeight + window.scrollY) >= (document.body.offsetHeight - 800)) {
                if (!isFetching) {
                    isFetching = true;
                    first += 10;
                    fetchResults(first).then(() => {
                        isFetching = false;
                    });
                }
            }
        });

        function fetchResults(pageFirst) {
            return fetch(`https://www4.bing.com/search?q=${encodeURIComponent(query)}&first=${pageFirst}`)
                .then(response => response.text())
                .then(data => {
                    const parser = new DOMParser();
                    const doc = parser.parseFromString(data, 'text/html');
                    const newResultsContainer = doc.getElementById('b_results');
                    if (!newResultsContainer) return;

                    const newResults = newResultsContainer.querySelectorAll('.b_algo');
                    if (newResults.length === 0) return;

                    const currentResults = resultsContainer.querySelectorAll('.b_algo');
                    const lastAlgo = currentResults[currentResults.length - 1];

                    newResults.forEach(result => {
                        const cloned = result.cloneNode(true);
                        cloned.style.opacity = '0';
                        cloned.style.transition = 'opacity 0.5s ease';

                        if (lastAlgo) {
                            lastAlgo.insertAdjacentElement('afterend', cloned);
                        } else {
                            resultsContainer.appendChild(cloned);
                        }

                        requestAnimationFrame(() => {
                            cloned.style.opacity = '1';
                        });
                    });
                })
                .catch(() => {});
        }
    }

    function cleanWideWideAlgo() {
        const captionCards = document.querySelectorAll('.captionMediaCard');
        captionCards.forEach(card => {
            const wideElements = card.querySelectorAll('.b_imagePair.wide_wideAlgo');
            wideElements.forEach(elem => {
                elem.classList.remove('wide_wideAlgo');
            });
        });
    }

    function redirectTowww4IfNeeded() {
        const urlObj = new URL(window.location.href);
        if (/^(cn\.)/.test(urlObj.hostname)){
                window.location.href = `https://www4.${urlObj.hostname.replace(/^(cn\.)/, '')}${urlObj.pathname}${urlObj.search}`;
        }
    }

    redirectTowww4IfNeeded();
    updateClassForBAlgoElements();
    elementsToRemove.forEach(removeElement);
    replace();
    processBingSearchPage();
    cleanWideWideAlgo();

    const observer = new MutationObserver(mutations => {
        elementsToRemove.forEach(removeElement);
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === 1) {
                    cleanWideWideAlgo(node);
                }
            });
        });
    });
    observer.observe(document.body, { childList: true, subtree: true });

    const _pushState = window.history.pushState;
    window.history.pushState = function () {
        replace();
        return _pushState.apply(this, arguments);
    };
})();