Created
August 4, 2015 06:38
-
-
Save jeffwesson/76c376f68a4efb237405 to your computer and use it in GitHub Desktop.
WIP: Get subtotal for all items in a given amazon wishlist
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 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