Greasy Fork

Greasy Fork is available in English.

必应搜索过滤

过滤必应搜索结果

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         必应搜索过滤
// @namespace    huelse/js-scripts/bing-filter
// @url          https://gitee.com/huelse/js-scripts/blob/master/bing-filter.js
// @version      1.0.1
// @description  过滤必应搜索结果
// @author       THENDINGs
// @require      https://unpkg.com/[email protected]/dist/jquery.min.js
// @match        https://*.bing.com/*
// @icon         https://www.bing.com/favicon.ico
// @grant        unsafeWindow
// @license      GPLv3 License
// ==/UserScript==

(function() {
    'use strict';

    // 屏蔽关键词列表
    const block_list = ['csdn', 'CSDN', '广告'];

    function center() {
        const sbox = document.querySelector('.sbox');
        if (sbox) sbox.style.cssText = 'margin:0 auto;position:fixed;left:0;right:0;';
    }

    function block() {
        const item_list = $('.b_algo');

        const ad_list = $('.b_algo .b_caption p');

        // 屏蔽广告区块
        $('.b_ad').css('display', 'none');

        // 屏蔽带有广告伪元素标签的
        $.each(ad_list, function(idx, el) {
            const ad_class = $(el).attr('class');
            // 部分正常内容的也在p中,如lineclamp
            if (ad_class && !ad_class.includes('lineclamp')) {
                $(el).parents('.b_algo').css('display', 'none');
            }
        });

        // 屏蔽关键词列表
        $.each(item_list, function(idx, el) {
            const text = el.innerText;
            $.each(block_list, function(idx1, el1) {
                if (text.includes(el1)) {
                    console.log(el)
                    $(el).css('display', 'none');
                    return false;
                }
            })
        });
    }

    function relink() {
        const as = $('#b_results h2 a')
        for (let i = 0; i < as.length; i++) {
            const url = as[i].href
            if (url.includes('bing.com/ck/a')) {
                $.get(url, function(data) {
                    const r = /var u = "(.*)";/.exec(data)
                    if (r && r[1]) {
                        as[i].href = r[1].replace(/[\?\&]+msclkid=.*/, '')
                    }
                })
            }
        }
    }

    $(function() {
        center();
        block();
        relink();
    });

})();