It looks like you're using the old way of doing magic words, which stopped working in 1.19.
Second of all, you should not use OutputPage inside the parser (you need to use ParserOutput). Otherwise, the results will only work on non-cached pages. Instead of $out->addModule, use $parser->getOutput()->addModules()
It is also possible that the javascript might load before the page loads, so it should probably be inside a onDOMContentLoaded callback (E.g. the $() operator). Alternatively the CSS could just be changed to do for both the ToC and non-TOC case and then the JS wouldn't be necessary, and not using JS would make things show up instantly instead of having a short flash where things weren't numbered (Assuming that addModuleStyles was used instead of addModules()) .
--
Brian