/* MAPS - "My contract supplies" button (11/19/2026). Shows only to signed-in contract customers: it appears on product list pages that EvolutionX renders with the "Display contract items only" switch (guests never get it). Click = turn the switch on (contract items only, with Search Within and filters still working). Click again = show all supplies. 11/20/2026: 'View my full contract list' link removed (Darrell: same as the button). */ (function () { if (window.__mxContractBtn) return; window.__mxContractBtn = 1; var BLUE = '#003E7E', LIGHT = '#1AB7EA'; function findSwitch() { var all = document.querySelectorAll('label, span, div, p, h4, h5, strong'); for (var i = 0; i < all.length; i++) { var el = all[i]; if (el.children.length > 2) continue; if (!/display\s+contract\s+items\s+only/i.test(el.textContent || '')) continue; var box = el; for (var k = 0; k < 4 && box; k++) { var cb = box.querySelector && box.querySelector('input[type=checkbox]'); if (cb) return cb; box = box.parentElement; } } return null; } function anchorPoint() { var cands = document.querySelectorAll('div, span, p, h5, h6'); for (var i = 0; i < cands.length; i++) { var t = (cands[i].textContent || '').trim(); if (cands[i].children.length <= 1 && /^\d[\d,]*\s+items? found$/i.test(t)) return cands[i]; } return null; } function build() { if (document.getElementById('mx-contract-bar')) return true; var sw = findSwitch(); if (!sw) return false; var at = anchorPoint(); if (!at) return false; var on = !!sw.checked; var bar = document.createElement('div'); bar.id = 'mx-contract-bar'; bar.style.cssText = 'display:flex;flex-wrap:wrap;align-items:center;gap:10px;margin:0 0 14px;padding:12px 14px;border-radius:8px;background:#EAF6FD;border:1px solid #BCE2F8;font-size:15px;color:' + BLUE; var btn = document.createElement('button'); btn.type = 'button'; btn.style.cssText = 'background:' + (on ? '#fff' : BLUE) + ';color:' + (on ? BLUE : '#fff') + ';border:2px solid ' + BLUE + ';border-radius:22px;padding:8px 18px;font-weight:700;cursor:pointer;font-size:15px'; btn.textContent = on ? 'Show all supplies' : 'Show only my contract supplies'; btn.addEventListener('click', function () { var s = findSwitch(); if (s) { s.click(); } setTimeout(function () { var b = document.getElementById('mx-contract-bar'); if (b) b.remove(); tries = 0; tick(); }, 900); }); var txt = document.createElement('span'); txt.textContent = on ? 'Showing your contract supplies. Use Search Within to find a cartridge fast.' : 'Your account has contract supplies. Show just those, then search within them.'; bar.appendChild(btn); bar.appendChild(txt); var host = at.closest('.row') || at.parentElement; host.parentElement.insertBefore(bar, host); return true; } var tries = 0, watching = false, pending = false; function watch() { if (watching) return; watching = true; // keep the bar in place when the product list re-renders after filtering new MutationObserver(function () { if (pending || document.getElementById('mx-contract-bar')) return; pending = true; setTimeout(function () { pending = false; tries = 30; tick(); }, 300); }).observe(document.body, { childList: true, subtree: true }); } function tick() { if (build()) { watch(); return; } if (++tries < 40) setTimeout(tick, 500); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', tick); else tick(); })();