/* Add custom Js styles below */ (function () { function tagPromotions() { document.querySelectorAll('.product-card__promotion, .promotion-title').forEach(function (el) { el.setAttribute( 'data-promotion', el.textContent.trim() === 'وصلت حديثاً' ? 'new-arrival' : 'other' ); }); } tagPromotions(); new MutationObserver(tagPromotions).observe(document.body, { childList: true, subtree: true, }); })(); (function () { const INSTALLMENTS = 4; const FREQUENTLY_BOUGHT_TITLE = { ar: 'قد يعجبك أيضاً', en: 'You may also like' }; function findInShadow(root, selector) { if (!root) return null; const light = root.querySelector(selector); if (light) return light; const sr = root.shadowRoot; if (sr) { const inShadow = sr.querySelector(selector); if (inShadow) return inShadow; const allEls = sr.querySelectorAll('*'); for (const el of allEls) { if (el.shadowRoot) { const deep = findInShadow(el, selector); if (deep) return deep; } } } return null; } const COMPANIES = [ { key: 'tamara', name: { ar: 'تمارا', en: 'Tamara' }, logo: 'https://nussuq-dev.com/sonbol/tamara.webp', findTarget: sallaEl => { const tamaraWidget = sallaEl.querySelector('tamara-widget'); if (!tamaraWidget) return null; const learnMore = findInShadow(tamaraWidget, '.tamara-inline-learn-more-link'); if (learnMore) return learnMore; return tamaraWidget; }, }, { key: 'tabby', name: { ar: 'تابي', en: 'Tabby' }, logo: 'https://nussuq-dev.com/sonbol/tabby.png', findTarget: sallaEl => { const newTarget = sallaEl.querySelector('[data-test="widget-learn-more"]'); if (newTarget) return newTarget; const wrap = sallaEl.querySelector('#tabbyPromo') || document.querySelector('#tabbyPromo'); if (!wrap) return null; const portal = wrap.querySelector('span.styles__containerPortal--c9f84'); if (!portal) return null; const lightTarget = portal.querySelector('[data-test="widget-learn-more"]'); if (lightTarget) return lightTarget; return portal.shadowRoot ? portal.shadowRoot.querySelector('[data-test="widget-learn-more"]') : null; }, }, ]; const TEXT = { ar: (n, amount) => `${n} دفعات بدون فوائد بقيمة ${amount} `, en: (n, amount) => `${n} interest-free payments of ${amount} SAR`, }; function getLang() { const lang = (document.documentElement.lang || '').toLowerCase(); return lang.startsWith('ar') || document.body.classList.contains('rtl') ? 'ar' : 'en'; } const fmt = n => Number.isInteger(n) ? String(n) : n.toFixed(2); function dispatchClick(el) { try { el.click(); } catch (e) {} try { el.dispatchEvent(new MouseEvent('click', { bubbles: false, cancelable: true, composed: false, view: window, })); } catch (e) {} } function buildWidget(price, lang, sallaEl) { const isRTL = lang === 'ar'; const per = fmt(Math.round((price / INSTALLMENTS) * 100) / 100); const wrap = document.createElement('div'); wrap.id = 'drs-inst-widget'; wrap.style.cssText = `direction:${isRTL?'rtl':'ltr'};margin:8px 0;`; wrap.innerHTML = `
`; wrap.querySelectorAll('.drs-logo-card').forEach(card => { card.addEventListener('click', e => { e.preventDefault(); e.stopPropagation(); const company = COMPANIES.find(c => c.key === card.dataset.provider); const target = company && company.findTarget(sallaEl); if (target) dispatchClick(target); }); }); return wrap; } function injectInstallment() { if (document.getElementById('drs-inst-widget')) return; const sallaEl = document.querySelector('salla-installment'); if (!sallaEl) return; let price = parseFloat(sallaEl.getAttribute('price') || '0'); if (!price) { const tamaraWidget = sallaEl.querySelector('tamara-widget'); price = parseFloat(tamaraWidget?.getAttribute('amount') || '0'); } if (!price) return; sallaEl.style.cssText = 'position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);opacity:0;'; sallaEl.parentNode.insertBefore(buildWidget(price, getLang(), sallaEl), sallaEl.nextSibling); } function patchFrequentlyBought() { const newTitle = FREQUENTLY_BOUGHT_TITLE[getLang()]; if (!newTitle) return; document.querySelectorAll('h2,h3,p,span').forEach(el => { if (!el.dataset.drsPatched && !el.children.length && el.textContent.trim() === 'عادة ما يتم شراؤه مع') { el.textContent = newTitle; el.dataset.drsPatched = '1'; } }); } function run() { injectInstallment(); patchFrequentlyBought(); } new MutationObserver(run).observe(document.body, { childList: true, subtree: true }); document.readyState === 'loading' ? document.addEventListener('DOMContentLoaded', run) : run(); setTimeout(run, 1000); setTimeout(run, 2500); })();