Created
June 13, 2026 12:37
-
-
Save oprypin/bb9989e5b8ab26efd30dd291955a6a27 to your computer and use it in GitHub Desktop.
Rebrickable: Display total number of parts owned
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
| // ==UserScript== | |
| // @name Display total number of parts owned | |
| // @description Display total number of parts I already own when looking at inventory | |
| // @namespace https://github.com/oprypin/userscripts/ | |
| // @version 1 | |
| // @match https://rebrickable.com/* | |
| // @grant GM.registerMenuCommand | |
| // @grant GM.getValue | |
| // @grant GM.setValue | |
| // @author oprypin | |
| // ==/UserScript== | |
| GM.registerMenuCommand('Display total number of parts owned', (async function() { | |
| let listURL = await GM.getValue('listURL'); | |
| listURL = prompt('Which list to reference?\nCopy the entire URL such as:\nhttps://rebrickable.com/users/USERNAME/lists/123456/\nhttps://rebrickable.com/users/USERNAME/allparts/', listURL); | |
| await GM.setValue('listURL', listURL); | |
| const resp = await fetch(`${listURL.replace(/\/$/, '')}/parts/?format=rbpartscsv&inc_spares=0&_=${+new Date()}`); | |
| const text = (await resp.text()).replaceAll('\r\n', '\n'); | |
| const owned = new Map(); | |
| for (const [, partNum, colorId, quantity] of text.matchAll(/^(\w+),([0-9]+),([0-9]+)\b/gm)) { | |
| owned.set(partNum, (+quantity) + (owned.get(partNum) || 0)); | |
| owned.set(`${partNum}/${colorId}`, (+quantity)); | |
| } | |
| for (const partEl of document.querySelectorAll('.js-part-data')) { | |
| const [, partNum] = new RegExp('/parts/(\\w+)/').exec(partEl.getAttribute('data-url')); | |
| const colorId = partEl.getAttribute('data-color_id'); | |
| const ownedColorQuantity = owned.get(`${partNum}/${colorId}`); | |
| const ownedQuantity = owned.get(partNum); | |
| const div = document.createElement('div'); | |
| div.innerText = (ownedQuantity > 0 ? ownedColorQuantity > 0 ? `${ownedColorQuantity} / ${ownedQuantity}` : `- / ${ownedQuantity}` : '-'); | |
| div.style.color = 'var(--text-color)'; | |
| partEl.querySelector('.part-text').append(div); | |
| partEl.querySelector('.js-part-price')?.remove(); | |
| } | |
| })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment