/* Add custom Js styles below */ // ===== config ===== const GROUP_SELECTOR = '.s-product-options-option-container[data-option-id]'; const CHECKBOX_SELECTOR = 'input[type="checkbox"][name^="options["]'; const MAX_PER_GROUP = 2; // ----- inject style once ----- (function injectStyleOnce() { if (document.getElementById('nb-dim-style')) return; const st = document.createElement('style'); st.id = 'nb-dim-style'; st.textContent = ` .nb-dim { opacity: .45; pointer-events: none; cursor: not-allowed; } .nb-msg { margin-top: 6px; font-size: 13px; color: #e11d48; } `; document.head.appendChild(st); })(); function isMultiGroup(g) { return g && g.querySelectorAll(CHECKBOX_SELECTOR).length > 1; } function stripRequiredIn(g) { if (!g || !isMultiGroup(g)) return; g.querySelectorAll(CHECKBOX_SELECTOR).forEach(cb => cb.removeAttribute('required')); } function updateGroupState(g) { if (!g || !isMultiGroup(g)) return; const id = g.getAttribute('data-option-id') || ''; const boxes = Array.from(g.querySelectorAll(CHECKBOX_SELECTOR)); const checked = boxes.filter(c => c.checked); const count = checked.length; // avoid doing work/logging if nothing changed const last = g.dataset.nbLastCount; if (String(count) === last) return; g.dataset.nbLastCount = String(count); // ensure message element (created once) let msg = g.querySelector('.nb-msg'); if (!msg) { msg = document.createElement('div'); msg.className = 'nb-msg'; g.appendChild(msg); } if (count >= MAX_PER_GROUP) { boxes.forEach(cb => { const label = cb.closest('label'); if (!cb.checked) { cb.disabled = true; if (label) label.classList.add('nb-dim'); } else { cb.disabled = false; if (label) label.classList.remove('nb-dim'); } }); msg.textContent = `اخترت ${MAX_PER_GROUP} عناصر. لإضافة خيار آخر قم بإلغاء تحديد أحد الخيارات المختارة.`; } else { boxes.forEach(cb => { const label = cb.closest('label'); cb.disabled = false; if (label) label.classList.remove('nb-dim'); }); msg.textContent = ''; } // single, meaningful log (no spam) console.log(`[DIM] group ${id}: ${count}/${MAX_PER_GROUP}`); } function updateAll() { document.querySelectorAll(GROUP_SELECTOR).forEach(g => { stripRequiredIn(g); updateGroupState(g); }); } // real-time: on checkbox change in a group document.addEventListener('change', function (e) { const t = e.target; if (!(t instanceof HTMLInputElement) || t.type !== 'checkbox') return; const g = t.closest(GROUP_SELECTOR); if (!g) return; updateGroupState(g); }, true); // initial run if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', updateAll); } else { updateAll(); } // debounced observer (prevents feedback loops) const root = document.querySelector('.s-product-options-wrapper') || document.body; let moPending = false; new MutationObserver(() => { if (moPending) return; moPending = true; // run once on the next frame after all mutations settle requestAnimationFrame(() => { moPending = false; updateAll(); }); }).observe(root, { childList: true, subtree: true }); const themeToggleBtn = document.getElementById("theme-toggle"); if(themeToggleBtn){ themeToggleBtn.replaceWith(themeToggleBtn.cloneNode(true)); } let esm = "إقلاع"; let link = "https://iqla3.com/"; document.addEventListener("DOMContentLoaded", function () { document.querySelector("footer p.text-gray-400").innerHTML = ` صنع بإتقان على أيدي ${esm} `; });