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.

Revisions

  1. luk4s revised this gist Nov 8, 2020. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions download_order.js
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ class OrderItem {
    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);
    this._price = Number.parseFloat(element.querySelector(".productInfo > span:last-child").innerText.replace(",","."));
    }
    /** @return {String} */
    get name() {
    @@ -24,12 +24,16 @@ class OrderItem {
    get price() {
    return this._price;
    }
    /** @return {Number} */
    get unitPrice() {
    return this.price / this.quantity;
    }

    /**
    * @return {String}
    */
    toCsv() {
    const row = [this.csvValue(this.name), this.quantity, this.price];
    const row = [this.csvValue(this.name), this.quantity, this.unitPrice, this.price];
    return row.join(",");
    }

    @@ -48,7 +52,7 @@ orderRows.forEach((item, index) => {
    * @param {Array<OrderItem,CartItem>} items
    */
    function downloadCSV(items) {
    const csv = ["name,quantity,price"];
    const csv = ["Nazev,Mnozstvi,Jed.cena,Clk.cena"];
    items.forEach((item) => {
    csv.push(item.toCsv());
    })
  2. luk4s revised this gist Nov 8, 2020. 1 changed file with 18 additions and 5 deletions.
    23 changes: 18 additions & 5 deletions download_order.js
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,18 @@ class OrderItem {
    get price() {
    return this._price;
    }

    /**
    * @return {String}
    */
    toCsv() {
    const row = [this.csvValue(this.name), this.quantity, this.price];
    return row.join(",");
    }

    csvValue(text){
    return `"${text}"`
    }
    }

    const orderRows = document.querySelectorAll(".collapseItemContent span.collapseInside");
    @@ -32,17 +44,18 @@ orderRows.forEach((item, index) => {
    items.push(new OrderItem(item))
    })

    /** @param {Array<OrderItem,CartItem>} items*/
    /**
    * @param {Array<OrderItem,CartItem>} items
    */
    function downloadCSV(items) {
    const csv = ["name", "quantity", "price"];
    const csv = ["name,quantity,price"];
    items.forEach((item) => {
    const row = [item.name, item.quantity, item.price];
    csv.push(row.join(","));
    csv.push(item.toCsv());
    })

    const csvFile = new Blob([csv.join("\n")], {type:"text/csv"});
    const downloadLink = document.createElement("a");
    downloadLink.download = "kosik.cz-objednavka.csv";
    downloadLink.download = "rohlik.cz-objednavka.csv";
    downloadLink.href = window.URL.createObjectURL(csvFile);
    downloadLink.style.display = "none";
    document.body.appendChild(downloadLink);
  3. luk4s created this gist Nov 8, 2020.
    51 changes: 51 additions & 0 deletions download_order.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@

    /**
    * @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);