Skip to content

Instantly share code, notes, and snippets.

@ChrisMBarr
Created August 1, 2012 20:42
Show Gist options
  • Save ChrisMBarr/3230548 to your computer and use it in GitHub Desktop.
Save ChrisMBarr/3230548 to your computer and use it in GitHub Desktop.
Total up the cost of all items in an Amazon wishlist
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));
@ryanjm
Copy link

ryanjm commented May 8, 2015

Made it a bookmarklet:

javascript: (function(){
var list = document.querySelectorAll('span.a-color-price.a-size-base');
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));
}() );

@mayel
Copy link

mayel commented Aug 14, 2015

Fixed it to work when any items are unavailable:

var list = $$("span.a-size-base.a-color-price");
var total=0;
for(i=0; i<list.length;i++){
  var n = parseFloat(list[i].innerText.replace("$","").replace(",",""));  
  if(n === Number(n)) total += parseFloat(n);
}
alert(list.length+" items for a total of: $"+total.toFixed(2));

@imemohit
Copy link

For amazon.in, the following works for me:

var list = $$('.price-section');
var total=0;
for(i=0; i<list.length;i++){
  total += (parseFloat(list[i].innerText.replace(',','')));
}
alert(list.length+" items for a total of: Rs. "+total.toFixed(2));

@mrworf
Copy link

mrworf commented Sep 14, 2017

Here's my $0.05

var list = $$('.a-price'); var total=0; for(i=0; i<list.length;i++){ total += parseFloat(list[i].innerText.split("\n")[0].substring(1).replace(',','')); } "Total: $" + Math.ceil(total);

Paste that into the console with the relevant whishlist visible on Amazon.com and it will give you the total (rounded up to nearest dollar)

CAVEAT
If you don't scroll to the bottom before running it, you'll only get whatever is visible on screen due to dynamic loading amazon now uses.

@jmverges
Copy link

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");

@aquelegabes
Copy link

aquelegabes commented Nov 5, 2018

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);

@silasjmatson
Copy link

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)

@namero999
Copy link

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)

@s0kil
Copy link

s0kil commented May 20, 2021

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