When the “footer” is rendered in Discourse, the app sends an “event”
The event is inserted-custom-html:footer
You can use that event to update your footer content like so
api.onAppEvent("inserted-custom-html:footer", () => {
// add your JS here
});
There’s a few more details here.
This should work for what you’re trying to achieve. If it doesn’t, let me know - and post the code you’re using.