Created
August 26, 2016 19:37
-
-
Save aminrasouli/5445bd4b66526d7698b73c78d8957937 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
String.prototype.toPersianDigit = function (a) { | |
return this.replace(/\d+/g, function (digit) { | |
var enDigitArr = [], peDigitArr = []; | |
for (var i = 0; i < digit.length; i++) { | |
enDigitArr.push(digit.charCodeAt(i)); | |
} | |
for (var j = 0; j < enDigitArr.length; j++) { | |
peDigitArr.push(String.fromCharCode(enDigitArr[j] + ((!!a && a == true) ? 1584 : 1728))); | |
} | |
return peDigitArr.join(''); | |
}); | |
}; | |
function TraceNodes(Node) { | |
if (Node.nodeType == 3) //TextNode | |
Node.nodeValue = Node.nodeValue.toPersianDigit(); | |
else | |
for (var i = 0; i < Node.childNodes.length; i++) | |
TraceNodes(Node.childNodes[i]); | |
} | |
TraceNodes(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment