The easiest way would be to replace
$content = $toc . $content;
with
$content = str_replace( '[toc]', $toc, $content );
This would do a search for the string [toc] and replace it with the table of contents.
It might be more complicated due to how the plugin would work, but on paper it is simple.