1
votes

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?

2

2 Answers

1
votes

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).

0
votes

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.