Can you share a little more about what you’re trying to achieve? There are a few different APIs that allow you to modify post content when it renders. The most common one would be api.decorateCookedElement
In fact, I just realized that I need to run the function on post content added to the DOM.
I am practically re-creating addPosterIcon API, because mine has to contain custom HTML. I have it already done everything working, except when the long page is being scrolled.
I am trying to add an icon next to the poster username, which triggers a custom event. The only problem is that it’s not getting yet added upon DOM change.
The problem with this method, is that it triggers multiple cooked objects at once and thus preferes an id (to avoid memory leaks), which is not something I need. What would worked for me, is if only one event was triggered after all elements are cooked. I have an idea on how it could be clutched but is there a proper way of doing it using Discourse API?
The decorateCookedElement api will be triggered once for each rendered post. The callback will be passed the DOM element containing the post content. The idea is that you only modify the element you’ve been passed, and not anything else on the page.
But since you want to make modifications to the metadata around the post content, decorateCookedElement probably isn’t the right option.
Then the best thing is probably to look at how the addPosterIcon API is implemented: