Proccing a Common Event upon Closing the Menu

In order for the game to efficiently check equipment (that is, without resorting to checking every tick), I think I'd need a way to proc a common event any time the player closes the menu. The base game itself doesn't seem to have what I'm looking for, and I can't seem to find any plugins that specifically proc a common event after the player closes the menu. Would it be difficult to write one out?
Something like this?


https://github.com/Trivel/RMMV/blob/master/MrTS_CommonEventOnMenuLeave.js
Yes, that's it! Thank you very much!


EDIT: Looks like there's something wrong with the code, though. I see a whole bunch of </span></td> in places I don't think are supposed to have them.

Original thread: https://forums.rpgmakerweb.com/threads/proccing-a-common-event-upon-closing-the-menu.60973/