Scripting Gmail part 2

July 6th, 2007 § 1 comment

UPDATE: Haha, alas this does not work all the time. Yep. See my next post… sigh.

After some time poking around with Firebug, here’s the updated code that also handles the “reply” text-editing area!

/* gmail seems to cycle between frames 'v1', 'v2' and 'v3'. try all */
var success = false;
var editorNames = [ 'hc_compose', 'ta_compose', 'hc_0', 'ta_0' ];
for (var i=1; i< =3 && !success; i++)
{
    /* if the frame is offscreen, it's not the active composing window */
    /* do this with a DOM element */
    var fe = top.main.document.getElementById('v'+i);
    if (fe && fe.offsetLeft >= 0)
    {
        /* the element name of the edit box could be one of 4 values, depending
           on rich text/plain text, as well as whether replying or composing.
           try them all. */
        var d = top.main.frames["v"+i].document; /* note we have to use oldschool frames[] syntax */
        var ed = null;
        for (var j=0; j<editornames .length; j++)
        {
            ed = d.getElementById(editorNames[j]);
            if (ed != null)
            {
                break;
            }
        }
 
        if (ed != null)
        {
            /* found it! rich text? or plain? */
            switch (ed.nodeName)
            {
                case "TEXTAREA":
                {
                    /* plain text */
                    /* do something with 'ed' */
                    success = true;
                    break;
                }
 
                case "IFRAME":
                {
                    /* rich text */
                    /* do something with 'ed' */
                    ed.contentDocument.execCommand( /* something something */ );
                    success = true;
                    break;
                }
            }
        }
    }
}

Phew!

§ One Response to Scripting Gmail part 2

What's this?

You are currently reading Scripting Gmail part 2 at bunnyhero dev.

meta