Skip to content

Instantly share code, notes, and snippets.

@broquaint
Created June 21, 2011 11:15
Show Gist options
  • Save broquaint/1037642 to your computer and use it in GitHub Desktop.
Save broquaint/1037642 to your computer and use it in GitHub Desktop.
Working example of GM_xmlhttpRequest speaking XML
// ==UserScript==
// @name gde33 XML example
// @namespace https://github.com/broquaint
// @description Working example of GM_xmlhttpRequest speaking XML
// @include http://en.wikipedia.org/wiki/Main_Page
// ==/UserScript==
// For some reason console.log wasn't working, too lazy to investigate why.
unsafeWindow.console.log("Requesting stuff!");
GM_xmlhttpRequest({
method: 'GET',
url: 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&revids=375536&rvdiffto=prev&format=xml',
onload: function(response) {
var xml = new DOMParser()
.parseFromString(response.responseText, "text/xml");
unsafeWindow.console.log("The response was: ", xml);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment