Last active
August 9, 2026 19:54
-
-
Save oprypin/23481436f696b874345706ecfa845b80 to your computer and use it in GitHub Desktop.
Export parts CSV from Lego Pick-a-Brick "Order details" page
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
| function initiateDownload(data, filename, type) { | |
| const blob = new Blob(data, {type: type}); | |
| const url = window.URL.createObjectURL(blob); | |
| const a = document.createElement('a') | |
| a.href = url; | |
| a.download = filename; | |
| a.style = 'display: "none"'; | |
| document.body.appendChild(a); | |
| a.click(); | |
| window.URL.revokeObjectURL(url); | |
| } | |
| csvRows = ['elementId,quantity\n']; | |
| for (const row of document.querySelectorAll('ul>li[class^="PabItem"]')) { | |
| const extractNumber = (selector) => /([0-9]+)\s*$/.exec(row.querySelector(selector).textContent)[1]; | |
| items = ['[class^="Sku-module"]', '[class^="Quantity-module"]'].map(extractNumber); | |
| csvRows.push(items.join(',') + '\n'); | |
| } | |
| initiateDownload(csvRows, 'parts.csv', 'text/csv;charset=utf-8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment