Skip to content

Instantly share code, notes, and snippets.

@partikus
Created January 21, 2019 16:27
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 partikus/3fe338a4b7727e1937e83cf103d48f78 to your computer and use it in GitHub Desktop.
Save partikus/3fe338a4b7727e1937e83cf103d48f78 to your computer and use it in GitHub Desktop.
Wielka Orkiestra
// simple JS script to parse and sum of donations for the chosen city
// usage
// 1. copy&paste below script
// 2. choose the city manually
// 3. then call e.g. `sum().then(alert)` or sum().then(sum => { console.log(sum); })
sumDonations = () => {
return [...document.querySelectorAll('.institution .value').values()].map(e => parseFloat(e.innerText)).reduce((a,b) => a + b, 0)
}
formatCurrency = (input, locale = 'pl-PL', currencyCode = 'PLN') => {
return new Intl
.NumberFormat(locale, { style: 'currency', currency: currencyCode })
.format(input);
}
sum = () => {
return Promise
.resolve(sumDonations())
.then(sum => formatCurrency(sum))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment