开发者

Greasemonkey, delete <a> element

I have this Greasemonkey script, I originally wanted to get all the <table> elements and search through those for but I couldn't get that to work. So I tried searching for the <a> elements themselves and just hiding them if they contained "http://www.4chanscapepk.t35.com" but its not working either. What am I missing?

var results = document.getElementsByTagName("a");
for ( var i=0; i<results.length; i++ ) {
    if (
        results[i].hr开发者_JAVA百科ef.indexOf("http://www.unwantedsites.com") == 0 ) {
        results[i].parentNode.style.display = "none";
    }
}


Maybe make the condition a little looser? Maybe instead of:

results[i].href.indexOf("http://www.unwantedsites.com") == 0 )

do:

results[i].href.indexOf("unwantedsites.com") >= 0 )


try using getAttribute instead of directly accessing the property href:

if ( results[i].getAttribute("href").indexOf("http://www.unwantedsites.com") == 0 ) {
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜