function replace(target) { target.normalize(); var x = document.evaluate('descendant::text()', target, null, 6, null); for (var i = 0, len = x.snapshotLength; i < len; i++) { var textNode = x.snapshotItem(i); textNode.nodeValue = textNode.nodeValue.replace(PATTERN_SHORTCUT, function($0) PATTERN[$0.toLowerCase()]); } } })();