Greasemonkey, delete <a> element

╄→尐↘猪︶ㄣ 提交于 2019-12-02 18:04:43

问题


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].href.indexOf("http://www.unwantedsites.com") == 0 ) {
        results[i].parentNode.style.display = "none";
    }
}

回答1:


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 )



回答2:


try using getAttribute instead of directly accessing the property href:

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


来源:https://stackoverflow.com/questions/2287931/greasemonkey-delete-a-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!