[Greasemonkey] Script scoping

Paul Roub paul at roub.net
Wed May 4 12:51:20 EDT 2005


Jeremy Dunck wrote:
> On 5/4/05, Paul Roub <paul at roub.net> wrote:
> 
>>An inside-out approach to that might be a GM event you could subscribe
>>to -- e.g.
>>
>>       GM_notifyOnLoad('otherscriptname', myfunction);
> 
> 
> Interesting.  What happens if the script doesn't get notified?  How
> does the user know why the dependent script doesn't do anything?
> _______________________________________________

How do they know now, when the other script is missing?  We can be at 
least as friendly and helpful as JS Console errors :-)

Easy enough for GM to do this -- GM has the list of notify-on-load 
scripts, and their subscribers.  When GM is all done loading whatever 
user scripts it's ever going to load for this page, it runs through the 
list, looking for any notifications that were never issued.  If it finds 
that myscript.user.js is waiting for the l33tlib.user.js that never 
loaded, we notify the user somehow.  And again, that notification can 
easily be more user friendly than the current case.

Nice things about this approach:

1.	The user doesn't care about the ordering, or even know about it, 
unless something breaks

2.	It's right there in the script, so we don't have to define / 
overwrite / update any new metadata

3.	It's lightweight.  No timers, no polling, no DOM-sniffing.

-paul


More information about the Greasemonkey mailing list