Skip to content

Instantly share code, notes, and snippets.

@jeffwesson
Created August 9, 2017 04:35
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 jeffwesson/127f1d69d04df3250bdb5a631d22b5c6 to your computer and use it in GitHub Desktop.
Save jeffwesson/127f1d69d04df3250bdb5a631d22b5c6 to your computer and use it in GitHub Desktop.
Sums items in a baby registry on Buy Buy Baby
Array.prototype.slice.call(document.querySelectorAll('.productRow .productContainer .productContent')).reduce((a, item) => {
let o = {};
o['requested'] = parseInt(item.querySelector('.requested').innerText.replace(/\D/g, ''));
o['purchased'] = parseInt(item.querySelector('.purchase').innerText.replace(/\D/g, ''));
o['price'] = parseFloat((item.querySelector('.rlpPrice') || item.querySelector('.toalpriceLtl')).innerText.replace(/[^\d\.]/g, ''));
a.push(o);
return a;
}, []).filter(item => item.requested !== item.purchased).reduce((s, item) => {
s += item.price * item.requested - item.purchased;
return s;
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment