Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active August 9, 2026 19:54
Show Gist options
  • Select an option

  • Save oprypin/23481436f696b874345706ecfa845b80 to your computer and use it in GitHub Desktop.

Select an option

Save oprypin/23481436f696b874345706ecfa845b80 to your computer and use it in GitHub Desktop.
Export parts CSV from Lego Pick-a-Brick "Order details" page
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