Skip to content

Instantly share code, notes, and snippets.

@fnlctrl
Last active January 9, 2018 15:02
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 fnlctrl/a65b6ac9e269bd414b9d6375f3d4310b to your computer and use it in GitHub Desktop.
Save fnlctrl/a65b6ac9e269bd414b9d6375f3d4310b to your computer and use it in GitHub Desktop.
Calculate steam purchases
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;
}, {}
)
@lingsamuel
Copy link

lingsamuel commented Mar 4, 2017

Issue: gift and refund.

Refund will with css class wht_refunded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment