Greasy Fork

Greasy Fork is available in English.

搜索时排除百家号站点

使用百度搜索时排除百家号站点

当前为 2019-02-14 提交的版本,查看 最新版本

// ==UserScript==
// @name         搜索时排除百家号站点
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  使用百度搜索时排除百家号站点
// @author       wymix
// @include      http://www.baidu.com/*
// @include      https://www.baidu.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Your code here...
    var kw=document.getElementById('kw');
    kw.style.cssText='display:none;';
    var xgss=document.getElementById('rs_top_new');
    if(xgss!=null){
        var as= xgss.getElementsByTagName('a');
        for(var i=0;i<as.length;i++){
            rebuildRs(as[i]);
        }
    }
    xgss=document.getElementById('rs');
    if(xgss!=null){
        as= xgss.getElementsByTagName('a');
        for(i=0;i<as.length;i++){
            rebuildRs(as[i]);
        }
    }
    var su=document.getElementById('su');
    var span=document.getElementsByClassName('bg s_ipt_wr quickdelete-wrap')[0];
    var kw_s=document.createElement("input");
    kw_s.id='kw_s';
    kw_s.name='wd_s';
    kw_s.className='s_ipt';
    kw_s.maxLength=255;
    kw_s.autocomplete='off';
    kw_s.value=kw.value.replace(' -(site:baijiahao.baidu.com)','');
    span.appendChild(kw_s);
    su.addEventListener('click',addCondition);

    function rebuildRs(a){
        a.href='https://www.baidu.com/s?wd='+a.innerText+'+-%28site%3Abaijiahao.baidu.com%29'
    }
    function addCondition(){
        kw.value=kw_s.value;
        if(kw.value.indexOf('-(site:baijiahao.baidu.com)')==-1){
            kw.value=kw.value+' -(site:baijiahao.baidu.com)';
        }
    }
})();