I coded one two (three?) years ago for a contract, and it worked like a charm. Used it for tracking pixels, Google tracking, and a bunch of other stuff.
Surprised this kind of snippet isn't readily available on the intertubes.
Let me know if you'd like a few of my more devious snippets to add to your project, like overloading document.write (surprising how many of those damned advertising scripts still use document.write instead of div injection! :-\).
http://perspectives.mvdirona.com/2009/10/31/TheCostOfLatency...
My suggestion was about plotting for content/advertiser networks the lag for their Javascript against the income the site derives from the network. This is quite likely to be somewhat sensitive information, at least to a degree, so sharing it would be generous.
Unfortunately, some of the better-paying CPM ad networks have the slowest javascript ads the world has ever seen.
We're basically trying to see if removing ads improves our page load speed and therefore our SERP enough to somewhat offset the lost income.