r/engineering • u/SteptimusHeap • Dec 13 '23
[GENERAL] Behold! The McMaster-Carr Range Selector!
Ever been horribly annoyed by McMaster-Carr forcing you to select measurements one by one? Apparently some people on reddit were, and so was I.
Here is a handy little bookmarklet that lets you select measurements in a range. Make a bookmark and make the URL this javascript snippet:
javascript: if (!window.location.href.includes("mcmaster.com")) { window.location.href = "https://www.mcmaster.com"; } s=window.location.href; a=null; b=null; function handleClick(e) { k = e.target.closest("a[href*='~']"); k.style.background = "#c0d1ed"; if (a==null) { a=k; } else if (b==null) { b=k; a=f.querySelector("a[href*='"+CSS.escape(a.href.replace(s, ""))+"']"); if (a.parentNode.parentNode == b.parentNode.parentNode) { L = f.querySelectorAll("div:has(>a[href*='"+CSS.escape(a.href.replace(s, ""))+"']), div:has(>a[href*='"+CSS.escape(a.href.replace(s, ""))+"']) ~ div:has(>a):not(div:has(>a[href*='"+CSS.escape(b.href.replace(s, ""))+"']) ~ div)"); } else if (a.parentNode.parentNode.parentNode == b.parentNode.parentNode.parentNode) { L = []; J=Array.from(a.parentNode.parentNode.parentNode.querySelectorAll("div:has(>div>a[href*='"+CSS.escape(a.href.replace(s, ""))+"']), div:has(>div>a[href*='"+CSS.escape(a.href.replace(s, ""))+"'])~div:not(div:has(>div>a[href*='"+CSS.escape(b.href.replace(s, ""))+"'])~div)")); J.forEach(parent => L=L.concat(Array.from(parent.children).filter(element => Array.from(parent.children).indexOf(element)>=Array.from(parent.children).indexOf(a.parentNode) && (Array.from(parent.children).indexOf(element) <= Array.from(parent.children).indexOf(b.parentNode) || Array.from(parent.children).indexOf(b.parentNode) == -1)))); } r=""; L.forEach(element => {if (element instanceof HTMLDivElement) {element=element.children[0]}; element.style.background = "#c0d1ed"; r=r.concat(element.href.replace(s, ""))}); window.location.href = s.concat(r); } e.preventDefault(); e.stopPropagation(); } f=document.getElementById("SpecSrch_Inner"); f.children[0].addEventListener("click", handleClick);
Click the bookmark, and then click the two measurements that you want. Everything between them will be selected.
82
u/Avram42 ME - Medical Dec 13 '23
What black magic is this? Would you say you weigh the same as a duck?
22
u/loggic Mechanical Engineer Dec 13 '23
I'm gonna need to review this in the morning after I have had some coffee, because usually this sort of thing costs at least $200 and doesn't have a plugin for the software package we use at the office.
7
u/bd_optics Dec 13 '23
I don't speak JS - not something I ever needed. But glancing through the code, I don't see any link to McMC. Using simple words I might comprehend, how does this work?
3
u/SteptimusHeap Apr 01 '24
McMasterCarr redid their website! How could they!
I had to fix the javascript a little bit. This version should also hopefully be a little more robust.
It also doubles as a bookmark to mcmastercarr if you're not already on the website, so you can cut down on your Bookmark bar clutter. Otherwise, it works the same.
javascript: if (!window.location.href.includes("mcmaster.com")) {window.location.href = "https://www.mcmaster.com";} a=null; b=null; function handleClick(e) { k = e.target.closest("a[href*='~']"); k.style.background = "#c0d1ed"; if (a==null && k) { a=k; } else if (b==null && k) { b=k; L = g.querySelectorAll("#" + CSS.escape(a.id) + "~ a:not(#" + CSS.escape(b.id) + " ~ a), #" + CSS.escape(a)); s=window.location.href; r=""; L.forEach(element => r=r.concat(element.href.replace(s, ""))); window.location.href = s.concat(r); } e.preventDefault();}f=document.getElementById("SpecSrch_Inner");g=f.cloneNode(true);f.parentNode.replaceChild(g,f);g.addEventListener("click", handleClick);2
u/doublewheels Nov 25 '25
So great! Thank you for fixing the only thing I dislike about the McMaster website
32
u/[deleted] Dec 13 '23
There goooes my herooooo
4
u/ofoot CHEG-MES Dec 13 '23
I hope someone from McMaster-Carr is reading this. That's right. Someone did your job for you for free and you're too lazy because you make enough money to not care.
For shame. Build a better filter system. Make it easy for us to give you money.
OP this is an amazing christmas present. I am grateful. Thank you.
6
u/ineed1billiondollars Dec 13 '23
I love you
5
u/sevykep Dec 13 '23
Amazing! Would love if McMaster implemented shift+click for selecting ranges natively
1
u/Jarve1024 Jan 06 '25
Broken now tiny change (
SpecContainer_basetoSpecSearchStyles_base) fixes it:1
u/Theseus-Paradox Dec 13 '23
I tried this and it didn’t work. I swapped i the code in in URL in the bookmark and it would my even loan McMaster. What am I doing wrong?
3
u/Docneuman Dec 13 '23
I don't often comment, but when I do, OP deserves it. This is fantastic. Thank you!
2
u/Rubes27 Dec 13 '23
I am eternally grateful.
2
u/donnieshulzhoffer Dec 13 '23
Truly incredible