The function I've got takes the contents of the passage class div, messes with the text strings (but preserves the HTML tags), and then outputs back into the same div. I've got it running outside Twine in a browser but there it's activated by pressing a button on a page (so the whole not running until the page is rendered thing isn't an issue there).
The general goal for this code is to have it activated for every passage (it'll then read the relevant State.variables variable and run based on that).
What I don't know is how best to accomplish that. I've tried to read the documentation but I'm unable to progress.
I suppose the other thing I need is to know whether this is how I should be reading/writing the passage contents?
On a normal webpage that gives me the contents of a div but it seems that's not the way to do it in Sugarcube.