That code likely has to be completely rewritten. You can find documentation on the onchange event for the ckeditor here:
https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#event-change
It will looks something like this at the bottom of the page:
<script>
CKEDITOR.instances.editor1.on('change', function() {
console.log("TEST");
});
</script>