Skip to content

Instantly share code, notes, and snippets.

@edvakf
Created March 18, 2009 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edvakf/81239 to your computer and use it in GitHub Desktop.
Save edvakf/81239 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name ad_entry_blocker_mod.user.js
// @namespace http://d.hatena.ne.jp/edvakf/
// @description Remove ad items
// @include http://reader.livedoor.com/reader/
// @include http://reader.livedoor.com/public/*
// @include http://fastladder.com/reader/
// ==/UserScript==
// Inspired by the original script http://blog.endflow.net/?p=58
// The "IE OK?" lines **might** work for IE as well
(function(){
/////////////// configurations ////////////////
var cfg = {
// judgement patterns of entry title
patterns: [/^[\s【\[]*(AD|PR|AD|PR)[\s】\]]*[::]/i, /^\s*[【\[]\s*(AD|PR|AD|PR)\s*[】\]]/i],
// advertisement entries style (apply this style to title link <a>)
style: ['color:#aaa;','font-size:12px;'],
// skip ad-entry
skip: true
}
///////////////////////////////////////////////
var w = (typeof unsafeWindow == 'undefined') ? window : unsafeWindow;
w.LDR_addStyle('.item.blocked h2 > a',cfg.style);
w.LDR_addStyle('.item.blocked > .padding > :not(.item_header)',['display:none;']);// for non-IE
//w.LDR_addStyle('.item.blocked .item_info, .item.blocked .item_body, .item.blocked .item_footer',['display:none;']); // IE OK
w.blockItem = function(self){
w.addClass(self.parentNode.parentNode.parentNode.parentNode.parentNode,'blocked');
};
w.entry_widgets.add('ad_entry_block', function(feed, item){
if(cfg.patterns.some(function(re){return re.test(item.title)})){
return '<img alt="" style="height:1px;width:1px;border:none;" src="data:,hoge" onerror="blockItem(this)" />';//for non-IE
//return '<img alt="" style="height:1px;width:1px;border:none;" src="/favicon.ico" onerror="blockItem(this)" onload="blockItem(this)" />';//IE OK
//return '<img alt="" style="height:1px;width:1px;border:none;" src="http://0.0.0.0/" onerror="blockItem(this)" />';//IE OK
}else{
return '';
}
}, 'LDR Ad-Entry Blocker');
if(cfg.skip){
w.addEventListener('load',function(){
var j_func = w.Keybind._keyfunc['j'];
w.Keybind.add('j|enter', function(){
j_func();
if(w.Control.next_item_offset()==null) return;
var info = w.get_active_item(true);
w.hasClass(info.element.parentNode.parentNode.parentNode, 'blocked') && arguments.callee() ;
});
var k_func = w.Keybind._keyfunc['k'];
w.Keybind.add('k|shift+enter', function(){
k_func();
var info = w.get_active_item(true);
w.hasClass(info.element.parentNode.parentNode.parentNode, 'blocked')
&& ( (w.Control.prev_item_offset()==null)? k_func() : arguments.callee() );
});
},false);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment