function isVisible(el) { if (!el || !el.getBoundingClientRect) return false; const rect = el.getBoundingClientRect(); const style = window.getComputedStyle(el); return rect.width > 0 && rect.height > 0 && style.display !== 'none' && style.visibility !== 'hidden'; } function walkRoots(root, rows, seen) { if (!root || seen.has(root)) return; seen.add(root); const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT); let node = walker.currentNode; while (node) { if (node.nodeType === Node.ELEMENT_NODE && node.tagName) rows.push(node); if (node.shadowRoot) walkRoots(node.shadowRoot, rows, seen); node = walker.nextNode(); } } function allElements() { const rows = []; walkRoots(document, rows, new Set()); return rows; } function insideInventoryRow(el) { return Boolean(el && el.closest && el.closest('div[data-sku]')); } function clickTargetFor(checkbox) { if (!checkbox) return null; if (checkbox.shadowRoot) { const shadowTarget = checkbox.shadowRoot.querySelector('[role="checkbox"], .checkbox'); if (shadowTarget) return shadowTarget; } return checkbox; } const rowCount = document.querySelectorAll('div[data-sku]').length; if (rowCount <= 0) { return { ok: false, reason: 'no inventory rows after status filter', rowCount }; } const checkboxes = allElements() .filter((el) => (el.tagName || '').toLowerCase() === 'kat-checkbox' && isVisible(el)) .sort((a, b) => { const rectA = a.getBoundingClientRect(); const rectB = b.getBoundingClientRect(); return rectA.top - rectB.top || rectA.left - rectB.left; }); const headerCheckbox = checkboxes.find((el) => !insideInventoryRow(el)) || checkboxes[0]; if (!headerCheckbox) { return { ok: false, reason: 'select-all checkbox not found', rowCount, checkboxCount: checkboxes.length }; } const target = clickTargetFor(headerCheckbox); target.scrollIntoView({ block: 'center', inline: 'nearest' }); target.click(); return { ok: true, rowCount, checkboxCount: checkboxes.length, clicked: { tag: headerCheckbox.tagName, insideInventoryRow: insideInventoryRow(headerCheckbox), outerHTML: (headerCheckbox.outerHTML || '').slice(0, 1000), }, };