Last active
December 25, 2018 20:20
-
-
Save gerryster/74db6714f62683599b31efa9e66dff72 to your computer and use it in GitHub Desktop.
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
/* | |
* Creates a CSV "shopping list" from the Item List view in the Ikea Kitchen Planner. Unfortunately, | |
* Ikea does not provide an easy way to convert kitchen plans to your shopping cart. This is | |
* probably by design as they want you to come to the store and review your design with thier | |
* kitchen experts. This is good advice for most people as they will help you spot mistakes. This | |
* tool is intended for those experienced with Ikea kitchens. | |
* | |
* How To Use in Google Chrome: | |
* 1) Open your Ikea kitchen design. | |
* 2) Click on the "Item list/Total Price" button at the top. | |
* 3) Open up the document inspector. | |
* 4) Copy and paste the code into the JavaScript console. | |
* 5) A block of CSV text should now be in your operating system's clipboard. Paste this into a file | |
* and open it up in your favorite spreadsheet. | |
* | |
* Copyright Ryan Gerry (https://github.com/gerryster), 2018 | |
*/ | |
var all_items = Array.from(document.querySelectorAll('.table_item_sku')).map(function(skuEl) { | |
parent = skuEl.parentElement; | |
return { | |
sku: skuEl.textContent, | |
quantity: parseInt(parent.querySelector('.table_item_quantity').textContent), | |
name: parent.querySelector('.table_item_longname').textContent, | |
price: parent.querySelector('.table_item_unitprice').textContent, | |
}; | |
}); | |
var by_sku = all_items.reduce(function(items, new_item) { | |
if(items[new_item.sku]) { | |
items[new_item.sku].quantity += new_item.quantity; | |
} | |
else { | |
items[new_item.sku] = { | |
sku: new_item.sku, | |
quantity: new_item.quantity, | |
name: new_item.name, | |
price: new_item.price, | |
}; | |
} | |
return items; | |
}, {}); | |
ordered_skus = Object.keys(by_sku).sort(); | |
var PRODUCT_URL = 'https://www.ikea.com/us/en/catalog/products/'; | |
var HEADER = "SKU, URL, Description, Quantity, Price\n"; | |
var csv_output = HEADER; | |
csv_output += ordered_skus.map(sku => { | |
item = by_sku[sku]; | |
return [ | |
item.sku, | |
PRODUCT_URL + item.sku, | |
'"' + item.name.replace('"', '""') + '"', // CSV escape double quotes | |
item.quantity, | |
item.price, | |
].join(", "); | |
}).join("\n"); | |
console.log(csv_output); | |
copy(csv_output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment