Skip to content

Instantly share code, notes, and snippets.

@luk4s
Last active November 8, 2020 11:27
Show Gist options
  • Select an option

  • Save luk4s/43282124c8666eed78b0084f861832b6 to your computer and use it in GitHub Desktop.

Select an option

Save luk4s/43282124c8666eed78b0084f861832b6 to your computer and use it in GitHub Desktop.
Rohlik.cz - stažení rozbalené objednávky
/**
* @class OrderItem
* Item in order detail in user profile
*
* @see https://www.rohlik.cz/uzivatel/profil
*/
class OrderItem {
/** @param {Element} element */
constructor(element) {
this._name = element.querySelector("a.productName span:first-child").innerText;
this._quantity = Number.parseFloat(element.querySelector("a.productName span.boldText").innerText);
this._price = Number.parseFloat(element.querySelector(".productInfo > span:last-child").innerText);
}
/** @return {String} */
get name() {
return this._name;
}
/** @return {Number} */
get quantity() {
return this._quantity;
}
/** @return {Number} */
get price() {
return this._price;
}
}
const orderRows = document.querySelectorAll(".collapseItemContent span.collapseInside");
const items = [];
orderRows.forEach((item, index) => {
items.push(new OrderItem(item))
})
/** @param {Array<OrderItem,CartItem>} items*/
function downloadCSV(items) {
const csv = ["name", "quantity", "price"];
items.forEach((item) => {
const row = [item.name, item.quantity, item.price];
csv.push(row.join(","));
})
const csvFile = new Blob([csv.join("\n")], {type:"text/csv"});
const downloadLink = document.createElement("a");
downloadLink.download = "kosik.cz-objednavka.csv";
downloadLink.href = window.URL.createObjectURL(csvFile);
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
downloadCSV(items);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment