Created
April 6, 2011 19:26
-
-
Save arantius/906344 to your computer and use it in GitHub Desktop.
GM_xmlhttpRequest Alert Interference Test
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 GM_xmlhttpRequest Alert Interference Test | |
// @include http* | |
// ==/UserScript== | |
// Uses unsafeWindow.dump() because of | |
// https://github.com/greasemonkey/greasemonkey/issues#issue/1229 | |
function doSampleXhr() { | |
unsafeWindow.dump('starting gm_xhr ...'); | |
try { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "http://localhost/", | |
onload: function() { unsafeWindow.dump('gm_xhr loaded\n'); }, | |
onerror: function() { unsafeWindow.dump('gm_xhr failed\n'); } | |
}); | |
} catch (e) { unsafeWindow.dump(e+'\n'); } | |
unsafeWindow.dump(' done\n'); | |
} | |
var now = (new Date()).valueOf(); | |
var then = parseInt(GM_getValue('last alert', 0), 10); | |
if (now - then > 60000) { | |
alert('Showing an alert which will break GM_xhr\n' | |
+ '(At URL: '+location.href+')'); | |
GM_setValue('last alert', String(now)); | |
} | |
doSampleXhr(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment