LibreJS is a Firefox add-on that does roughly what you describe. If a piece of Javascript code is not properly annotated with a license (for example in a comment block at the top) it refuses to execute it.
https://www.gnu.org/software/librejs/
https://www.gnu.org/software/librejs/free-your-javascript.ht...
It can be a bit fickle. I recently tried to make code comply with it and it didn't initially work because I was using a non-standard version of the ISC license with one different word.
Even if nearly everyone uses GPL for their JavaScript, you still need to go through this process for every site that may use non-free software, which is a royal pain.
Perhaps a "better" solution is to fight to have browsers check the license of JavaScript before loading it (either prompt the user, or have a browser setting for acceptable licenses), but that's a much harder battle than promoting JavaScript-less web pages, especially since the user has control of blocking JavaScript today.