Created
August 1, 2012 20:42
-
-
Save ChrisMBarr/3230548 to your computer and use it in GitHub Desktop.
Total up the cost of all items in an 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 list = $$("#item-page-wrapper .list-items table tbody .lineItemMainInfo .lineItemPart strong"); | |
var total=0; | |
for(i=0; i<list.length;i++){ | |
total += parseFloat(list[i].innerText.replace("$","")); | |
} | |
alert(list.length+" items for a total of: $"+total.toFixed(2)); |
amazon br
var list = $$('.a-price'); var total=0;
for (var i = 0; i < list.length; i++) {
total += parseFloat(list[i].innerText.split("R$")[1].replace(',','.')) ;
}
console.log("Total = " + total);
You can use the data-price
attribute on the li
. Tested on amazon com.
$$("li[data-price]").reduce((amount, li) => amount + parseFloat(li.getAttribute('data-price'), 0), 0.0)
This version takes into account elements without a price (such as items not available)
$$("li[data-price]").reduce((amount, li) => amount + Math.max(0, parseFloat(li.dataset['price'])), 0.0)
Latest Version:
$$('.a-price').map(_ => _.firstChild.innerText.replace('$', '')).map(_ => parseFloat(_)).reduce((a, v) => a + v)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
amazon.es
var list = $$(".a-offscreen");
var total=0;
var numHidden = 0;
var temp=0;
for(i=0; i<list.length;i++){
temp = parseFloat(list[i].innerText.replace(" €","").replace(',','.'));
numHidden += isNaN(temp);
total += isNaN(temp) ? 0 : temp;
}
console.log(list.length - numHidden +" items for a total of: "+total.toFixed(2) + "€ less " + numHidden + " Hidden Items");