Thank you Erik.
Now my code is:
MobyUtils = {
apiKeyCache: GM_getValue("mobypicture.api.key"),
getKey: function(){return this.apiKeyCache;},
///.....
};
On Wed, Oct 28, 2009 at 3:57 AM, Erik Vold <[email protected]> wrote:
>
> This type of thing usually happens because you attached an event
> listener to a DOM element which calls MobyUtils.getThumbUrl(). The
> unsafeWindow is not allowed to call functions you define in your
> userscripts because if it were then webmasters could write could
> potentially get access to a GM api feature such as GM_xmlhttpRequest()
> and make cross site requests which they cannot do normally.
>
> > So, how can I get the returned value from GM_getValue() properly?
>
> Store the GM_getValue() in a js variable (which your event listener
> can access) on page load and every time you update the var with
> GM_setValue().
>
> On Oct 27, 1:31 am, darasion <[email protected]> wrote:
> > Hi everyone,
> >
> > Please forgive my not-so-well English.
> >
> > I have already readhttp://
> wiki.greasespot.net/0.7.20080121.0_compatibility.
> > The script I am writing is to display picture thumbnails from links
> > likehttp://moby.to/rrrg1x.
> >
> > I got 'Greasemonkey access violation: unsafeWindow cannot call
> > GM_getValue.' errors when I call MobyUtils.getThumbUrl() function. And
> > the code is listed below.
> >
> > I am not sure whether the GM_getValue was called in unsafeWindow,
> > because I am not using the 'unsafeWindow' word at all. I just want to
> > load the api key at run time via getKey method.
> >
> > So, how can I get the returned value from GM_getValue() properly?
> >
> > Thanks.
> >
> > MobyUtils = {
> >
> > apiKeyStorage: "mobypicture.api.key",
> > apiKeyCache: '',
> >
> > setKey:function(key){
> > GM_setValue(this.apiKeyStorage,key);
> > },
> >
> > getKey: function(){
> > return this.apiKeyCache || ( this.apiKeyCache =
> GM_getValue
> > (this.apiKeyStorage) );
> > },
> >
> > getThumbUrl: function(tinyUrlCode, size, format, callback){
> >
> > if('function' === typeof size){
> > callback = size;
> > size = null;
> > }
> >
> > if('function' === typeof format){
> > callback = format;
> > format = null;
> > }
> >
> > size = size || 'small';
> > format = format || 'json';
> >
> > url = 'http://api.mobypicture.com/?action=getThumbUrl'
> > + '&t=' + encodeURIComponent(tinyUrlCode)
> > + '&s=' + size
> > + '&k=' + encodeURIComponent(this.getKey())
> > + '&format=' + format;
> >
> > tFormat = (format == 'plain')?'text':format;
> >
> > $.ajax({
> > 'url': url,
> > 'type': 'GET',
> > 'success': function(data, status){callback(data,
> status)},
> > 'dataType': tFormat
> > });
> >
> > }
> >
> > };
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---