Gmail 2 Logo We just wrote about how Gmail 2 breaks a lot of the Greasemonkey scripts that are available, and Gina from Lifehacker turned right around and released Better Gmail 2. As expected this version only has a fraction of scripts that the original extension had, and it still lacks some of my favorites: Google Calendar integration, Google Reader integration, and Folders4Gmail. None of those scripts have been made compatible with Gmail 2 yet.




One script that I have to have is one for automatically inserting HTML signatures into my emails. The script I used previously wasn’t all that complicated, and I decided to go ahead and fix it myself. I took it one step further, however, and made it work with both the new version and the old version of Gmail.

Note: This script is designed to insert your signature at the beginning of replies/forwards, instead of at the end.

Here’s what you have to do:

  1. Download and install Greasemonkey if you don’t already have it.
  2. Install the script
  3. You’ll need to have the HTML code for the signature that you want to insert. Once you have that just go to the Greasemonkey script manager and edit the script’s HTML signature. The code looks something like this (insert the signature where you see the green text):

    var htmlSignature = ‘<br>–<br>Ryan Wagner, Founder/Editor<br><a href=”http://cybernetnews.com/”>CyberNet Technology News</a><br><a href=”http://cybernetnews.com/”><img src=”http://feeds.feedburner.com/CyberNet.gif” style=”border:0″ alt=”CyberNet Technology News”/></a>‘;

    top.window.setTimeout(“top.window.frames[‘main’].frames[‘” + parent.name + “‘].document.getElementById(‘hc_compose’).contentWindow.document.getElementsByTagName(‘body’)[0].innerHTML = ‘” + htmlSignature + “‘ + top.window.frames[‘main’].frames[‘” + parent.name + “‘].document.getElementById(‘hc_compose’).contentWindow.document.getElementsByTagName(‘body’)[0].innerHTML;”,500);

    var allBody = document.evaluate(“//body[@class=’editable tr-field’]”, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    allBody.snapshotItem(0).innerHTML = htmlSignature + allBody.snapshotItem(0).innerHTML;

This script does work with Opera, but only with the older version of Gmail. I used a special Firefox-only searching property to insert the signature for the new version of Gmail, and the reason being that Gmail 2 has some issues in Opera. In fact Opera users won’t even see a link to the newer version of Gmail unless they are masking the browser as Firefox or IE.