Created
November 26, 2021 22:54
-
-
Save eusonlito/403e5b57f36295cd3d99aa30a413f6e4 to your computer and use it in GitHub Desktop.
Javascript to randomize every number in a HTML page
This file contains hidden or 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
| 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