Nice.
Sounds like you might want to consider the widget route.
Also consider this api method:
api.reopenWidget("poster-name", {
html() {
<<your-code-here-but-consider-using-the-original-as-template>>
}
}
I would recommend you look at: A tour of how the Widget (Virtual DOM) code in Discourse works
It’s significantly more effort to do this kind of thing in Discourse because it is an auto-magical-web-app, but once you do it right, the solution can be very robust.