Could an alternative approach be to deliver the JS via a custom HTML block, rather than Additional HTML?
This way you can be more targetted, and deploy the block within certain courses, or across certain categories, rather than sitewide.
The other approach (although it would require much more maintenance) is to create a blacklist of course ID's, and use JS conditionals to break out of the code if they are in the blacklist.
Are you using Snap? If so, it helps you greatly here. It adds the current course ID as a class to the body tag, and this class is available in every page/tool within the course, eg: this is in a book
<body id="page-mod-book-view" class=".... course-2644 ....">
You could extend your current JS to get this body class value, compare it to the blacklist and then either execute the rest of the code, or break out.