Created
July 14, 2015 16:46
-
-
Save sehrgut/983fc57973ff087517db to your computer and use it in GitHub Desktop.
reads ebay purchase history from purchase history page
This file contains hidden or 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
function getEbayHistory() { | |
var jq = jQuery([1]); | |
function parseItem(el) { | |
jq[0] = el; | |
var $title = jq.find('a.item-title'); | |
return { | |
title: $title.text(), | |
url: $title.attr('href') | |
}; | |
} | |
function parseCost(el) { | |
jq[0] = el; | |
var $info = jq.find('.purchase-info'); | |
var price = $info.find('.cost-label').text(); | |
var shipping = $info.find('.ship-label :first-child').text(); | |
return { | |
price_raw: price, | |
shipping_raw: shipping | |
}; | |
} | |
function moneyStringToUSD(str) { | |
// todo: currency conversion like my kickstarter userscript | |
if (str.match(/^US \$/)) { | |
return Number(str.replace(/^US \$/, '')); | |
} | |
throw "Unknown currency for money '" + str + "'" | |
} | |
function shippingToMoneyString(str) { | |
return str.replace(/^\+ /, ''); | |
} | |
function shippingToUSD(str) { | |
if (str == "Free shipping") return 0.0; | |
return moneyStringToUSD(shippingToMoneyString(str)); | |
} | |
function mapHistoryItems () { | |
var item = parseItem(this); | |
var cost = parseCost(this); | |
return { | |
title: item.title, | |
url: item.url, | |
price_raw: cost.price_raw, | |
shipping_raw: cost.shipping_raw, | |
price: moneyStringToUSD(cost.price_raw), | |
shipping: shippingToUSD(cost.shipping_raw) | |
}; | |
} | |
return $('.order-r').map(mapHistoryItems).toArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment