Advertisement
Guest User

[Bookmarklet]Automatically TotaPrices on Amazon Offers Page

a guest
Sep 9th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. divsToUpdate = document.getElementsByClassName("olpOffer");
  2. var i = 0;
  3. while (i < divsToUpdate.length){
  4.     var d = divsToUpdate[i];
  5.     var o = d.getElementsByClassName("olpOfferPrice")[0];
  6.     var p = o.innerText;
  7.     //var amountRegex = new RegExp(/[0-9\.]+/ig);
  8.     //console.log("Parent: ",d);
  9.     //console.log("Span  : ",p);
  10.     //console.log("Regex : ",amountRegex.exec(p));
  11.     var amountRegex = new RegExp(/[0-9\.]+/ig);
  12.     var cost = amountRegex.exec(p);
  13.     //console.log("Cost  : ",cost);
  14.  
  15.     // not all have a shipping price
  16.     var shipping = 0.0;
  17.     var s = d.getElementsByClassName("olpShippingPrice")[0];
  18.     if (s !== undefined) {
  19.         var amountRegex = new RegExp(/[0-9\.]+/ig);
  20.         shipping = amountRegex.exec(s.innerText);
  21.     }
  22.     //console.log(d);
  23.     var c = parseFloat(cost) + parseFloat(shipping);
  24.     //console.log("Actual Price: " + c);
  25.  
  26.     // now replace the big red price with the ACTUAL price
  27.     o.removeAttribute("class", "a-size-large");
  28.     actualPrice = document.createElement("span");
  29.     actualPrice.className = "a-size-large a-color-price olpOfferPrice a-text-bold";
  30.     actualPrice.innerText = c;
  31.     o.parentElement.insertBefore(actualPrice, o.parentElement.firstChild);
  32.  
  33.     i++;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement