title: Set event handler on arbitrary JS function?
body: <p>I'd like to write a Chrome extension that works with a particular JS-based chat application. It needs to be made aware every time the chat receives a message.</p>
  
  <p>Now, I can obviously do this easily by setting up a timer and checking to see if <code>$("chat-messages").childElements().length</code> has increased, but I'd rather go with the more elegant method of setting up an event handler of some sort to fire every time <code>appendChatMessage()</code> is invoked. Is there a way to do this?</p>
  
  <pre><code>var oldfunc = appendChatMessage;
  appendChatMessage = function() { eval(oldfunc); myChatMessageReceivedHandler(); }
  </code></pre>
  
  <p>Doesn't seem to be working.</p>