Last active
December 17, 2019 23:28
-
-
Save p0358/2d5e3195187bf2fa690b60ea7c435395 to your computer and use it in GitHub Desktop.
Aaaaaaa aa aaaa aa aaaa aaaa "A" aaa "a" aaaaaaa ("A language", aaaaaaaa aAaaaa aaaa)
This file contains 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
(function(){ | |
// Aaa aaaaaa: | |
// Get all text nodes in a given container | |
// Source: http://stackoverflow.com/a/4399718/560114 | |
function getTextNodesIn(node, includeWhitespaceNodes) { | |
var textNodes = [], nonWhitespaceMatcher = /\S/; | |
function getTextNodes(node) { | |
if (node.nodeType == 3) { | |
if (includeWhitespaceNodes || nonWhitespaceMatcher.test(node.nodeValue)) { | |
textNodes.push(node); | |
} | |
} else { | |
for (var i = 0, len = node.childNodes.length; i < len; ++i) { | |
getTextNodes(node.childNodes[i]); | |
} | |
} | |
} | |
getTextNodes(node); | |
return textNodes; | |
} | |
var textNodes = getTextNodesIn( document, false ); | |
var i = textNodes.length; | |
var node; | |
while (i--) { | |
node = textNodes[i]; | |
node.textContent = node.textContent.replace(/([A-Z])/g, "A").replace(/([a-z])/g, "a"); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment