Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Javascript to randomize every number in a HTML page
document.querySelectorAll('body *').forEach(function (e) {
const html = e.innerHTML;
if (!html || !html.match(/^[0-9\-\.\,\s]+$/)) {
return;
}
const chars = html.split('');
for (i = 0; i < chars.length; i++) {
if (chars[i].match(/[0-9]/)) {
chars[i] = Math.floor(Math.random() * 10);
}
}
e.innerHTML = chars.join('');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment