/* Add custom JS code below */ document.addEventListener('DOMContentLoaded', function () { // واتساب document.querySelectorAll('a[href*="api.whatsapp.com/send"]').forEach(function(el) { el.href = 'https://api.whatsapp.com/send?phone=966539985651&text=السلام عليكم، أود الاستفسار عن أحد المنتجات'; el.target = '_blank'; }); }); window.addEventListener('load', function () { const waitForFilter = setInterval(() => { const select = document.querySelector('#product-filter'); if (!select || document.querySelector('.custom-sort')) return; clearInterval(waitForFilter); // إخفاء فلتر سلة الأصلي select.style.display = 'none'; // ترتيب حسب const wrapper = document.createElement('div'); wrapper.className = 'custom-sort'; wrapper.innerHTML = `
ترتيب حسب
مقترحاتنا
الأكثر مبيعاً
الأعلى تقييماً
السعر: الأعلى للأقل
السعر: الأقل للأعلى
`; // التحقق من صفحة الورد الطبيعي const isNaturalFlowers = window.location.href.includes('/%D9%88%D8%B1%D8%AF-%D8%B7%D8%A8%D9%8A%D8%B9%D9%8A/'); // تصنيف حسب const categoryBtn = document.createElement('div'); categoryBtn.className = 'custom-category'; categoryBtn.innerHTML = `
تصنيف حسب
${isNaturalFlowers ? ` بوكيه ورد فازه ورد ` : ''}
الأسعار
عرض الكل
أقل من 100 ريال
100 - 200 ريال
200 - 300 ريال
أعلى من 300 ريال
`; select.parentNode.insertBefore(categoryBtn, select); select.parentNode.insertBefore(wrapper, select); categoryBtn.querySelector('.custom-sort-btn').onclick = function () { categoryBtn.querySelector('.custom-sort-list').classList.toggle('show'); }; // فلترة الأسعار + عرض الكل setTimeout(() => { // عرض الكل document.querySelectorAll('.price-filter-reset').forEach(btn => { btn.addEventListener('click', function(){ document.querySelectorAll('custom-salla-product-card').forEach(card => { card.style.display = ''; }); categoryBtn.querySelector('.custom-sort-btn').innerHTML = this.textContent.trim(); categoryBtn.querySelector('.custom-sort-list') .classList.remove('show'); }); }); // فلترة الأسعار document.querySelectorAll('.price-filter').forEach(btn => { btn.addEventListener('click', function(){ const min = Number(this.dataset.min); const max = Number(this.dataset.max); categoryBtn.querySelector('.custom-sort-btn').innerHTML = this.textContent.trim(); document.querySelectorAll('.s-product-card-price').forEach(priceEl => { const price = parseFloat( priceEl.textContent.replace(/[^\d.]/g,'') ) || 0; const card = priceEl.closest('custom-salla-product-card'); if(!card) return; if(price >= min && price < max){ card.style.display = ''; } else { card.style.display = 'none'; } }); categoryBtn.querySelector('.custom-sort-list') .classList.remove('show'); }); }); }, 1500); // CSS const style = document.createElement('style'); style.innerHTML = ` .custom-sort, .custom-category{ position:relative; display:inline-block; width:145px; margin-left:10px; vertical-align:top; } .custom-sort-btn{ background:#F8EEE8; color:#C37A6B; border:1px solid #D9B3AA; border-radius:12px; height:42px; display:flex; align-items:center; justify-content:center; font-size:14px; font-weight:700; cursor:pointer; box-shadow:0 2px 8px rgba(195,122,107,.08); } .custom-sort-list{ display:none; position:absolute; top:48px; right:0; width:220px; background:#D9A79D; border:1px solid #C37A6B; border-radius:14px; overflow:hidden; box-shadow:0 8px 25px rgba(195,122,107,.15); z-index:99999; } .custom-sort-list.show{ display:block; } .custom-sort-list div, .price-filter, .price-filter-reset{ padding:14px; cursor:pointer; text-align:center; color:#FFFFFF; font-weight:600; border-bottom:1px solid rgba(255,255,255,.25); } .custom-sort-list div:hover, .price-filter:hover, .price-filter-reset:hover{ background:#C37A6B; color:#FFFFFF; } .custom-category-link{ display:block; padding:14px; text-align:center; color:#FFFFFF; text-decoration:none; transition:.2s; border-bottom:1px solid rgba(255,255,255,.25); } .custom-category-link:hover{ background:#C37A6B; color:#FFFFFF; } .price-title{ padding:14px; text-align:center; background:#C37A6B !important; color:#FFFFFF !important; font-weight:700; cursor:default; pointer-events:none; border-bottom:1px solid rgba(255,255,255,.25); } .custom-sort-list .price-title{ background:#C37A6B !important; } `; document.head.appendChild(style); wrapper.querySelector('.custom-sort-btn').onclick = function () { wrapper.querySelector('.custom-sort-list').classList.toggle('show'); }; wrapper.querySelectorAll('.custom-sort-list div').forEach(item => { item.onclick = function () { select.value = this.dataset.value; select.dispatchEvent( new Event('change', { bubbles: true }) ); wrapper.querySelector('.custom-sort-btn').textContent = this.textContent.trim(); wrapper.querySelector('.custom-sort-list') .classList.remove('show'); }; }); }, 1000); }); /* ============================ POPUP GIFT CARDS - PETALYA نافذة كروت الإهداء المنبثقة يمكن حذف الكود بالكامل إذا لم تعد مطلوبة ============================ */ /* ============================ POPUP GIFT CARDS - PETALYA نافذة كروت الإهداء المنبثقة يمكن حذف الكود بالكامل إذا لم تعد مطلوبة ============================ */ /* ===== POPUP GIFT CARDS - PETALYA ===== */ document.addEventListener('click', function(e){ const btn = e.target.closest('button'); if(!btn) return; const currentUrl = decodeURIComponent(window.location.href); if( currentUrl.includes('c1393700411') || currentUrl.includes('كرت-اهداء-') ){ return; } const text = btn.innerText || ''; if( !text.includes('إضافة للسلة') && !text.includes('اضافة للسلة') ){ return; } setTimeout(() => { if(document.getElementById('gift-popup')) return; document.body.insertAdjacentHTML('beforeend', `
×

💌 أضيف كرت إهداء؟

اجعل هديتك أكثر تميزاً مع كرت إهداء أنيق

`); document.querySelector('.gift-close').onclick = () => { document.getElementById('gift-popup').remove(); }; document.querySelector('.skip-btn').onclick = () => { document.getElementById('gift-popup').remove(); }; },1000); }); /*تغيير كلمه ملاحظه للكروت */ setInterval(() => { const currentUrl = decodeURIComponent(location.href); if (!currentUrl.includes('كرت-اهداء')) return; document.querySelectorAll('button').forEach(btn => { if ( btn.textContent.includes('إضافة ملاحظة') || btn.textContent.includes('اضافة ملاحظة') ) { btn.innerHTML = btn.innerHTML.replace( 'إضافة ملاحظة', 'اكتب رسالتك داخل الكرت' ); btn.innerHTML = btn.innerHTML.replace( 'اضافة ملاحظة', 'اكتب رسالتك داخل الكرت' ); } }); }, 500); document.addEventListener('DOMContentLoaded', () => { const currentUrl = decodeURIComponent(location.href); if (!currentUrl.includes('كرت-اهداء')) return; setInterval(() => { document.querySelectorAll('textarea').forEach(el => { el.placeholder = 'اكتب عبارتك الخاصة 💌'; }); }, 500); }); /* نافذة كروت الإهداء للجوال فقط بعد إضافة منتج */ if (window.innerWidth <= 768) { let lastCartCount = 0; setInterval(() => { const cartCountEl = document.querySelector('.s-cart-summary-count'); if (!cartCountEl) return; const currentCount = parseInt(cartCountEl.textContent.trim()) || 0; const currentUrl = decodeURIComponent(window.location.href); if( currentUrl.includes('c1393700411') || currentUrl.includes('كرت-اهداء-') ){ lastCartCount = currentCount; return; } /* أول تشغيل */ if (lastCartCount === 0) { lastCartCount = currentCount; return; } /* يظهر فقط عند زيادة العدد */ if ( currentCount > lastCartCount && !document.getElementById('gift-popup') ) { document.body.insertAdjacentHTML('beforeend', `
×

💌 أضيف كرت إهداء؟

اجعل هديتك أكثر تميزاً مع كرت إهداء أنيق

`); document.querySelector('.gift-close').onclick = () => { document.getElementById('gift-popup')?.remove(); }; document.querySelector('.skip-btn').onclick = () => { document.getElementById('gift-popup')?.remove(); }; } /* تحديث العدد دائماً */ lastCartCount = currentCount; }, 500); } /* بوكس الإهداء + ترتيب الحقول */ setInterval(() => { const booking = document.querySelector('[data-option-id="1505507254"]'); const gift = document.querySelector('[data-option-id="851405446"]'); const nameField = document.querySelector('[data-option-id="1300255374"]'); const phoneField = document.querySelector('[data-option-id="1766559880"]'); if (!booking || !gift || !nameField || !phoneField) return; /* ترتيب الأقسام */ const parent = booking.parentNode; if (parent.firstElementChild !== booking) { parent.prepend(booking); } if (booking.nextElementSibling !== gift) { booking.after(gift); } /* نقل الاسم والرقم أسفل الهدية */ if (!gift.dataset.ready) { gift.appendChild(nameField); gift.appendChild(phoneField); nameField.style.display = 'none'; phoneField.style.display = 'none'; gift.dataset.ready = '1'; } /* نعم / لا */ const radios = gift.querySelectorAll('input[type="radio"]'); if (radios.length) { const yes = [...radios].find(r => r.closest('label')?.innerText.includes('نعم') ); const no = [...radios].find(r => r.closest('label')?.innerText.includes('لا') ); if (yes?.checked) { nameField.style.display = 'block'; phoneField.style.display = 'block'; } if (no?.checked) { nameField.style.display = 'none'; phoneField.style.display = 'none'; } } }, 500); /*خانه لا افتراضي*/ document.addEventListener("DOMContentLoaded", function () { setTimeout(() => { const noRadio = document.querySelector( 'input[value="1630298578"]' ); if (noRadio) { noRadio.click(); } }, 1000); }); /*خانه نعم اجباري */ document.addEventListener("click", function (e) { const btn = e.target.closest( '#cart-submit button, #cart-submit' ); if (!btn) return; const yesRadio = document.querySelector( 'input[name="options[851405446]"][value="390546129"]' ); if (!yesRadio || !yesRadio.checked) return; const receiverName = document.querySelector( 'input[name="options[1300255374]"]' ); const receiverPhone = document.querySelector( 'input[name="options[1766559880]"]' ); const name = receiverName?.value.trim() || ""; const phone = receiverPhone?.value.replace(/\D/g, "") || ""; let errorBox = document.querySelector( ".receiver-error" ); if (!errorBox) { errorBox = document.createElement("div"); errorBox.className = "receiver-error"; const container = receiverName?.closest( ".s-product-options-option-container" ); container?.prepend(errorBox); } errorBox.style.display = "none"; function showError(message){ errorBox.innerHTML = "🌸 " + message; errorBox.style.display = "block"; } if (!name) { e.preventDefault(); e.stopImmediatePropagation(); showError( "يرجى تعبئة اسم المستلم" ); receiverName?.focus(); return false; } if (!phone) { e.preventDefault(); e.stopImmediatePropagation(); showError( "يرجى تعبئة رقم المستلم" ); receiverPhone?.focus(); return false; } if ( phone.length !== 10 || !phone.startsWith("05") ) { e.preventDefault(); e.stopImmediatePropagation(); showError( "رقم المستلم يجب أن يتكون من 10 أرقام ويبدأ بـ 05" ); receiverPhone?.focus(); return false; } }, true);