Created
March 9, 2016 02:30
-
-
Save shlevy/3fd96b0c230471bdcf4e to your computer and use it in GitHub Desktop.
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
| var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); | |
| while (walker.nextNode()) { | |
| var newText = walker.currentNode.nodeValue.replace(/(\d+\s*)?π/g, function (match, multiplierString) { | |
| var multiplier = parseInt(multiplierString.trim(), 10); | |
| if (isNaN(multiplier)) { | |
| return "τ/2"; | |
| } else if (multiplier == 2) { | |
| return "τ"; | |
| } else { | |
| return (multiplier / 2).toString() + "τ" + ((multiplier % 2 == 0) ? "" : "/2"); | |
| } | |
| }); | |
| if (newText != walker.currentNode.nodeValue) { | |
| walker.currentNode.nodeValue = newText; | |
| } | |
| } |
Author
Yeah, I realized that shortly after posting. Didn't expect anyone to find this except through my original post about it, I'm curious how you did?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 11 seems incorrect? i.e. 5π will turn into 2.5τ/2 if i'm reading it correctly.