[Greasemonkey] function failed in 0.64
Jeremy Dunck
jdunck at gmail.com
Tue Jan 3 17:17:01 EST 2006
On 1/3/06, Chris Hayes <chayes at antenna.nl> wrote:
> Oh yeah I forgot to mention them, they are simply wrappers.
> I made the attachment which shows the same error.
> Since it is so short I will save you the effort to open the attachment
> if you do not want to install it:
>
> unsafeWindow.GM_SET = function(name,val){GM_setValue(name,val);}//wrapper
> unsafeWindow.GM_GET = function(name){return GM_getValue(name);}//wrapper
> unsafeWindow.GM_GETorDEFAULT = function(name,defaultValue){if
> (!GM_GET(name)) GM_SET(name,defaultValue); return GM_getValue(name);}
>
> var BannedUsers = GM_GETorDEFAULT('BannedUsers','|');
Any time you use a variable without qualifying it, the scope chain is used.
You're assigning an anonymous function to unsafeWindow, which isn't in
the sandbox's scope chain (on purpose).
You either want this:
===
function GM_GETorDEFAULT(name,defaultValue){if
(!GM_GET(name)) GM_SET(name,defaultValue); return GM_getValue(name);}
unsafeWindow.GM_GETorDEFAULT = GM_GETorDEFAULT
===
or this:
===
var BannedUsers = unsafeWindow.GM_GETorDEFAULT('BannedUsers','|');
===
or even this:
===
function GM_GETorDEFAULT(name,defaultValue){if
(!GM_GET(name)) GM_SET(name,defaultValue); return GM_getValue(name);}
var BannedUsers = GM_GETorDEFAULT('BannedUsers','|');
===
But here's my obligatory warning. You're directly assigning an API
function to unsafe Window. Pretty please don't do that. Doing that
allows page content to do evil things, like fill up your prefs store
at least, and possibly worse. GM_*Value is one of the lesser dangers,
but it's just a bad habit to get into.
Without seeing the wider context of what you're doing, it's hard for
me to know a better approach, but this might be good:
unsafeWindow.GetBannedUsers = function() { return
GM_GETorDEFAULT('BannedUsers','|'); }
More information about the Greasemonkey
mailing list