Last active
August 29, 2015 14:02
-
-
Save akanix42/0ffc66cb92bb54cec8cf to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Amazon Wishlist Total | |
// @namespace http://use.i.E.your.homepage/ | |
// @version 0.1 | |
// @description enter something useful | |
// @match http://www.amazon.com/gp/registry/wishlist/* | |
// @copyright 2012+, You | |
// @require http://code.jquery.com/jquery-latest.js | |
// ==/UserScript== | |
var list = $("span.a-size-small.a-color-price, span.a-size-base.a-color-price"); | |
var total=0; | |
for(i=0; i<list.length;i++){ | |
var item = list[i]; | |
var itemId = item.id.replace(/.*_/, ''); | |
var itemTotal = parseFloat(item.innerText.replace("$","").replace(",","")); | |
var quantity = parseInt($('#itemRequested_'+itemId).text() || $('[name="requestedQty.'+itemId+'"]').val()) || 1; | |
console.log($('[name="requestedQty.'+itemId+'"]')); | |
total += itemTotal * quantity; | |
console.log('quantity ' + quantity); | |
} | |
total = total.toLocaleString(); | |
var numberOfItems = getNumberOfItems(list.length); | |
var totalHtml = getHtml().replace('{subtotal}', total).replace('{numberOfItems}', numberOfItems); | |
$('#item-page-wrapper') | |
.before(totalHtml) | |
.removeClass('a-hidden'); | |
function getHtml(){ | |
return '<div id="" class="a-row a-spacing-none"><div class=\"a-box-group a-spacing-none a-spacing-top-base g-bulk-atc-result hidden g-bulk-atc-box\" style=\"overflow: hidden; display: block;\">\n <div class=\"a-box a-first a-box-normal a-color-offset-background\"><div class=\"a-box-inner\">\n <div class=\"a-fixed-right-grid\"><div class=\"a-fixed-right-grid-inner\" style=\"padding-right:220px\">\n <div class=\"a-fixed-right-grid-col a-col-left\" style=\"padding-right:10%;*width:89.6%;float:left;\">\n <div class=\"a-row a-spacing-mini a-spacing-top-mini\">\n <span class=\"a-size-medium\"><b>List subtotal<\/b>:<\/span>\n <span class=\"a-size-medium a-color-price a-text-bold\">{subtotal}<\/span>\n <span class=\"a-size-mini\">({numberOfItems})<\/span>\n <\/div>\n <\/div>\n \n <\/div><\/div>\n <\/div><\/div>\n\n<\/div><\/div>'; | |
} | |
function getNumberOfItems(count){ | |
return count == 1 ? '1 item' : count + ' items'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment