The Undo is a matter of Revert to Saved. I don't think any other method would be feasible, as you really want to replace almost ALL the text in a file.
In the meantime I have experimented on a couple of other, more realistic, test documents and I got some crashes in FM11. So instead of using the TextSelection and then walk through all paragraphs in the document, I now use the proper method to select the first paragraph in the first text frame in the main flow and then walk through the linked list of paragraphs down to the end of the flow.
I am still testing this, as there are unforeseen problems with the selection of paragraphs, so be careful when you want to apply this script, especially in a book. Do extensive testing, single stepping and make backups of all your files before you put this into production. It might be a simple typo but I am not sure of that and I do not have time to make this rock solid - at least not today.
Good luck
Jang