I tried but the same result. New lines are eliminated, but there is a section in the footer where the function is not applied.
The problem seems to be that those comments are not processed by the Autoptimize or my function (as you suggested). This comments appear due a setting on a slider plugin to put its JS code in the footer and i think its hook runs after your plugin.
All the lines are eliminated until i get this.
<script type='text/javascript'>
/* <![CDATA[ */
var ATTR = {"enable":"enable","width":"80","height":"45"};
/* ]]> */
</script>
There is a way/hook to scan and preg replace the entire source code after the entire code is loaded? I have set the priority in the add_filter to 999, but no luck.