Google検索フィルタリング

待ちが入ったので、グリモン。
Autopagerizeに対応。あとでコピーするようにメモ

// ==UserScript==
// @name           Google検索フィルタリング
// @namespace      http://d.hatena.ne.jp/kennak/
// @include        http://www.google.co.jp/search?*
// ==/UserScript==
(function(){
	var menu = 0;
	//xpathで指定された箇所に属性としてstyleを追加
    function addAttribute(xpath,style){
		
	    var node = document.evaluate(xpath,document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );

	    if(node.snapshotLength){
	        //console.log(node.snapshotLength + 'find');

	        for (var i = 0; i < node.snapshotLength; i++) {
	            //console.log(node.snapshotItem(i));
				//node.snapshotItem(i).parentNode.removeChild(node.snapshotItem(i));
	            node.snapshotItem(i).setAttribute("style", style);
	        }
	    }else{
	        //console.log('none:' + xpath);
	    }
    }

	//xpathで指定された箇所を削除
    function deleteItem(xpath){
	    var node = document.evaluate(xpath,document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
		var count = 0;

	    if(node.snapshotLength){

	        for (var i = 0; i < node.snapshotLength; i++) {
				node.snapshotItem(i).parentNode.removeChild(node.snapshotItem(i));
	        }
			count++;
	    }else{
	        //console.log('none:' + xpath);
	    }
        return count;
    }

	//xpathで指定された箇所にtxtを追加
    function addText(xpath,txt){
	    var node = document.evaluate(xpath,document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
		var count = 0;

	    if(node.snapshotLength){
			if(menu == 0){
				menu = node.snapshotItem(0).textContent
			}

			node.snapshotItem(0).textContent = menu + txt;

	    }else{
	        //console.log('none:' + xpath);
	    }
		//console.log('find:' + count + ':' +xpath);
        return count;
    }

	//指定された単語でフィルタ
	function searchBlockWord(word){

		var count = deleteItem('/html/body/div/div/div/ol/li/h3/a[contains(@href,"' + word + '")]/../..');
		//console.log('delete:' + word + ':' + count);
		return count;
	}

	var f = function(doc){
		//フィルタリングするサイト
		var BLOCK_WORD=[
			'2ch',
			'2nn',
			'bookmark',
			'buzzurl',
			'tag',
			'keyword',
			'search',
			'clips',
			'clip.livedoor.com',
			'www.flog.jp',
			'feed.designlinkdatabase.net',
			'b.hatena.ne.jp',
			'swik.net',
			'ikubon.com',
			'mark.jolt.jp',
			'clip.nifty.com',
			's.phpspot.org',
			'pookmark.jp',
			'gaia.luna.tv',
			'youtube.com',
			'wassr.jp',
			'twitter',
			'faves.com',
			'laszlo.jp',
			'i.pecipeci.net',
			'kizasi.jp'
		];

		//フィルタ実行
		var count = 0;
	    for(var i = 0;i < BLOCK_WORD.length;i++){
	    	count += searchBlockWord(BLOCK_WORD[i]);
	    }
	    addText('//*[@id="ssb"]/p',' - ' + count + '件削除しました')
	}

	f(document);
	if (window.AutoPagerize) {
	  boot();
	} else {
	  window.addEventListener('GM_AutoPagerizeLoaded',boot,false);
	}

	function boot(){
	  window.AutoPagerize.addFilter(function(docs){
	    docs.forEach(f);
	  });
	}


})();