|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
How to get the returned value from GM_getValue() in unsafeWindow ?Hi everyone, Please forgive my not-so-well English. I have already read http://wiki.greasespot.net/0.7.20080121.0_compatibility. The script I am writing is to display picture thumbnails from links like http://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 greasemonkey-users@... To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@... For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: How to get the returned value from GM_getValue() in unsafeWindow ?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 <daras...@...> 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 greasemonkey-users@... To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@... For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: How to get the returned value from GM_getValue() in unsafeWindow ?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 <erikvvold@...> wrote:
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To post to this group, send email to greasemonkey-users@... To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@... For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |