Last active
November 8, 2020 11:27
-
-
Save luk4s/43282124c8666eed78b0084f861832b6 to your computer and use it in GitHub Desktop.
Revisions
-
luk4s revised this gist
Nov 8, 2020 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal 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.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.unitPrice, this.price]; return row.join(","); } @@ -48,7 +52,7 @@ orderRows.forEach((item, index) => { * @param {Array<OrderItem,CartItem>} items */ function downloadCSV(items) { const csv = ["Nazev,Mnozstvi,Jed.cena,Clk.cena"]; items.forEach((item) => { csv.push(item.toCsv()); }) -
luk4s revised this gist
Nov 8, 2020 . 1 changed file with 18 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal 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 */ function downloadCSV(items) { const csv = ["name,quantity,price"]; items.forEach((item) => { csv.push(item.toCsv()); }) const csvFile = new Blob([csv.join("\n")], {type:"text/csv"}); const downloadLink = document.createElement("a"); downloadLink.download = "rohlik.cz-objednavka.csv"; downloadLink.href = window.URL.createObjectURL(csvFile); downloadLink.style.display = "none"; document.body.appendChild(downloadLink); -
luk4s created this gist
Nov 8, 2020 .There are no files selected for viewing
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 charactersOriginal 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);