Skip to content

Instantly share code, notes, and snippets.

@ali-master
Created May 6, 2023 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ali-master/40def25cf445e675f67c3b107a2e4a08 to your computer and use it in GitHub Desktop.
Save ali-master/40def25cf445e675f67c3b107a2e4a08 to your computer and use it in GitHub Desktop.
Convert HTML document numbers to Persian Digits
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