Home

Show ALT

Source code for bookmarklet Show ALT.



javascript:
(function(){
    
    function cE(a)
    {
        var a2 = [];
        for (var k = 0; k < a.length; ++k) {
            a2.push(a[k]);
            }
        return a2;
    }

    function hasAttribute(e, a)
    {
        return e.hasAttribute(a);
    }
    var rp = 0;
    var ic = 0;
    function eD(dt) {
        var c = cE( dt.images );
        for (var k = 0; k < c.length; ++k) {
            var img = c[k];
            var alt = img.alt;
            var noalt = !hasAttribute(img, "ALT");

            ++ic;
            rp += (noalt ? 1 : 0);
            var s = dt.createElement( "SPAN" );
            s.appendChild(
                dt.createTextNode( noalt ? "[IMG_" + ic + "]" : alt)
                );
            s.title = img.src;
            img.parentNode.replaceChild(s, img)
            }
        alert("ALT-less items: " + rp + "/" + ic);
    }


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

    // "dI" == "documentIterator"
    function dI_(dt, f) {
        if (dt == null) {return;}
        eD(dt, f);
        ifs_( dt.getElementsByTagName("FRAME") );
        ifs_( dt.getElementsByTagName("IFRAME") );
    }

    // iterate through all documents
    dI_(document, null);
})();