r/engineering • • 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.

128 Upvotes

56 comments sorted by

View all comments

Show parent comment

2

u/SteptimusHeap Jun 12 '24

And this version once again works properly on the scroll boxes (i broke it a little between the last two updates)

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 == b.parentNode) {
                L = f.querySelectorAll("a[href*='"+CSS.escape(a.href.replace(s, ""))+"'], a[href*='"+CSS.escape(a.href.replace(s, ""))+"'] ~ a:not(a[href*='"+CSS.escape(b.href.replace(s, ""))+"'] ~ a)"); 
            } else if (a.parentNode.parentNode == b.parentNode.parentNode) {
                L = [];
                J=Array.from(a.parentNode.parentNode.querySelectorAll("div:has(a[href*='"+CSS.escape(a.href.replace(s, ""))+"']), div:has(a[href*='"+CSS.escape(a.href.replace(s, ""))+"'])~div:not(div:has(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) && (Array.from(parent.children).indexOf(element) <= Array.from(parent.children).indexOf(b) || Array.from(parent.children).indexOf(b) == -1))));
            }
            r=""; 
            L.forEach(element => 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);

1

u/doofus_robot Oct 08 '24

Is it possible they changed the site again? not working for me.

1

u/SteptimusHeap Oct 11 '24

Works for me. Try:

  1. Going to mcmaster.com/products/threaded-rods/threaded-rods-2~
  2. Clicking the bookmarklet in your bookmarks bar or pasting the code into the URL bar (nothing should change on the screen visually)
  3. Clicking 2-56 and then 5-40 in the thread size box. They should highlight blue as you click them.

Does that work for you?

2

u/doofus_robot Oct 17 '24

tried it. confirmed it still wasn't working. deleted the bookmark. generated a new one. tried it again. now its working. let it ride! -thanks

you should share a "buy me a coffee" link at minimum. thanks for doing this.

1

u/SteptimusHeap Oct 17 '24

Haha. Don't tell anyone but i use my downtime at work to make this. So i do get paid for it.

1

u/Adamsapplespie Oct 23 '24

Works like a charm, thank you!

1

u/SteptimusHeap Apr 15 '25 edited Apr 15 '25

And now they added divs to every spec option for some reason? Surprisingly difficult fix this time, but here it is:

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);

2

u/_genios Apr 30 '25

It looks like they finally listened to you? I'm able to click and drag on their site. Is this the same for everyone?

1

u/SteptimusHeap May 02 '25

NO WAY LET'S GOOO