1

I'm developing a small plugin that changes the favicons if there are unread messages in mailbox in Roundcubemail. However, the API sucks, and the event listupdate is fired only when the whole page is loaded, even if it is meant to fire when the list is updated.

However, I've managed to find out, that every time the list is updated, certain functions are called, such as set_unread_count. It gets the unread-count easily, so it would be great to somehow "append" stuff to this function. I just think based on hours of searching that there is no solution for this. Can I add a callback to be called when the set_unread_count is called? Can I somehow append stuff to that function? Any other ideas?

Martti Laine
  • 12,655
  • 22
  • 68
  • 102
  • cant you simply add an event listener to unread-count , and if there is a change, then you should do whatever you need.rather than attaching a callback function on another function, which even I think may not be possible. – Neeraj Jan 18 '11 at 14:53

1 Answers1

2

Create a little hook.

var _old_set_unread_count = set_unread_count;
set_unread_count = function() {
    // do whatever you want here
    // access arguments[x] to get arguments.

    _old_set_unread_count.apply(this, arguments);
};

Demo: http://www.jsfiddle.net/4yUqL/69/

jAndy
  • 231,737
  • 57
  • 305
  • 359
  • Won't this only work if the function has yet to be bound as an event listener, or if it's called from within another function? I.e. how do you know that when `set_unread_count` is called, the caller refers to it through its global identifier, as opposed to calling it as a func assigned to a local var? (as would be the case with something like `something.addEventListener('x', set_unread_count)`... – James Jan 18 '11 at 14:55
  • @J-P: Of course this will only work if you hook the method after before it was bound or referenced somewhere else. – jAndy Jan 18 '11 at 15:00