<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bunnyhero dev &#187; Bookmarklets</title>
	<atom:link href="http://www.bunnyhero.org/category/bookmarklets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bunnyhero.org</link>
	<description>Notes on iPhone, Flash and Web development</description>
	<lastBuildDate>Fri, 23 Jul 2010 18:00:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Deeper into the rabbit hole: Gmail scripting part 3!</title>
		<link>http://www.bunnyhero.org/2007/07/13/deeper-into-the-rabbit-hole-gmail-scripting-part-3/</link>
		<comments>http://www.bunnyhero.org/2007/07/13/deeper-into-the-rabbit-hole-gmail-scripting-part-3/#comments</comments>
		<pubDate>Fri, 13 Jul 2007 05:01:59 +0000</pubDate>
		<dc:creator>bunnyhero</dc:creator>
				<category><![CDATA[Bookmarklets]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bunnyhero.org/2007/07/13/deeper-into-the-rabbit-hole-gmail-scripting-part-3/</guid>
		<description><![CDATA[I have discovered that the &#8220;reply&#8221; editing area is not always named &#8220;hc_0&#8221; or &#8220;ta_0&#8220;. No, the number following the underscore can be other numbers &#8212; it seems to correspond to the index of message in the conversation. This gets more complex, because I forgot that more than one reply editing area can be open at the same time! And they can be of different types (i.e. rich or plain text)! So now not only do we have to find the editing area(s), we have to determine which one has the current focus. So far, I&#8217;ve not been able to find a way to determine what element has the focus, using JavaScript, on a page I didn&#8217;t create. Hmmm&#8230;! More later&#8230;]]></description>
			<content:encoded><![CDATA[<p>I have discovered that the &#8220;reply&#8221; editing area is not always named &#8220;<code>hc_0</code>&#8221; or &#8220;<code>ta_0</code>&#8220;. No, the number following the underscore can be other numbers &#8212; it seems to correspond to the index of message in the conversation.</p>
<p>This gets more complex, because I forgot that more than one reply editing area can be open at the same time! And they can be of different types (i.e. rich or plain text)! So now not only do we have to find the editing area(s), we have to determine which one has the current focus. So far, I&#8217;ve not been able to find a way to determine what element has the focus, using JavaScript, on a page I didn&#8217;t create. Hmmm&#8230;!</p>
<p>More later&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bunnyhero.org/2007/07/13/deeper-into-the-rabbit-hole-gmail-scripting-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Gmail part 2</title>
		<link>http://www.bunnyhero.org/2007/07/06/scripting-gmail-part-2/</link>
		<comments>http://www.bunnyhero.org/2007/07/06/scripting-gmail-part-2/#comments</comments>
		<pubDate>Fri, 06 Jul 2007 23:25:54 +0000</pubDate>
		<dc:creator>bunnyhero</dc:creator>
				<category><![CDATA[Bookmarklets]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bunnyhero.org/2007/07/06/scripting-gmail-part-2/</guid>
		<description><![CDATA[UPDATE: Haha, alas this does not work all the time. Yep. See my next post&#8230; sigh. After some time poking around with Firebug, here&#8217;s the updated code that also handles the &#8220;reply&#8221; text-editing area! /* gmail seems to cycle between frames 'v1', 'v2' and 'v3'. try all */ var success = false; var editorNames = &#91; 'hc_compose', 'ta_compose', 'hc_0', 'ta_0' &#93;; for &#40;var i=1; i&#60;=3 &#38;&#38; !success; i++&#41; &#123; /* if the frame is offscreen, it's not the active composing window */ /* do this with a DOM element */ var fe = top.main.document.getElementById&#40;'v'+i&#41;; if &#40;fe &#38;&#38; fe.offsetLeft &#62;= 0&#41; &#123; /* 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&#91;&#34;v&#34;+i&#93;.document; /* note we have to use oldschool frames[] syntax */ var ed = null; for &#40;var j=0; j&#60;editorNames.length; j++&#41; &#123; ed = d.getElementById&#40;editorNames&#91;j&#93;&#41;; if &#40;ed != null&#41; &#123; break; &#125; &#125; &#160; if &#40;ed != null&#41; &#123; /* found it! rich text? or plain? */ switch &#40;ed.nodeName&#41; &#123; case &#34;TEXTAREA&#34;: &#123; /* plain text */ /* do something with 'ed' */ success = true; break; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE</strong>: Haha, alas this does not work all the time. Yep. See my next post&#8230; sigh.</p>
<p>After some time poking around with Firebug, here&#8217;s the updated code that also handles the &#8220;reply&#8221; text-editing area!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* gmail seems to cycle between frames 'v1', 'v2' and 'v3'. try all */</span>
<span style="color: #003366; font-weight: bold;">var</span> success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> editorNames <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'hc_compose'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'ta_compose'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'hc_0'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'ta_0'</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span><span style="color: #CC0000;">3</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>success<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #009966; font-style: italic;">/* if the frame is offscreen, it's not the active composing window */</span>
    <span style="color: #009966; font-style: italic;">/* do this with a DOM element */</span>
    <span style="color: #003366; font-weight: bold;">var</span> fe <span style="color: #339933;">=</span> top.<span style="color: #660066;">main</span>.<span style="color: #660066;">document</span>.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'v'</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fe <span style="color: #339933;">&amp;&amp;</span> fe.<span style="color: #660066;">offsetLeft</span> <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">/* 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. */</span>
        <span style="color: #003366; font-weight: bold;">var</span> d <span style="color: #339933;">=</span> top.<span style="color: #660066;">main</span>.<span style="color: #660066;">frames</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;v&quot;</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">document</span><span style="color: #339933;">;</span> <span style="color: #009966; font-style: italic;">/* note we have to use oldschool frames[] syntax */</span>
        <span style="color: #003366; font-weight: bold;">var</span> ed <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>editorNames.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            ed <span style="color: #339933;">=</span> d.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>editorNames<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ed <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ed <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #009966; font-style: italic;">/* found it! rich text? or plain? */</span>
            <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>ed.<span style="color: #660066;">nodeName</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;TEXTAREA&quot;</span><span style="color: #339933;">:</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #009966; font-style: italic;">/* plain text */</span>
                    <span style="color: #009966; font-style: italic;">/* do something with 'ed' */</span>
                    success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;IFRAME&quot;</span><span style="color: #339933;">:</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #009966; font-style: italic;">/* rich text */</span>
                    <span style="color: #009966; font-style: italic;">/* do something with 'ed' */</span>
                    ed.<span style="color: #660066;">contentDocument</span>.<span style="color: #660066;">execCommand</span><span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/* something something */</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Phew!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bunnyhero.org/2007/07/06/scripting-gmail-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Scripting Gmail with Bookmarklets</title>
		<link>http://www.bunnyhero.org/2007/07/02/scripting-gmail-with-bookmarklets/</link>
		<comments>http://www.bunnyhero.org/2007/07/02/scripting-gmail-with-bookmarklets/#comments</comments>
		<pubDate>Mon, 02 Jul 2007 19:45:32 +0000</pubDate>
		<dc:creator>bunnyhero</dc:creator>
				<category><![CDATA[Bookmarklets]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bunnyhero.org/2007/07/02/scripting-gmail-with-bookmarklets/</guid>
		<description><![CDATA[I am working on some bookmarklets for Gmail. I discovered that targetting any specific element in the Gmail window is a bit tricky, due to Google&#8217;s interesting use of frames. It turns out that Gmail swaps between using frames named &#8220;v1&#8243; and &#8220;v2&#8243; to display the main content (at least in Firefox). If I had to guess, I&#8217;d mumble something about history and the back button and maybe cacheing :P Anyway: here is how I find the text-editing area (it&#8217;ll be either a textarea or an iframe, depending on whether the user is using rich formatting or not): /* gmail seems to swap between frames 'v1' and 'v2'. try both */ var success = false; for &#40;var i=1; i&#60;=2 &#38;&#38; !success; i++&#41; &#123; var ta = top.main.frames&#91;&#34;v&#34;+i&#93;.document.getElementById&#40;&#34;hc_compose&#34;&#41;; if &#40;ta&#41; &#123; /* do something with ta, for example: */ ta.contentDocument.execCommand&#40;/* something something */&#41;; success = true; &#125; else &#123; // try getting the plain text area ta = top.main.frames&#91;&#34;v&#34;+i&#93;.document.getElementById&#40;&#34;ta_compose&#34;&#41;; if &#40;ta&#41; &#123; /* do something with ta here, a textarea element */ success = true; &#125; &#125; &#125; I&#8217;m certain this could be done more cleanly, but you get the idea. Share and enjoy! UPDATE: This currently doesn&#8217;t work for a [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on some <a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklets</a> for Gmail. I discovered that targetting any specific element in the Gmail window is a bit tricky, due to Google&#8217;s interesting use of frames.</p>
<p>It turns out that Gmail swaps between using frames named &#8220;v1&#8243; and &#8220;v2&#8243; to display the main content (at least in Firefox). If I had to guess, I&#8217;d mumble something about history and the back button and maybe cacheing :P</p>
<p>Anyway: here is how I find the text-editing area (it&#8217;ll be either a textarea or an iframe, depending on whether the user is using rich formatting or not):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* gmail seems to swap between frames 'v1' and 'v2'. try both */</span>
<span style="color: #003366; font-weight: bold;">var</span> success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span><span style="color: #CC0000;">2</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>success<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> ta <span style="color: #339933;">=</span> top.<span style="color: #660066;">main</span>.<span style="color: #660066;">frames</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;v&quot;</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">document</span>.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;hc_compose&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ta<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009966; font-style: italic;">/* do something with ta, for example: */</span>
        ta.<span style="color: #660066;">contentDocument</span>.<span style="color: #660066;">execCommand</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/* something something */</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//  try getting the plain text area</span>
        ta <span style="color: #339933;">=</span> top.<span style="color: #660066;">main</span>.<span style="color: #660066;">frames</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;v&quot;</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">document</span>.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ta_compose&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ta<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #009966; font-style: italic;">/* do something with ta here, a textarea element */</span>
            success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I&#8217;m certain this could be done more cleanly, but you get the idea. Share and enjoy!</p>
<p><strong>UPDATE</strong>: This currently doesn&#8217;t work for a &#8220;reply&#8221; editing area. I will (I hope) update the snippet to cover that case, too.</p>
<p><strong>UPDATE 2</strong>: Sorry, this doesn&#8217;t work consistently. I should test more before posting :P I am now finding a frame called &#8220;v3&#8243;. Perhaps Gmail increments this continuously? In any case, I am leaving this post up for research purposes.</p>
<p><strong>UPDATE 3</strong>: Got it working reliably (I think). See the <a href="http://www.bunnyhero.org/2007/07/06/scripting-gmail-part-2/">fixed version</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bunnyhero.org/2007/07/02/scripting-gmail-with-bookmarklets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
