"Show all parts" bookmarklet

paul_mertonpaul_merton UKMember Posts: 2,952
edited August 2013 in Brickset.com
Just thought I'd share this, as others might find it useful. I find it a bit tricky to visualise in my mind how many useful parts there are in a set when I'm looking at a list of the unique parts and their respective quantities, so I made the following bookmarklet script which opens a new page and shows all of the individual parts in a set. For example, if there is a part with a quantity of 8, it'll show 8 of them.

1. Save the following URL as a bookmark

javascript:(function(){inventory%20=%20document.getElementsByClassName("inventory")[0].children;results%20=%20"";for%20(i=0;%20i<%20inventory.length;%20i++)%20{html%20=%20inventory[i].innerHTML;match%20=%20/<b>(\d+)<\/b>/.exec(html);if%20(match%20!=%20null)%20{count%20=%20match[1];for%20(n=0;%20n<count;%20n++)%20{results%20+=%20html.match(/<img.*?">/)[0];}}}nD%20=%20window.open().document;nD.writeln("<html><body><ul>"%20+%20results%20+%20"</ul></body></html>");nD.close();})();

2. Browse to the "Parts" tab of any set, then click the bookmark.

If you try this on the Z-95 polybag, for example, it will display all 54 parts in the set:

image
carlqMatthewJosephCupIsHalfEmptyCapnRex101

Comments

  • HuwHuw Brickset Towers, Hampshire, UKAdministrator Posts: 6,441
    Very cool. Now try it on Tower Bridge :-)
  • paul_mertonpaul_merton UKMember Posts: 2,952
    Cheeeeeeeeese!
  • graphitegraphite USMember Posts: 3,241
    I was thinking the same thing @Huw not only because it has over 4k parts but because there are so many of the same parts. Just parted out 2 of them and the fact that there are tons of the same part actually made it the easiest thing to sort since each bag typically only had 10 different parts and a lot of them.

    Is there a way for that bookmark to print the quantity or just show distinct parts?
  • paul_mertonpaul_merton UKMember Posts: 2,952
    ^ Isn't that what the normal Brickset parts list already does?
  • graphitegraphite USMember Posts: 3,241
    ^ yeah but I guess I meant in the just parts image layout like yours did. More compact without the text. Was just curious as it isn't something I'd probably use.
  • BumblepantsBumblepants DFWMember Posts: 5,829
    Cool app. I was afraid this might a thread about the Series 11 female robot.
  • plasmodiumplasmodium UKMember Posts: 1,936
    @paul_merton: I can't seem to get this to work. What browser did you use and how did you save the Javascript as a bookmark?
  • ljames28ljames28 Member Posts: 88
    I hope you don't mind, I thought that looked pretty awesome and added it on Brick Owl

    Z-95 http://brickowl.com/catalog/lego-z-95-headhunter-set-30240/inventory?display=visual

    Obligatory Tower Bridge http://brickowl.com/catalog/lego-tower-bridge-set-10214/inventory?display=visual
    CupIsHalfEmptykhmellymelpaul_merton
  • paul_mertonpaul_merton UKMember Posts: 2,952

    @paul_merton: I can't seem to get this to work. What browser did you use and how did you save the Javascript as a bookmark?

    Should work in most browsers, although I use Firefox most of the time.
    The easiest way to create a new bookmark in that is to right-click on the Bookmarks Toolbar and select New Bookmark.
  • plasmodiumplasmodium UKMember Posts: 1,936
    Ok. That is how I did it (with the Javascript as the "location"), but it didn't seem to do anything after I clicked on the new bookmark.
  • paul_mertonpaul_merton UKMember Posts: 2,952
    All I can suggest is, make sure you copied the entire line, and also make sure you're looking at the "Parts" tab when you click on it. Not sure why else it wouldn't work, unless you've disabled JavaScript or support for bookmarklets somehow.
  • plasmodiumplasmodium UKMember Posts: 1,936
    edited August 2013
    That's possible, I guess. I managed to use the parts function on brickowl (as mentioned above) to much the same effect. Thanks, though.
  • paul_mertonpaul_merton UKMember Posts: 2,952
    With some slight tweaks, here's a Harlem Shake version of the bookmarket:

    javascript:(function(){inventory%20=%20document.getElementsByClassName("inventory")[0].children;results%20=%20"";for%20(i=0;%20i%3C%20inventory.length;%20i++)%20{html%20=%20inventory[i].innerHTML;match%20=%20/%3Cb%3E(\d+)%3C\/b%3E/.exec(html);if%20(match%20!=%20null)%20{count%20=%20match[1];for%20(n=0;%20n%3Ccount;%20n++)%20{results%20+=%20html.match(/%3Cimg.*?"%3E/)[0];}}}nD%20=%20window.open().document;nD.writeln("%3Chtml%3E%3Cbody%3E%3Cul%3E"%20+%20results%20+%20"%3C/ul%3E%3Cscript%20src='htt"+"ps://gist.github.com/commadelimited/4958196/raw/42ef5c7df04a95bbf51a8f7b197d44ecf44ff846/harlem-shake.js'%3E%3C/script%3E%3C/body%3E%3C/html%3E");nD.close();})();

    For the best demonstration:

    1. Copy the above text and save it as a new bookmark.
    2. Go to http://www.brickset.com/detail/?Set=50011-1
    3. Click on the "Parts" tab to see the parts list
    4. Click on the bookmark

    Enjoy :D
    CupIsHalfEmpty
  • aimlesspursuitsaimlesspursuits USMember Posts: 207
    Thanks @paul_merton
    The second bookmarklet worked for me but not the original one. Nice script!
Sign In or Register to comment.
Recent discussions Categories Privacy Policy