Javascript events when modal window is opened or closed How can I detect when a modal window has been opened or closed?

I am writing a plugin which wants to detect when a garnish elementeditor modal window has been opened or closed.
This is what I ended up doing:

https://github.com/nystudio107/disclosedassets/blob/master/resources/js/disclosedassets.js

There is a Garnish.Modal.visibleModal that will contain the handle to the Garnish modal object if one is visible. You can use this to see if a modal is visible, and even see which one.

Unfortunately there's no event I'm aware of that triggers when a modal is shown, so you'll still have to poll via window.setTimeout() -- it's a hack, but...