[Greasemonkey] Convert links to TinyURLs
Anthony Lieuallen
arantius at gmail.com
Fri Aug 25 10:44:25 EDT 2006
On 8/25/2006 3:20 AM, Brendan J wrote:
> Also, I was wondering if there was a cleaner way ... to pass
> variables through these functions?
Yes, it's called a closure. This script will alert "myval" when the
request is complete because it still has a reference to the global
"myVar" variable. You'd want to create a closure that gives you a
reference to the original DOM (anchor) object.
> // ==UserScript==
> // @name Variable Inside GM_xhr
> // @include *
> // ==/UserScript==
>
> var myVar='myval';
>
> GM_xmlhttpRequest({
> method: 'GET',
> url: 'http://www.google.com/',
> onload: function(responseDetails) {
> alert(myVar);
> }
> });
http://www.jibbering.com/faq/faq_notes/closures.html
More information about the Greasemonkey
mailing list