Home

Show Tables

Source code for bookmarklet Show Tables.



javascript:
(function(){
    
    function hasAttribute(e, a)
    {
        return e.hasAttribute(a);
    }

    var table_count = 0;
    function eD(dt) {
        var fs = dt.getElementsByTagName( "TABLE" );
        for (var i = 0, l = fs.length; i < l; ++i )
        {
            ++table_count;

            fs[i].style.border = "thin solid red";
            if ( hasAttribute(fs[i], "SUMMARY") )
            {
                fs[i].style.borderTop = "thick solid green";
                fs[i].title = "Table summary: " + fs[i].summary;
            }
        }
    }


    // "dIr" == "documentIterator"
    function dIr(dt, f) {
        function ifsr( fs )
        {
            for (var i = 0; i < fs.length; ++i)
            {
                try {
                    dIr(fs[i].contentDocument, fs[i]); // recursive call
                }
                catch (e) {
                    alert(e || "Unspecified error");
                }
            }
        }

        if (dt == null) {return;}
        eD(dt, f);
        ifsr( dt.getElementsByTagName("FRAME") );
        ifsr( dt.getElementsByTagName("IFRAME") );
    }

    // iterate through all documents
    dIr(document, null);

    var st = (table_count > 0) ? ("Tables: " + table_count) : "No tables";
    alert(st + ".");
}());