Greasy Fork is available in English.

从Google Baidu Bing搜索结果中屏蔽卡饭教程

从Google Baidu Bing Haosou Youdao搜索结果中屏蔽'卡饭教程'

Version vom 03.11.2015. Aktuellste Version

// ==UserScript==
// @name 从Google Baidu Bing搜索结果中屏蔽卡饭教程
// @namespace BlockKafanTopicinGoogle
// @include /^https?\:\/\/encrypted.google.[^\/]+/
// @include /^https?\:\/\/www.google.[^\/]+/
// @include /^https?\:\/\/www.baidu.[^\/]+/
// @include /^https?\:\/\/[\w]+.bing.[^\/]+/
// @include /^https?\:\/\/www.haosou.com+/
// @include /^https?\:\/\/www.youdao.com/
// @icon    https://coding.net/u/zb227/p/zbImg/git/raw/master/icon.jpgg
// @author       AC
// @version 0.2.3
// @description 从Google Baidu Bing Haosou Youdao搜索结果中屏蔽'卡饭教程'
// @grant none
// ==/UserScript==

var sepcStr1_USELESS=new Array("目的URL","网址的class", "网址对应块的class");
var sepcStr1=new Array("rj.baidu.com","c-showurl", "result-op c-container"); //百度软件推广
var sepcStr2=new Array("baike.baidu.com","c-showurl", "result-op c-container xpath-log"); //百度百科

/*
变量x用于baidu-google-bing-haosou-youdao
就是网址的黑名单的意思~~,--不显示该名单中的网址
*/
var x=new Array(
	"kafan.cn/topic",
	"www.kafan.cn › 卡饭教程"
);
var tmp_count=-1;
/*******************************************Baidu**********************************************/
document.addEventListener('DOMNodeInserted',blockKafanBaidu,false);
function blockKafanBaidu() {
	if(tmp_count < 0) {
		var isBaidu = (location.href.indexOf('.baidu.com') > -1);
		if(isBaidu){
				var citeList = document.getElementsByClassName('g');  //之前取的是g,但这个标签在google中是最大的标签,导致谷歌页面卡住
				for (var index = 0; index < citeList.length; index++) {
					var element = replaceAll(citeList[index].innerHTML);
					//alert(element);
					if (checkIndexof(element)) {
						var node = citeList[index].parentNode;
						for(var index=0; index <= 4; index++){
							node = node.parentNode;
							if(node.className == "result c-container "){
									 break;
							}
						}
						if(index <= 4)
							node.parentNode.removeChild(node);
					}
					tmp_count = index;
				}
				tryto_del_specificEle(sepcStr1[0], sepcStr1[1], sepcStr1[2], sepcStr1[3]);
				//tryto_del_specificEle(sepcStr2[0], sepcStr2[1], sepcStr2[2], sepcStr2[3]);
		}
	}
}
/**************************************Google+Bing+Haosou+Youdao**********************************/
document.addEventListener('DOMNodeInserted',blockKafanGoogle_Bing_Haosou_Youdao,false);
function blockKafanGoogle_Bing_Haosou_Youdao() {
	if(tmp_count < 0) {
		var citeList = document.getElementsByTagName('cite');
		for (var index = 0; index < citeList.length; index++) {
			var element = replaceAll(citeList[index].innerHTML);
			if (checkIndexof(element)) {
				var node = citeList[index].parentNode;
				for(var index1 =0; index1 <= 4; index1++){
					node = node.parentNode;
					if(node.className == "g" || 
						 node.className == "b_algo" || 
						 node.className == "res-list" || 
						 node.className == "rnw default"){
								break;
						}
				}
				if(index1 <= 4)
					node.parentNode.removeChild(node);
			}
		}
	}
}
/**
url_d 被删除的地址url
spec_d 被删除节点的Class名字
spec_f_d 被删除节点的总的父亲节点的Class名字
index_d 节点到父节点的层数
*/
function tryto_del_specificEle(url_d, spec_d, spec_f_d, index_d){
		//alert('删除ing '+spec_d);
		index--;
		var citeList2 = document.getElementsByClassName(''+spec_d);
		for(var index = 0; index < citeList2.length; index++){
		var ele = replaceAll(citeList2[index].innerHTML);
		if((ele.indexOf(''+url_d)>-1)){
			var node = citeList2[index].parentNode;
			for(var index2 = 0; index2 <= 4; index2++){
				node = node.parentNode;
				//alert(node.className);
				if(node.className == spec_f_d){
						 break;
				}
			}
			if(index2 <= 4)
				node.parentNode.removeChild(node);
		}
	}
}
/*去掉网址中的<xxx>*/
function replaceAll(sbefore){
	var send;
	send = sbefore.replace(/<[^>]*>/g ,"");
	return send;
}
/*确认是当前例子的一个子例*/
function checkIndexof(element){
	var result = (element.indexOf(x[0]) > -1);
	for(var i = 1; i <= x.length; i++){
		//alert("check");
		result = result || (element.indexOf(x[i]) > - 1);
	}
	return result;
}