Skip to content

Instantly share code, notes, and snippets.

@shanemhansen
Last active September 23, 2018 05:38
Show Gist options
  • Save shanemhansen/4af0d049d76b3c6a5cdae65169be43d4 to your computer and use it in GitHub Desktop.
Save shanemhansen/4af0d049d76b3c6a5cdae65169be43d4 to your computer and use it in GitHub Desktop.

Bookmarklet to copy amazon cart to csv

This is a simple bookmarklet to copy your amazon cart to csv. Directions:

  1. Go to your bookmarks folder and add a bookmark called "copy cart". Set the url to the contents of CopyAmazonCart.js.
  2. Open up your cart page in amazon. ( https://www.amazon.com/gp/cart/view.html?ref=nav_cart )
  3. Click on your bookmark.
  4. That's it! Your cart is now in your clipboard in csv.
  5. Paste/import into your favorite spreadsheet program using comma as a delimiter.
javascript:!function(){var e,t,n;try{var o=document.querySelectorAll("div[data-name='Active Items'] div[data-asin]"),r=[["ProductID","Price","Quantity","Description","Link"].join(",")];o.forEach(function(e){var t=e.getAttribute("data-price"),n=e.getAttribute("data-quantity"),o=e.getAttribute("data-asin"),c=e.querySelector(".sc-product-link").href,a='"'+e.querySelector(".sc-product-title").textContent.replace(/"/g,'""').trim()+'"';r.push([o,t,n,a,c].join(","))}),e=r.join("\n"),t=document.createElement("textarea"),n=document.getSelection(),t.textContent=e,document.body.appendChild(t),n.removeAllRanges(),t.select(),document.execCommand("copy"),n.removeAllRanges(),document.body.removeChild(t)}catch(e){return void alert("Copy failed: "+e)}alert("Copy Successful, csv in in your clipboard")}();
ProductID Price Quantity Description Link
B01E3V66QS 299.00 1 AIMS 2000 Watt Pure Sine Power Inverter 12 VDC to 120 VAC USB Port ETL Listed to UL458 2 Year Warranty https://www.amazon.com/gp/product/B01E3V66QS/ref=ox_sc_act_title_1?smid=ATVPDKIKX0DER&psc=1
B01K1E86VO 11.90 1 Ruth&Boaz Inka Pattern Square Decor Pillow Case Cushion Cover (16"x16", B) https://www.amazon.com/gp/product/B01K1E86VO/ref=ox_sc_act_title_2?smid=A1MQ37XXQ9EU7N&psc=1
B01K1E86UA 13.90 1 Ruth&Boaz Inka Pattern Square Decor Pillow Case Cushion Cover (16"X16") (A) https://www.amazon.com/gp/product/B01K1E86UA/ref=ox_sc_act_title_3?smid=A1MQ37XXQ9EU7N&psc=1
B07C8D3CN7 41.90 1 Ruth&Boaz Outdoor Wool Blend Blanket Ethnic Inka Pattern(P) (A, LARGE) https://www.amazon.com/gp/product/B07C8D3CN7/ref=ox_sc_act_title_4?smid=A1MQ37XXQ9EU7N&psc=1
B004CR4OP4 14.44 1 LDR 516 B1210 Braided Nylon Tubing, 1/2-Inch ID x 10-Foot, Clear https://www.amazon.com/gp/product/B004CR4OP4/ref=ox_sc_act_title_18?smid=ATVPDKIKX0DER&psc=1
B002XM5G70 72.00 1 SHURFLO 4008-101-E65 3.0 Revolution Water Pump https://www.amazon.com/gp/product/B002XM5G70/ref=ox_sc_act_title_20?smid=A21JB2LOTROWHL&psc=1
(function() {
var copy = (function (text) {
var node = document.createElement('textarea')
var selection = document.getSelection()
node.textContent = text
document.body.appendChild(node)
selection.removeAllRanges()
node.select()
document.execCommand('copy')
selection.removeAllRanges()
document.body.removeChild(node)
});
try {
var data = document.querySelectorAll("div[data-name='Active Items'] div[data-asin]");
var buf = [
["ProductID",
"Price",
"Quantity",
"Description",
"Link"].join(",")
]
data.forEach(function(node) {
var price = node.getAttribute("data-price");
var quantity = node.getAttribute("data-quantity");
var productID = node.getAttribute("data-asin");
var link = node.querySelector(".sc-product-link");
var url = link.href;
var title = '"'+node.querySelector(".sc-product-title").textContent.replace(/"/g, '""').trim() + '"';
buf.push([productID, price, quantity, title, url].join(","))
});
copy(buf.join("\n"));
} catch(err) {
alert("Copy failed: "+err);
return;
}
alert("Copy Successful, csv in in your clipboard");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment