Search code examples
javascripttagshide

Hiding specific tag<td> containing certain string(user id)


Site address: http://tcafe2a.com/bbs/board.php?bo_table=free

I want to remove a few posts done by user-id "captinharu".

I did the following(in Tampermonkey script) and it removed most of the webpages instead of just post done by 'captainharu' and I have no idea. Please help.

function rmvtd2(name) {
    var t = document.getElementsByTagName("td");
    for (var i=0; i<t.length; i++)
    {
        var elementHtml = t[i].outerHTML;
        var n1 = elementHtml.indexOf(name);
        if(n1>1){
                t[i].style.visibility = 'hidden';
        }
    }
}
rmvtd2("captinharu");

Solution

  • For this particular case, this solution works. But may not be valid for all the cases.

    function rmvtd2(name) {
        var t = document.getElementsByTagName("tr");
        for (var i=0; i<t.length; i++)
        {
            var elementHtml = t[i].outerHTML;
            var n1 = elementHtml.indexOf(name);
            if(n1 > -1 && n1 < 1000){
                t[i].style.display = 'none';
            }
        }
    }
    rmvtd2("captinharu");