Unfortunately, script is probably not usable here:
From the github page:
specifically, I wrote this with the forthcoming Vim Stack Exchange site in mind
From the script docu:
Certain interactive commands, such as vi(1), create garbage in the typescript file.
script works best with commands that do not manipulate the screen, the results are meant
to emulate a hardcopy terminal.
Other than that, I'm inclined to have a look at op's code to see if one might break out the gif-encoding to a sepearate bit -- and "encode" for js/html playback (as well, or in place of) video/gif.
Years ago I rewrote rxvt in javascript. https://github.com/paddymul/rxvt-js my aim was to create a terminalcast recording site. my rxvt implementation doesn't work with color, but it can succesfully redisplay an emacs session with split windows.
Please, hack on the code, this is something that should exist.
From the github page:
From the script docu: