Hab jetzt keinen fertigen Code, aber könnte man sowas nicht mit MutationObservern erreichen?

MutationObserver - Web APIs | MDN
The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. It is designed as a replacement for the older Mutation…
developer.mozilla.org