Greasy Fork is available in English.
根据网站、网址和关键字来屏蔽不想要的搜索结果
当前为
// ==UserScript==
// @name Google 搜索结果屏蔽
// @name:en Google Search Results Block
// @namespace Cheez.Search
// @version 0.5
// @description 根据网站、网址和关键字来屏蔽不想要的搜索结果
// @author 以茄之名
// @author:en Cheez
// @include https://www.google.*/search*
// @include https://www.google.*.*/search*
// @require http://cdn.staticfile.org/jquery-once/2.1.1/jquery.once.min.js
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
(function() {
'use strict';
var $=jQuery;
var blacklist=GM_getValue('blacklist')&&JSON.parse(GM_getValue('blacklist'))||{
host:[],
url:[]
};
console.log(blacklist);
$('[onmousedown]').attr('onmousedown','');
$.each(jQuery('[href*=webcache]'),function(i,o){jQuery(o).attr('href',jQuery(o).attr('href').replace('p:','ps:'));});
function hid(hosts,urls){
$('.r>a').filter(function(i,o){
if($.inArray(o.host,hosts)>-1){return true;}
var flag=false;
$.each(urls,function(i,o){
if(o.baseURI.match(oo)){
flag=true;
return false;
}
});
if(!flag){
var p=$(o).parents('.g');
var menu=$(p).find('.action-menu-panel>ol');
if( menu.size() ){
menu.filter(':not(:has(.block))').append(
'<li class="action-menu-item ab_dropdownitem" role="menuitem" aria-selected="false"><a class="fl block-site" data-url="'+o.baseURI+'" tabindex="-1">屏蔽该类网址</a></li>'+'<li class="action-menu-item ab_dropdownitem" role="menuitem" aria-selected="false"><a class="fl block" data-host="'+o.host+'" tabindex="-1">屏蔽该网站</a></li>');
}else{
var text='<div class="action-menu ab_ctl"><a class="_Fmb ab_button" href="#" aria-label="结果详情" aria-expanded="false" aria-haspopup="true" role="button" jsaction="m.tdd;keydown:m.hbke;keypress:m.mskpe" ><span class="mn-dwn-arw"></span></a><div class="action-menu-panel ab_dropdown" role="menu" tabindex="-1" jsaction="keydown:m.hdke;mouseover:m.hdhne;mouseout:m.hdhue"><ol>';
$(p).find('.kv').append(text+'<li class="action-menu-item ab_dropdownitem" role="menuitem" aria-selected="false"><a class="fl block-site" data-url="'+o.baseURI+'" tabindex=" -1"="">屏蔽该类网址</a></li></ol></div></div>');
$(p).find('.action-menu-panel>ol').filter(':not(:has(.block))').append('<li class="action-menu-item ab_dropdownitem" role="menuitem" aria-selected="false"><a class="fl block" data-host="'+o.host+'" tabindex=" -1"="">屏蔽该网站</a>');
}
}
return flag;
}).parents('.g').addClass('hiden').hide();
}
hid(blacklist.host,blacklist.url);
$('#rso').delegate('a.block','click',function(e){
$(this).parents('.g').addClass('hiden').hide();
blacklist.host.push($(this).data('host'));
GM_setValue('blacklist',JSON.stringify(blacklist));
hid([$(this).data('host')],[]);
});
$('#rso').delegate('a.block-site','click',function(e){
var mch=prompt("请输入对应的匹配",$(this).data('url'));
if(mch){
mch=str2reg(mch);
$(this).parents('.g').addClass('hiden').hide();
blacklist.url.push(mch);
GM_setValue('blacklist',JSON.stringify(blacklist));
hid([],[mch]);
}
});
function str2reg(str){
return new RegExp(str.replace(/(?!\\)\$\(\)\*\+\.\[\]\?\^\{\}\|\\/g,/\\$1/));
}
})();