Skip to content

Instantly share code, notes, and snippets.

@tyoro
Created March 14, 2012 15:10
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 tyoro/2037119 to your computer and use it in GitHub Desktop.
Save tyoro/2037119 to your computer and use it in GitHub Desktop.
LDR Ad-Entry Blocker for Chrome
(function(){
location.href= "javascript:function $x(x,c){c=c||document;var res=document.evaluate(x,c,null,4,null);for(var i,nodes=[];i=res.iterateNext();nodes.push(i));return nodes;}; var cfg = { patterns: [/^[\s【]*(AD|PR|AD|PR)[\s】]*[::]/i],style: {color: '#aaa', fontSize: '12px' }, interval: 1000, skip: true}; LDR.register_hook('AFTER_PRINTFEED', function() { var hist = []; var isComp = function(){ var len = hist.length; if(len < 3) return false; return hist[len-1] == hist[len-2] && hist[len-2] == hist[len-3]; }; var blocker = function(){ var titles = $x('//h2[@class=\"item_title\"]/a'); hist.push(titles.length); for(var i = 0; i < titles.length; i++){ var title = titles[i]; for(var j = 0; j < cfg.patterns.length; j++){ if((new RegExp(cfg.patterns[j])).test(title.innerHTML)){ setStyle(title, cfg.style); addClass(title.parentNode, 'laeb_blocked'); var childs = title.parentNode.parentNode.parentNode.childNodes; for(var k = 0; k < childs.length; k++){ if(childs[k].nodeType !== 1 || hasClass(childs[k], 'item_header')) continue; DOM.hide(childs[k]); } break; }; }; }; isComp() || setTimeout(blocker, cfg.interval); }; setTimeout(blocker, cfg.interval); }); if(cfg.skip){ var isEnd = function(dir){ var pos = get_active_item(); return dir ? pos == get_active_feed().items.length - 1 : pos == 0 }; var j_func = Keybind._keyfunc['j']; Keybind.add('j|enter', function(){ do{ j_func(); }while(!isEnd(true) && hasClass(get_active_item(true).element, 'laeb_blocked')); }); var k_func = Keybind._keyfunc['k']; Keybind.add('k|shift+enter', function(){ do{ k_func(); }while(!isEnd(false) && hasClass(get_active_item(true).element, 'laeb_blocked')); }); };";
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment