1

I want to read the contents of Gmail messages and add some fancyness on links. Here's some code:

unsafeWindow.gmonkey.load("1.0", function(gmail){
  gmail.registerViewChangeCallback(function(){
    if (gmail.getActiveViewType && gmail.getActiveViewType() == "cv") {
      var viewElement = gmail.getActiveViewElement()
      // Do things with viewElement
    }
  })
})

The actual detection of links in the dom objects for the mails is the easy part. The problem is that the registerViewChangeCallback only runs when you display a thread. Large threads will have most of it's messages hidden, only to be loaded by a users request. I haven't found a Gmail greasemonkey API method for this particular action (loading a individual message), which is when I need to run my script.

Any suggestions?

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111

2 Answers2

1

As you say, the registerViewChangeCallback() function only fires when the user changes their view from e.g. threads to archives, etc.

What you really need is to add a function that intercepts gmail's post-backs and then changes the links. I have never tried doing it myself, but this answer has some sample code for you. When gmail has retrieved a new message, it will fire a readystatechange event, which your code can intercept. You can then change the contents of the message in whichever way you wish (although you may have to wait for a moment to allow gmail to insert the message first - not sure about that one).

Community
  • 1
  • 1
a_m0d
  • 12,034
  • 15
  • 57
  • 79
  • I tried to trace function calls in firebug so that I could monkey patch into those, but wasn't able to because of the thousands of function calls Gmail performs. Figuring out which AJAX call to took into should be much easier, though, I'll investigate the answer you linked to and see what I can find out. – August Lilleaas Aug 18 '09 at 09:01
0

I think you'll find that some messages are loaded when they're listed in the thread; hence your problem.

Why don't you just use a custom style anyway? UserStyles FF plugin.

Noon Silk
  • 54,084
  • 6
  • 88
  • 105