_bs = {}; _bs.autoLink = function(html) { // replace any "(space)###(space)" with a link to the brickset db // number must be 4 to 6 chars to reduce chance of linking non lego ID numbers. e.g. dates return html.replace(/\s(\d{4,6})\s/g, function(text, id) { return '<a href="http://www.brickset.com/detail/?set=' + id + '-1">' + id + ' ' + (_bs[id] || '') + '</a>'; }); } _bs[8129] = 'AT-AT Walker (2010)'; _bs[10198] = 'Tantive IV (2009)';That example only has 2. But you get the idea. This is a static file that you generate once in a while and then add to this forums head via a simple include.
$('.Message').each(function() { $(this).html(_bs.autoLink($(this).html())); });
Please use our links: LEGO.com • Amazon
Recent discussions • Categories • Privacy Policy • Brickset.com
Brickset.com is a participant in the Amazon Services LLC Associates Program, the Amazon.com.ca, Inc. Associates Program and the Amazon EU Associates Programme, which are affiliate advertising programs designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.
As an Amazon Associate we earn from qualifying purchases.
Comments
Only limitation is it doesn't sem to work on the mobile version of the forum.
It also doesn't add the set name in like yours which would be useful.
It looks like I'm not that only one that is unaware since so many sets aren't linked. I still like the idea of putting the name in however. It saves a click.
I could certainly create a 'live' version from the database of the _bs array as a .JS file that could be referenced from here, that might be the easiest way.
I'll give it some thought when I've finished what I'm currently working on.
I'm doing a 1066 MOC, halfway there with the Normans, still loads of Saxons to go.
I wouldn't want people thinking I am doing a 1066-1: Little People with Accessories MOC. Although I guess in reality, with that set name I am doing that.
To use this, you just have to create a new bookmark which points to this address:
javascript:(function(){var%20setNumber=window.getSelection();if(setNumber==""){setNumber=prompt("No%20LEGO%20set%20number%20highlighted;%20please%20enter%20one%20manually.");}var%20regexp=/\b(\d{3,7})\b/;var%20result=regexp.exec(setNumber);if(!result){alert("Please%20highlight%20a%20LEGO%20set%20number%20or%20manually%20enter%20a%20valid%20number%20before%20clicking%20on%20the%20bookmarklet.");}else{setNumber=result[1];window.open("http://www.brickset.com/detail/?Set="+setNumber+"-1");}})()
If you name the bookmark something sensible like "Lookup on brickset.com" then you just have to select the set number and click on the bookmark. It doesn't matter if you accidentally select too much text, as it'll search through the whole selection for a valid-looking set number.
You could use something like GreaseMonkey to do this automatically for every page you visit, but I didn't consider that to be desirable! (It assumes that any 3-7 digit number corresponds to a Lego set, which is of course not true, and I can't be bothered to maintain a complete list of all set numbers in a bookmarklet :)
I find this bookmarklet quite useful, especially when hunting around eBay. Let me know if you like it, or if you think it could be improved.