Last active
January 9, 2018 15:02
-
-
Save fnlctrl/a65b6ac9e269bd414b9d6375f3d4310b to your computer and use it in GitHub Desktop.
Calculate steam purchases
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
var currencies = ['USD', 'pуб.', '¥'] | |
Array.prototype.reduce.call( | |
document.body.querySelectorAll(".wht_total"), | |
(acc, x) => { | |
const rawPrice = x.textContent.trim(); | |
let number = 0; | |
let currency = ''; | |
for (let i = 0; i < currencies.length; i++) { | |
let potentialPriceStr = rawPrice.split(currencies[i]); | |
if (potentialPriceStr.length > 1) { | |
let rawNumber = potentialPriceStr.find(i => /\d/.test(i)) | |
if (rawNumber) { | |
let matched = rawNumber.match(/\d+\.+\d+|\d+\,\d+|\d+/) | |
if (matched) { | |
number = parseFloat(matched[0].replace(',', '')); | |
currency = currencies[i]; | |
break; | |
} | |
} | |
} | |
} | |
if (number > 0) { | |
acc[currency] = (acc[currency] || 0) + number | |
} | |
return acc; | |
}, {} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue: gift and refund.
Refund will with css class
wht_refunded