Created
June 7, 2013 14:57
-
-
Save arantius/5729861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name XHR Context | |
// @namespace http://github.com/arantius | |
// @include http* | |
// @version 1 | |
// ==/UserScript== | |
// See: https://github.com/greasemonkey/greasemonkey/issues/1725 | |
(function() { | |
// Note that "r" lives in this anonymous function's private scope! | |
var r = Math.random(); | |
console.log('Starting request, r =', r); | |
GM_xmlhttpRequest({ | |
'method': 'GET', | |
'url': '/', | |
'onload': onResponse, | |
'context': r, | |
}); | |
})(); | |
function onResponse(response) { | |
// But here onResponse can read it via the context property. | |
console.log('Request complete; context =', response.context); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment