iitc-project / ingress-intel-total-conversion

ingress.com/intel total conversion user script with some new features. Should allow easier extension of the intel map.
http://iitc.jonatkins.com/
ISC License
991 stars 553 forks source link

Optimize plugin wrapper #367

Open fkloft opened 11 years ago

fkloft commented 11 years ago

Is there a specific reason to append

var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ wrapper +')();'));
(document.body || document.head || document.documentElement).appendChild(script);

after each plugin instead of calling wrapper() directly?

The current implementation has some major drawbacks. The code is first parsed, then wrapper.toString() is implicitly called to add the source into the <script> element, which is then parsed again. This is

jonatkins commented 11 years ago

The same applies to the main IITC script too (end of main.js)

I believe it's done like this so all the code runs within the context of the page itself, rather than any separate context used by Greasemonkey/Tampermonkey