Home

Show ALT as TITLE

Source code for bookmarklet Show ALT as TITLE.



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; // replacement count
    var ic = 0; // item count
    function eI(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");

            rp += (noalt ? 1 : 0);
            ++ic;
            img.title = "[" + (noalt ? "[" + img.src + "]" : alt) + "]";
            }
    }

    function eA(dt) {
        var c = cE( dt.getElementsByTagName("area") );
        for (var k = 0; k < c.length; ++k) {
            var img = c[k];
            var alt = img.alt;
            var noalt = !hasAttribute(img, "ALT");

            rp += (noalt ? 1 : 0);
            ++ic;
            img.title = "[" + (noalt ? "[" + img.href + "]" : alt) + "]";
            }
    }

    function eD(dt) {
        eI(dt);
        eA(dt);
        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);
})();