Skip to content

Instantly share code, notes, and snippets.

@arantius
Created June 7, 2013 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arantius/5729861 to your computer and use it in GitHub Desktop.
Save arantius/5729861 to your computer and use it in GitHub Desktop.
// ==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