User talk:Arantius
From GreaseSpot Wiki
Greasemonkey -> XPI compiler: how to detect when a script is running under it?
Hello, Arantius. I am using your compiler to port one of my userscripts into a firefox extension. The script has got some features that are useful while it's still a script (e.g.: checking for new versions), but completely useless - or, worse, even dangerous - if running as a FF extension. Is there a way to detect whether the script is running thanks to the script-compiler.js or not? I was thinking about a variable, maybe something simple like MOUNTED = True on loading of the script and False on unloading, but how to achieve that? Or do you have any better suggestion? Thanks a lot, and keep on doing your great job :) Daniele
- There isn't a good way now. The easiest would be to test for the presence of an API newer than the compiler, e.g. GM_listValues. If that function exists, it's not the compiler, because the compiler doesn't provide it. Arantius 22:00, 19 October 2010 (UTC)
- I've apparently found a workaroud: in Load and onUnLoad events on script-compiler.js, I toggle a boolean preference (script-compiler_active), that I then read from inside the script; it seems to be working. Daniele (77.42.60.138 12:59, 20 October 2010 (UTC))