Skip to content

Instantly share code, notes, and snippets.

@bphamict
Last active September 10, 2023 06:03
Show Gist options
  • Select an option

  • Save bphamict/3bcae947d149e0dca71f5da860080ef6 to your computer and use it in GitHub Desktop.

Select an option

Save bphamict/3bcae947d149e0dca71f5da860080ef6 to your computer and use it in GitHub Desktop.
modify number on random.org with XHR request
// ==UserScript==
// @name random.org
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Modify number on random.org with XHR request
// @author bphamict
// @match https://www.random.org/widgets/integers/iframe*
// @icon https://www.google.com/s2/favicons?domain=random.org
// @grant none
// @homepage https://gist.github.com/bphamict/3bcae947d149e0dca71f5da860080ef6
// @updateURL https://gist.github.com/bphamict/3bcae947d149e0dca71f5da860080ef6/raw/random.org.user.js
// @downloadURL https://gist.github.com/bphamict/3bcae947d149e0dca71f5da860080ef6/raw/random.org.user.js
// ==/UserScript==
const winNums = [1, 2, 3];
(function() {
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
this.addEventListener('readystatechange', function() {
if (this.readyState === 4) {
var num = winNums.shift();
if (num) {
var responseText = this.responseText;
var e = document.createElement('div');
e.innerHTML = responseText;
e.getElementsByTagName('span')[0].innerText = num + '\n';
Object.defineProperty(this, 'responseText', {writable: true});
this.responseText = e.innerHTML;
}
}
});
return open.apply(this, arguments);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment