Skip to content

Instantly share code, notes, and snippets.

@jeffwesson
Created August 4, 2015 06:38
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/76c376f68a4efb237405 to your computer and use it in GitHub Desktop.
Save jeffwesson/76c376f68a4efb237405 to your computer and use it in GitHub Desktop.
WIP: Get subtotal for all items in a given amazon wishlist
var divs = document.getElementsByTagName("div");
var products = [];
for (var i = 0; i < divs.length; i ++) {
if (/^item_price_/.test(divs[i].id)) {
products.push(divs[i]);
}
}
var rawPrices = [];
var priceClass = /-price\b/;
for (var j = 0; j < products.length; j++) {
for (var k = 0; k < products[j].children.length; k++) {
for (var l = 0; l < products[j].children[k].classList.length; l++) {
if (priceClass.test(products[j].children[k].classList[l])) {
rawPrices.push(products[j].children[k].innerText);
}
}
}
}
var priceRe = /^\$[0-9]*\.?[0-9]{0,2}\b/;
var truePrices = [];
rawPrices.forEach(function(rawPrice) {
if (priceRe.test(rawPrice)) {
truePrices.push(rawPrice.replace("$", ""));
}
});
var actualPrices = [];
truePrices.forEach(function(truePrice) {
actualPrices.push(new Number(truePrice));
});
var total = 0;
actualPrices.filter(function(amount) {
total += amount;
});
console.log(total);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment