Skip to content

Instantly share code, notes, and snippets.

@mahdizojaji
Last active February 12, 2024 14:11
Show Gist options
  • Save mahdizojaji/ba932fe52d2a730a5c62e132acdb67bc to your computer and use it in GitHub Desktop.
Save mahdizojaji/ba932fe52d2a730a5c62e132acdb67bc to your computer and use it in GitHub Desktop.
buynow paid calculator
var total = 0;
const paid_amounts = document.getElementsByClassName("purchase-amount-number");
var persianNumbers = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g];
var arabicNumbers = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
fixNumbers = function (str)
{
if(typeof str === 'string')
{
for(var i=0; i<10; i++)
{
str = str.replace(persianNumbers[i], i).replace(arabicNumbers[i], i);
}
}
return str;
};
for(e of paid_amounts)
{
total += parseInt(fixNumbers(e.innerHTML.trim().replace(",", "")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment