I've tested this script in a much larger site/file.
It sort of works, but there's two problems:
(1) It only removes the last two characters of the classes defined. (see point c in first post).
(2) It moves the content to the wrong place. I think this is because of the $('body').append part but I can't see how to set it to go to the place it should do. I'm guessing if I tested completely stand alone then $('body').append is right as I think that means just inside the <body>, but if the HTML is anywhere else that won't work.