How to capture an Ajax event that periodically updates a gmail inbox

I am trying to write a Greasemonkey script that works with Gmail. I know how to create javascript that responds to a user clicking the inbox or the refresh link. My problem is that Gmail periodically updates mailboxes with new conversations, and I have no way to capture this event. Is there a way to capture Ajax periodic events in javascript?

+5
source share
2 answers

I tried Miles' excellent suggestion above, but unfortunately it doesn’t work, because Gmail has already called the original setTimeout function before I can change it in my Greasemonkey script.

The only thing I can do is somehow respond to the changes that Gmail makes when it periodically updates its inbox. I found that there are several DOM-related events that fire when a node is added or removed:

http://www.w3.org/TR/DOM-Level-3-Events/events.html#event-DOMNodeInserted

Since Gmail is updating the DOM with my latest emails, I can listen to these DOM events (I use DOMNodeInserted) and respond to changes.

It is not elegant, but it works.

+1
source

window.setTimeout (, , window.setInterval) :

window._setTimeout = window.setTimeout;
window.setTimeout = function(func, delay) {
    return window._setTimeout(function() {
        // Your code goes here, before the client function is called
        alert('A timeout event just fired!');

        if (typeof func == 'string') {
            eval(func);
        } else {
            func();
        }
    }, delay);
}
+1

All Articles