Skip to content

Instantly share code, notes, and snippets.

@crashmax-dev
Created December 24, 2024 18:25
Show Gist options
  • Save crashmax-dev/ab39371030949f9dc11acd462578e600 to your computer and use it in GitHub Desktop.
Save crashmax-dev/ab39371030949f9dc11acd462578e600 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name fake-random-userscript
// @version 0.0.0
// @license MIT
// @match https://www.random.org/widgets/integers/*
// ==/UserScript==
(function() {
"use strict";
function l(n, t, o) {
const e = new MutationObserver((i, c) => {
for (const s of i)
t(s, c);
});
return e.observe(n, {
childList: true,
subtree: true,
...o
}), () => e.disconnect();
}
let resultIndex = 0;
const fakeResults = [
42,
32,
100,
69
];
function getResultNumber() {
const result = fakeResults[resultIndex];
resultIndex++;
if (result === void 0) return;
return result;
}
l(document.body, (mutation) => {
if (mutation.addedNodes.length === 2) return;
const el = document.evaluate(
"/html/body/div/span[5]",
document,
null,
XPathResult.ANY_TYPE,
null
);
const span = el.iterateNext();
if (!span) return;
const result = span.querySelector("center > span");
if (!result) return;
const resultNum = getResultNumber();
const num = Number(result.textContent);
if (Number.isNaN(num) || resultNum === void 0) return;
result.innerHTML = `${resultNum}<br>`;
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment