インターネットの広告が話題になっているようなので便乗してみた

人気の記事になっていたhttp://d.hatena.ne.jp/gnarl/20080923/1222107368を見て。おれの出番きた。

まえにつくったスクリプトをつかって広告を消してみた。

結果↓

demo

javascript:function addGlobalStyle(list){for(var i=0;i<list.id.length;i++){list.id[i]='#'+list.id[i];}for(var i=0;i<list.class.length;i++){list.class[i]='.'+list.class[i];}for(var i=0;i<list.name.length;i++){list.name[i]='[name="'+list.name[i]+'"]';}var removeList=list.id.concat(list.class,list.name);var head=document.getElementsByTagName('head')[0];if(!head){return;}var style=document.createElement('style');style.type='text/css';style.innerHTML=removeList+'{display:none!important;}';head.appendChild(style);}(function(){var list={};list.id=[];list.class=['block_cvv2008','block_zdnet2008','block_wp_item','ad_square_leaf','frame_col_right','ad_large','block_header_info'];list.name=[];addGlobalStyle(list);var adtable=document.evaluate('//table[@border="0"][parent::div[@class="postbody"]]',document,null,7,null);if(adtable.snapshotItem(0)){adtable.snapshotItem(0).parentNode.removeChild(adtable.snapshotItem(0));}})();

グーグルのトップ3人が語る、ヤフー提携、YouTube、Android(japan.cnet.com)のページを開いてアドレスバーに、上の「javascript:〜」をコピペしてエンターを押すと広告を削除します。

ソースコード

function addGlobalStyle(list){

    for(var i=0;i<list.id.length;i++){ list.id[i] = '#'+list.id[i];}
    for(var i=0;i<list.class.length;i++){ list.class[i] = '.'+list.class[i];}
    for(var i=0;i<list.name.length;i++){ list.name[i] = '[name="'+list.name[i]+'"]';}
    var removeList = list.id.concat(list.class,list.name);

    var head = document.getElementsByTagName('head')[0];
    if(!head){ return; }
    var style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = removeList+'{display:none!important;}';
    head.appendChild(style);
}

    var list = {};
    list.id = [];
    list.class = ['block_cvv2008','block_zdnet2008','block_wp_item','ad_square_leaf','frame_col_right','ad_large','block_header_info'];
    list.name = [];

    addGlobalStyle(list);

感想

Adblockとか使わずに、パズル気分でfirebugを使って広告のclassを抽出しただけ。楽チン。