Last active
July 8, 2017 13:13
-
-
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)
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 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