Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Created November 26, 2021 22:54
Show Gist options
  • Select an option

  • Save eusonlito/403e5b57f36295cd3d99aa30a413f6e4 to your computer and use it in GitHub Desktop.

Select an option

Save eusonlito/403e5b57f36295cd3d99aa30a413f6e4 to your computer and use it in GitHub Desktop.
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