Skip to content

Instantly share code, notes, and snippets.

@Qofar
Created October 16, 2014 05:18
Show Gist options
  • Save Qofar/cf8f2695e7bd48cc9b93 to your computer and use it in GitHub Desktop.
Save Qofar/cf8f2695e7bd48cc9b93 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name LDR_ad_entry_blocker_mod.user.js
// @namespace http://d.hatena.ne.jp/edvakf/
// @description Remove ad items
// @include http://reader.livedoor.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(){
function source(){
/////////////// configurations ////////////////
var cfg = {
// judgement patterns of entry title
patterns: [/^[\s\[]*(AD|PR||)[\s\]]*[:]/i, /^\s*[\[]\s*(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
};
///////////////////////////////////////////////
LDR_addStyle('.item.blocked h2 > a',cfg.style);
LDR_addStyle('.item.blocked > .padding > :not(.item_header)',['display:none;']);// for non-IE
//LDR_addStyle('.item.blocked .item_info, .item.blocked .item_body, .item.blocked .item_footer',['display:none;']); // IE OK
window.blockItem = function(self){
addClass(self.parentNode.parentNode.parentNode.parentNode.parentNode,'blocked');
};
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){
addEventListener('load',function(){
var j_func = Keybind._keyfunc['j'];
Keybind.add('j|enter', function(){
j_func();
if(Control.next_item_offset()==null) return;
var info = get_active_item(true);
hasClass(info.element.parentNode.parentNode.parentNode, 'blocked') && arguments.callee() ;
});
var k_func = Keybind._keyfunc['k'];
Keybind.add('k|shift+enter', function(){
k_func();
var info = get_active_item(true);
hasClass(info.element.parentNode.parentNode.parentNode, 'blocked')
&& ( (Control.prev_item_offset()==null)? k_func() : arguments.callee() );
});
},false);
}
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML = '(' + source.toString() + ')();';
document.body.appendChild(script);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment