Skip to content

Instantly share code, notes, and snippets.

@Pandry
Last active July 8, 2017 13:13
Show Gist options
  • Save Pandry/2e447177ed8e016c414c8287c619f580 to your computer and use it in GitHub Desktop.
Save Pandry/2e447177ed8e016c414c8287c619f580 to your computer and use it in GitHub Desktop.
Little code to paste in the console to get the price of a list on amazon. (You need to open the list than execute the code)
var elementPrice = document.getElementsByClassName("a-size-base a-color-price a-text-bold");
var elementusedprice = document.getElementsByClassName("a-color-price itemUsedAndNewPrice");
var countedItems = 0;
var totalprice = 0.0;
for (var i = 0; i < elementPrice.length; i++){
var price = parseFloat(elementPrice[i].innerText.replace(",",".").substring(4));
if(isNaN(price)){
price = parseFloat(elementusedprice[i].innerText.replace(",",".").substring(4));
}
if(!isNaN(price)){
totalprice += price;
countedItems++;
}else{
console.log(i)
}
}
var textDiv = document.getElementById("list-header");
var newDiv = "<div>Total price: " + totalprice.toFixed(2) +" Counted elements: " + countedItems+"</div>" ;
var dp = new DOMParser();
textDiv.appendChild(dp.parseFromString(newDiv, "application/xml").documentElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment