I recently built a userscript for Board Games Stack Exchange. On page load, it scans questions and answers for certain plaintext patterns and replaces them with some HTML, making the posts prettier.
It only works on page load, however. If someone hits edit and edits the post in place (where they get to do the edit and save process in an AJAXy way without leaving the page), then when they save their edit, their freshly-edited post will be reloaded and won't be prettified by the userscript.
Or if pictures make it clearer:
- Have post that was prettified on page load.
- Do some editing.
- Save, post gets saved all AJAX-style and reloaded, and is no longer prettified.
How can I have my userscript reliably detect that a post's finished being edited, and do stuff to the freshly reloaded post only once there's something to do stuff to?