Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

2008-03-08

[][greasemonkey][seahorse]はてブのhotentryで、2chコピペブログや「ネタ」を削除す...勝手に改造

firefoxでしか確認していないけれど、URL正規表現XPathで指定できる様にしてみたよ。

// ==UserScript==
// @name           filter for Hatena::Bookmark
// @namespace      http://anond.hatelabo.jp/
// @include        http://b.hatena.ne.jp/hotentry*
// @include        http://b.hatena.ne.jp/entrylist*
// origin http://anond.hatelabo.jp/20080302214727
// ==/UserScript==
(function(){
	var itemxpath = "//div[@class='entry']";
	function xpathgenURL(url) {return "//div[@class='entry' and descendant::a[starts-with(@href,'"+url+"')]]"}
	var filters = [
		// start with '//' then xpath
		// moconico douga
//		{"tag": "div", "name": "entry", "pattern": "nicovideo\.jp"},
		"//div[@class='entry' and descendant::a[contains(@href,'nicovideo.jp')]]",
/*
		// tag of "2ch"
		{"tag": "a", "name": "tag", "pattern": "2ch", "parentNum": HatebuTagParentNum},
		{"tag": "a", "name": "tag", "pattern": "\\*2ch", "parentNum": HatebuTagParentNum},
***/
		// start with 'http' then url
		// 2ch blogs  
		//  livedoor
//		{"tag": "div", "name": "entry",
//			"pattern": /http:\/\/blog\.livedoor\.jp\/(insidears|dqnplus)\//},
		"http://blog.livedoor.jp/insidears/",
		"http://blog.livedoor.jp/dqnplus/",
//		{"tag": "div", "name": "entry",
//			"pattern": /http:\/\/(guideline|alfalfa|news4vip)\.livedoor\.biz\//},
		"http://guideline.livedoor.biz/",
		"http://alfalfa.livedoor.biz/",
		"http://news4vip.livedoor.biz/",
		// typeof /regexp/ is function (@firefox) then regexp pattern
		//  fc2
//		{"tag": "div", "name": "entry",
//			"pattern": /http:\/\/(urasoku|news23vip|waranote|vipvipblogblog|netanabe|res2ch|kanasoku|tenkomo)\.blog\d+\.fc2\.com\//},
		/http:\/\/(urasoku|news23vip|waranote|vipvipblogblog|netanabe|res2ch|kanasoku|tenkomo)\.blog\d+\.fc2\.com\//,

		// tag of "neta"
//		{"tag": "a", "name": "tag", "pattern": "ネタ", "parentNum": HatebuTagParentNum},
		"//div[@class='entry' and descendant::a[@class='tag' and string()='ネタ']]",
//		{"tag": "a", "name": "tag", "pattern": "*ネタ", "parentNum": HatebuTagParentNum},
		"//div[@class='entry' and descendant::a[@class='tag' and string()='*ネタ']]",

		// hatena anonymouse diary
//		{"tag": "div", "name": "entry", "pattern": /http:\/\/anond\.hatelabo\.jp\//}
		"http://anond.hatelabo.jp/",
	];

	for (var i=0; i<filters.length; i++) {
		var filter = filters[i];
		var type = typeof filter;
		var regexp;
		var xpath;
		if (type == "function") {
			xpath = itemxpath;
			regexp = filter;
		} else if (type == "string") {
			if (filter.match(/^http/)) {
				xpath = xpathgenURL(filter);
			} else if (filter.match(/^\/\//)) {
				xpath = filter;
			} else {
				next;
			}
		}
		var removeNodes = document.evaluate(xpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
		for (var j=0; j<removeNodes.snapshotLength; j++) {
			var node = removeNodes.snapshotItem(j);
			if (!regexp || node.innerHTML.match(regexp)) {
				node.parentNode.removeChild(node);
			}
		}
	}
})();

ついでに増田版も作ってみたよ。

// ==UserScript==
// @name           filter for Hatelabo::AnonymousDiary
// @namespace      http://anond.hatelabo.jp/
// @include        http://anond.hatelabo.jp/
// @include        http://anond.hatelabo.jp/*?page=*
// @exclude        http://anond.hatelabo.jp/YourID/*
// ==/UserScript==
// origin http://anond.hatelabo.jp/20080302214727
(function(){
	var itemxpath = "//div[@class='section']";
	function xpathgenURL(url) {return "//div[@class='section' and descendant::a[starts-with(@href,'"+url+"')]]"}
	var filters = [
		// start with '//' then xpath
		"//div[@class='section' and child::h3[starts-with(string(),'■はてな嫌われ者!')]]",
		// start with 'http' then url
		"http://anond.hatelabo.jp/",
		// typeof /regexp/ is function (@firefox) then regexp pattern
		/釣り/,
	];

	for (var i=0; i<filters.length; i++) {
		var filter = filters[i];
		var type = typeof filter;
		var regexp;
		var xpath;
		if (type == "function") {
			xpath = itemxpath;
			regexp = filter;
		} else if (type == "string") {
			if (filter.match(/^http/)) {
				xpath = xpathgenURL(filter);
			} else if (filter.match(/^\/\//)) {
				xpath = filter;
			} else {
				next;
			}
		}
		var removeNodes = document.evaluate(xpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
		for (var j=0; j<removeNodes.snapshotLength; j++) {
			var node = removeNodes.snapshotItem(j);
			if (!regexp || node.innerHTML.match(regexp)) {
				node.parentNode.removeChild(node);
			}
		}
	}
})();
記事への反応 -

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん