ブックマークから消す
// ==UserScript==
// @name EGaiblock for Hatena-Bookmark
// @namespace http://d.hatena.ne.jp/rikuo/
// @include http://b.hatena.ne.jp/hotentry*
// @include http://b.hatena.ne.jp/entrylist*
// @include http://b.hatena.ne.jp/t/*
// @include http://b.hatena.ne.jp/t?tag=*
// @include http://b.hatena.ne.jp/keyword/*
// origin http://anond.hatelabo.jp/20080302214727
// origin http://anond.hatelabo.jp/20080308200619
// ==/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
// tag
"//div[@class='entry' and descendant::a[@class='keyword' and string()='永上裕之']]",
"//div[@class='entry' and descendant::a[@class='tag' and string()='これはえがい']]",
"//div[@class='entry' and descendant::a[@class='tag' and string()='永上裕之']]",
"//div[@class='entry' and descendant::a[@class='tag' and string()='えがちゃん']]",
// start with 'http' then url
"http://blog.livedoor.jp/ikiradio/",
// typeof /regexp/ is function (@firefox) then regexp pattern
/http:\/\/(gazo|ura2ch|kago|infotop.boy|youtube2|ura2ch|egachan).(in|jp|net)\//,
];
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 EGaiblock for HatenaDiary/Group
// @namespace http://d.hatena.ne.jp/rikuo/
// @description Hidden unrequisite entry for HatenaDiary & HatenaGroup
// @include http://d.hatena.ne.jp/*
// @include http://*.g.hatena.ne.jp/*
// @exclude http://d.hatena.ne.jp/keyword/*
// @exclude http://*.g.hatena.ne.jp/keyword/*
// ==/UserScript==
// origin1 http://anond.hatelabo.jp/20080302214727
// origin2 http://anond.hatelabo.jp/20080308200619
// cf. http://furyu.tea-nifty.com/annex/2008/03/greasemonkeysea_0cad.html
var filters = [
// start with '//' or 'descendant::' then xpath
"//div[@class='section' and child::h3[contains(string(),'えがい')]]",
// start with 'http' then url
"http://blog.livedoor.jp/ikiradio/",
// typeof /regexp/ is function (@firefox) then regexp pattern
/これはえがい/,
/えがちゃん/,
/永上裕之/,
];
(function(){
var oWindow=window;
if(typeof unsafeWindow!='undefined'){
window=unsafeWindow;
document=window.document;
}
var w=window,d=w.document;
var setEventHandler=(function(){
if(w.addEventListener){
return function(obj,evt,handler){obj.addEventListener(evt,handler,false)};
}else if(w.attachEvent){
return function(obj,evt,handler){obj.attachEvent('on'+evt,handler)};
}else{
return function(obj,evt,handler){var org=obj['on'+evt];obj['on'+evt]=function(){if(typeof org=='function')org();handler()}};
}
})();
filterDiary();
function filterDiary(){
var itemxpath = "descendant::div[@class='section']";
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(/^(\/\/|descendant::)/)){
xpath = filter;
}else{
next;
}
}
var removeNodes = makexpath(document,xpath);
for(var j=0; j<removeNodes.snapshotLength; j++){
var node = removeNodes.snapshotItem(j);
if(!regexp || node.innerHTML.match(regexp)){
var footnotes = makexpath(node,"descendant::span[@class='footnote']/a/@name");
if(footnotes.snapshotLength > 0){
for(var i=0; i<footnotes.snapshotLength; i++){
var footnote = makexpath(node.parentNode,xpathfootnote(footnotes.snapshotItem(i).textContent.replace(/n/,'')));
var footnoteString = footnote.snapshotItem(0);
footnoteString.parentNode.parentNode.removeChild(footnoteString.parentNode);
}
}
node.parentNode.removeChild(node);
}
}
}
}
function xpathgenURL(url){return "//div[@class='section' and descendant::a[starts-with(@href,'"+url+"')]]"}
function xpathfootnote(name){return "descendant::a[@name='" + name + "']"}
function makexpath(context, query){
return document.evaluate(
query, context, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
)
}
(function(){
var pagerBottom=d.getElementById('pager-bottom');
if(!pagerBottom) return;
var link=pagerBottom.getElementsByTagName('a')[0],img=pagerBottom.getElementsByTagName('img')[0];
if(!link||!img){
setTimeout(arguments.callee,10);
return;
}
var checkHref=link.href;
var isBusy=false;
function checkPager(img) {
setEventHandler(img,'click',function(){
if(isBusy) return;
isBusy=true;
(function(){
var pagerBottom=d.getElementById('pager-bottom');
var link=pagerBottom.getElementsByTagName('a')[0];
if(link){
var newimg=pagerBottom.getElementsByTagName('img')[0];
if(link.href==checkHref||img===newimg){
setTimeout(arguments.callee,10);
return;
}
filterDiary();
checkhref=link.href;
if(newimg)checkPager(newimg);
isBusy=false;
}
})();
});
}
checkPager(img);
})();
var AutoPagerize=w.AutoPagerlike||oWindow.AutoPagerize;
if(AutoPagerize){
var addFilter=(AutoPagerize.addElementFilter)?AutoPagerize.addElementFilter:AutoPagerize.addFilter;
addFilter(function(){filterDiary()});
}
})();
参考リンク
前者は http://anond.hatelabo.jp/20080308200619 (匿名の作者)のままです。
後者はやはり http://d.hatena.ne.jp/rikuo/20080902#p2008090202 のまま。
補足
使う場合は、文字コードにご注意下さい。
補足2
あと言わずもがなですが、元々のGreasmonkeyはどちらも任意の条件でフィルタできる仕組みなので、今回に限らず自由に禁止ワードなどを設定できます。
><