Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture the Ajax event that periodically refreshes the gmail inbox

I'm trying to write a Greasemonkey script that works with Gmail. I know how to create javascript that reacts to the user clicking on the Inbox link or the the Refresh link. My problem is that Gmail periodically refreshes the inbox with new conversations and I have no way of capturing this event. Is there any way to capture periodical Ajax events in javascript?

like image 351
Ben Mills Avatar asked Nov 05 '22 21:11

Ben Mills


1 Answers

You could try replacing the window.setTimeout function (and possibly window.setInterval) with your own functions:

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);
}
like image 132
Miles Avatar answered Nov 12 '22 14:11

Miles