document.addEventListener('DOMContentLoaded', function () { const socialHTML = `
1

دعم العملاء

متاح الآن - نرد خلال دقيقة

مرحباً! 👋

كيف يمكننا مساعدتك اليوم؟ فريقنا جاهز للرد على جميع استفساراتك.

فريق الدعم

`; document.body.insertAdjacentHTML('beforeend', socialHTML); // المتغيرات const waBtn = document.getElementById('wa-float-btn'); const widget = document.getElementById('wa-custom-widget'); const closeBtn = document.getElementById('wa-close'); const startBtn = document.getElementById('wa-start-btn'); const badge = document.getElementById('wa-badge'); const toggleBtn = document.getElementById('toggle-social'); const socialBar = document.getElementById('social-bar'); // ─── كشف صفحة المنتج ورفع الزر فوق أزرار الطلب ─── function checkProductPage() { var isProductPage = document.querySelector('.s-product-options-option-container') || document.querySelector('.product__description') || document.querySelector('#product-content') || document.querySelector('[id*="add-to-cart"]') || /\/(p|products)\//.test(window.location.pathname); if (isProductPage && window.innerWidth <= 768) { waBtn.classList.add('wa-product-page'); var mt = document.getElementById('wa-mini-toggle'); if (mt) mt.classList.add('wa-mini-product'); } else { waBtn.classList.remove('wa-product-page'); var mt2 = document.getElementById('wa-mini-toggle'); if (mt2) mt2.classList.remove('wa-mini-product'); } } // فحص عند التحميل وعند تغيير حجم الشاشة checkProductPage(); window.addEventListener('resize', checkProductPage); // دالة إغلاق النافذة مع أنيميشن function closeWidget() { if (!widget.classList.contains('show')) return; if (widget.classList.contains('wa-closing')) return; widget.classList.add('wa-closing'); // إغلاق بعد انتهاء الأنيميشن أو بعد 300ms كحد أقصى var closed = false; function finishClose() { if (closed) return; closed = true; widget.classList.remove('show', 'wa-closing'); } widget.addEventListener('animationend', finishClose, { once: true }); setTimeout(finishClose, 300); } // فتح/إغلاق Widget waBtn.addEventListener('click', function () { if (widget.classList.contains('show')) { closeWidget(); } else { widget.classList.remove('wa-closing'); widget.classList.add('show'); badge.style.display = 'none'; } socialBar.classList.remove('show'); toggleBtn.classList.remove('active'); }); closeBtn.addEventListener('click', function () { closeWidget(); }); // فتح الواتساب startBtn.addEventListener('click', function () { window.open('https://api.whatsapp.com/send/?phone=966579844925&text=مرحباً، أحتاج مساعدة 👋', '_blank'); }); // تبديل شريط المنصات toggleBtn.addEventListener('click', function () { socialBar.classList.toggle('show'); toggleBtn.classList.toggle('active'); closeWidget(); }); // روابط المنصات المحدثة document.getElementById('instagram-btn').addEventListener('click', function () { window.open('https://www.instagram.com/Miftahdigitalksa', '_blank'); }); document.getElementById('tiktok-btn').addEventListener('click', function () { window.open('https://www.tiktok.com/@Miftahksa', '_blank'); }); document.getElementById('twitter-btn').addEventListener('click', function () { window.open('https://x.com/MiftahKSA', '_blank'); }); // إغلاق عند النقر خارج العناصر document.addEventListener('click', function (e) { if (!widget.contains(e.target) && !waBtn.contains(e.target) && !socialBar.contains(e.target) && !toggleBtn.contains(e.target)) { closeWidget(); socialBar.classList.remove('show'); toggleBtn.classList.remove('active'); } }); // ═══════════════════════════════════════════════════════ // نظام الإخفاء/الإظهار الذكي عند التمرير (موبايل فقط) // ═══════════════════════════════════════════════════════ var lastScrollY = window.scrollY; var scrollDelta = 0; var scrollThreshold = 60; var ticking = false; var isHidden = false; var miniToggle = document.getElementById('wa-mini-toggle'); function isMobile() { return window.innerWidth <= 768; } function hideFloatingElements() { if (isHidden) return; isHidden = true; waBtn.classList.add('wa-scroll-hidden'); toggleBtn.classList.add('wa-scroll-hidden'); // إغلاق النافذة والشريط عند الإخفاء if (socialBar.classList.contains('show')) { socialBar.classList.remove('show'); toggleBtn.classList.remove('active'); } // إظهار زر إعادة الإظهار المصغر if (miniToggle) miniToggle.classList.add('visible'); } function showFloatingElements() { if (!isHidden) return; isHidden = false; waBtn.classList.remove('wa-scroll-hidden'); toggleBtn.classList.remove('wa-scroll-hidden'); // إخفاء زر إعادة الإظهار المصغر if (miniToggle) miniToggle.classList.remove('visible'); } // زر إعادة الإظهار المصغر if (miniToggle) { miniToggle.addEventListener('click', function (e) { e.stopPropagation(); scrollDelta = 0; showFloatingElements(); }); } function onScroll() { if (!isMobile()) { if (isHidden) showFloatingElements(); return; } var currentScrollY = window.scrollY; var scrollDirection = currentScrollY - lastScrollY; if (Math.abs(scrollDirection) < 3) { lastScrollY = currentScrollY; ticking = false; return; } if (scrollDirection > 0) { scrollDelta += scrollDirection; if (scrollDelta > scrollThreshold) { hideFloatingElements(); if (widget.classList.contains('show')) { closeWidget(); } } } else { scrollDelta = 0; showFloatingElements(); } if (currentScrollY <= 10) { scrollDelta = 0; showFloatingElements(); } lastScrollY = currentScrollY; ticking = false; } window.addEventListener('scroll', function () { if (!ticking) { requestAnimationFrame(onScroll); ticking = true; } }, { passive: true }); }); document.addEventListener('DOMContentLoaded', function () { // البحث عن قسم الوسوم (tags) const tagsSection = document.querySelector('.nova-main-content .mb-3'); if (tagsSection && !document.querySelector('.product-features-boxes')) { // إنشاء حاوية المزايا const featuresContainer = document.createElement('div'); featuresContainer.className = 'product-features-boxes'; featuresContainer.style.cssText = ` display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 12px !important; margin: 20px 0 !important; width: 100% !important; `; // البيانات للصناديق الثلاثة const features = [ { icon: ` `, title: 'الدعم الفني' }, { icon: ` `, title: 'ضمان الاشتراك' }, { icon: ` `, title: 'أفضل الأسعار' } ]; // إنشاء كل صندوق features.forEach((feature, index) => { const box = document.createElement('div'); box.className = `feature-box feature-box-${index + 1}`; box.style.cssText = ` background: linear-gradient(135deg, rgba(0, 123, 130, 0.06) 0%, rgba(0, 92, 99, 0.03) 100%) !important; border: 1.5px solid rgba(0, 123, 130, 0.2) !important; border-radius: 12px !important; padding: 12px 14px !important; display: flex !important; flex-direction: row !important; align-items: center !important; gap: 10px !important; text-align: right !important; transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important; cursor: pointer !important; position: relative !important; overflow: hidden !important; min-height: 58px !important; `; box.innerHTML = `
${feature.icon}

${feature.title}

`; // تأثيرات Hover box.addEventListener('mouseenter', function () { this.style.transform = 'translateY(-3px)'; this.style.boxShadow = '0 8px 20px rgba(0, 123, 130, 0.18)'; this.style.borderColor = 'rgba(0, 123, 130, 0.4)'; this.style.background = 'linear-gradient(135deg, rgba(0, 123, 130, 0.1) 0%, rgba(0, 92, 99, 0.05) 100%)'; const icon = this.querySelector('.feature-icon'); if (icon) icon.style.transform = 'scale(1.1) rotate(5deg)'; }); box.addEventListener('mouseleave', function () { this.style.transform = 'translateY(0)'; this.style.boxShadow = 'none'; this.style.borderColor = 'rgba(0, 123, 130, 0.2)'; this.style.background = 'linear-gradient(135deg, rgba(0, 123, 130, 0.06) 0%, rgba(0, 92, 99, 0.03) 100%)'; const icon = this.querySelector('.feature-icon'); if (icon) icon.style.transform = 'scale(1) rotate(0deg)'; }); featuresContainer.appendChild(box); }); // إدراج الصناديق مباشرة بعد قسم الوسوم tagsSection.after(featuresContainer); // ── ستايلات الموبايل لصناديق المزايا ── const featuresStyle = document.createElement('style'); featuresStyle.textContent = ` @media (max-width: 640px) { .product-features-boxes { grid-template-columns: 1fr !important; gap: 8px !important; margin: 14px 0 !important; } .product-features-boxes .feature-box { padding: 10px 12px !important; min-height: auto !important; gap: 8px !important; flex-direction: row !important; } .product-features-boxes .feature-icon svg { width: 24px !important; height: 24px !important; } .product-features-boxes .feature-content h3 { font-size: 13px !important; white-space: normal !important; word-break: keep-all !important; } } @media (min-width: 641px) and (max-width: 768px) { .product-features-boxes .feature-icon svg { width: 24px !important; height: 24px !important; } .product-features-boxes .feature-content h3 { font-size: 12px !important; white-space: normal !important; } .product-features-boxes .feature-box { padding: 8px 10px !important; min-height: auto !important; gap: 6px !important; } } `; document.head.appendChild(featuresStyle); } }); document.addEventListener('DOMContentLoaded', function () { const heroSection = document.querySelector('.nova-video-text-photo .flex-1.text-center'); if (heroSection) { // إضافة Styles مع !important const style = document.createElement('style'); style.textContent = ` @keyframes floatAnimation { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-8px); } } .hero-search-input { background: #ffffff !important; background-color: #ffffff !important; text-align: right !important; direction: rtl !important; } .hero-search-input::placeholder { color: rgba(26, 35, 64, 0.45) !important; text-align: right !important; } .hero-search-container { animation: floatAnimation 3s ease-in-out infinite !important; } `; document.head.appendChild(style); // إنشاء مربع البحث const searchBox = document.createElement('div'); searchBox.className = 'hero-search-container'; searchBox.style.cssText = ` margin-top: 40px; max-width: 700px; margin-left: auto; margin-right: auto; position: relative; `; const searchForm = document.createElement('form'); searchForm.action = '/search'; searchForm.method = 'GET'; searchForm.style.cssText = ` position: relative; width: 100%; `; const searchInput = document.createElement('input'); searchInput.type = 'text'; searchInput.name = 'q'; searchInput.className = 'hero-search-input'; searchInput.placeholder = 'ابحث عن المنتجات، الباقات أو استخدم كلمات مفتاحية…'; searchInput.setAttribute('dir', 'rtl'); searchInput.style.cssText = ` width: 100% !important; height: 65px !important; padding: 0 24px 0 70px !important; background: #ffffff !important; background-color: #ffffff !important; border: 2px solid rgba(0, 123, 130, 0.35) !important; border-radius: 16px !important; color: #1a2340 !important; font-size: 16px !important; font-weight: 500 !important; outline: none !important; box-shadow: 0 6px 24px rgba(0, 123, 130, 0.12), 0 0 0 1px rgba(0, 123, 130, 0.08) inset !important; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important; text-align: right !important; direction: rtl !important; line-height: 65px !important; `; searchInput.addEventListener('focus', function () { this.style.borderColor = 'rgba(0, 123, 130, 0.7)'; this.style.boxShadow = '0 10px 32px rgba(0, 123, 130, 0.25), 0 0 0 1px rgba(0, 123, 130, 0.2) inset'; searchBox.style.animation = 'none'; }); searchInput.addEventListener('blur', function () { this.style.borderColor = 'rgba(0, 123, 130, 0.35)'; this.style.boxShadow = '0 6px 24px rgba(0, 123, 130, 0.12), 0 0 0 1px rgba(0, 123, 130, 0.08) inset'; searchBox.style.animation = 'floatAnimation 3s ease-in-out infinite'; }); const searchButton = document.createElement('button'); searchButton.type = 'submit'; searchButton.innerHTML = ` `; searchButton.style.cssText = ` position: absolute !important; left: 10px !important; top: 50% !important; transform: translateY(-50%) !important; width: 48px !important; height: 48px !important; background: linear-gradient(135deg, #007b82 0%, #005c63 100%) !important; border: none !important; border-radius: 12px !important; color: #ffffff !important; cursor: pointer !important; display: flex !important; align-items: center !important; justify-content: center !important; box-shadow: 0 6px 20px rgba(0, 123, 130, 0.4) !important; transition: all 0.2s ease !important; flex-shrink: 0 !important; `; searchButton.addEventListener('mouseenter', function () { this.style.boxShadow = '0 8px 24px rgba(0, 123, 130, 0.5)'; this.style.filter = 'brightness(1.1)'; }); searchButton.addEventListener('mouseleave', function () { this.style.boxShadow = '0 6px 20px rgba(0, 123, 130, 0.4)'; this.style.filter = 'brightness(1)'; }); searchButton.addEventListener('mousedown', function () { this.style.transform = 'translateY(-50%) scale(0.95)'; }); searchButton.addEventListener('mouseup', function () { this.style.transform = 'translateY(-50%) scale(1)'; }); // تجميع العناصر searchForm.appendChild(searchInput); searchForm.appendChild(searchButton); searchBox.appendChild(searchForm); // إضافة مربع البحث بعد الفقرة const paragraph = heroSection.querySelector('p'); if (paragraph) { paragraph.after(searchBox); } // إخفاء الأزرار الأصلية const buttonsContainer = heroSection.querySelector('.flex.flex-col.sm\\:flex-row'); if (buttonsContainer) { buttonsContainer.style.display = 'none'; } } }); document.addEventListener('DOMContentLoaded', function () { setTimeout(function () { // ── 0. إضافة ستايلات RTL لأزرار الخيارات ────────────────────────── const optionsRtlStyle = document.createElement('style'); optionsRtlStyle.textContent = ` /* ─── RTL لأزرار الخيارات ─── */ .s-product-options-multiple-options-wrapper { display: flex !important; flex-wrap: wrap; gap: 10px !important; align-items: flex-start; direction: rtl !important; } .s-product-options-multiple-options-wrapper label { display: inline-flex !important; align-items: center; direction: rtl !important; text-align: right !important; gap: 8px; } .s-product-options-multiple-options-wrapper label > div, .s-product-options-multiple-options-wrapper label > span { direction: rtl !important; text-align: right !important; unicode-bidi: embed; } .s-product-options-multiple-options-wrapper input[type="checkbox"] { margin-left: 0 !important; margin-right: 8px !important; order: 1; } /* موبايل */ @media (max-width: 640px) { .s-product-options-multiple-options-wrapper label { flex: 0 1 100%; justify-content: flex-start; direction: rtl !important; text-align: right !important; gap: 8px; } } `; document.head.appendChild(optionsRtlStyle); // ── 1. اختيار واحد فقط داخل كل مجموعة ────────────────────────── const checkboxWrappers = document.querySelectorAll('.s-product-options-multiple-options-wrapper'); checkboxWrappers.forEach(function (wrapper) { const checkboxes = wrapper.querySelectorAll('input[type="checkbox"]'); checkboxes.forEach(function (checkbox) { checkbox.addEventListener('change', function () { if (this.checked) { checkboxes.forEach(function (other) { if (other !== checkbox) other.checked = false; }); } }); }); }); // ── 2. ربط مجموعات "نوع الإشتراك" ببعض ───────────────────────── // الكلمات المفتاحية التي تحدد المجموعات المرتبطة const linkedKeywords = ['نوع الإشتراك', 'نوع الاشتراك', 'نوع الإشتراكات', 'نوع الاشتراكات']; // جمع المجموعات المرتبطة const allContainers = document.querySelectorAll('.s-product-options-option-container'); const linkedContainers = []; allContainers.forEach(function (container) { const label = container.querySelector( '.s-product-options-option-label b, .s-product-options-option-label' ); if (!label) return; const labelText = label.textContent.trim(); const isLinked = linkedKeywords.some(function (keyword) { return labelText.includes(keyword); }); if (isLinked) { linkedContainers.push(container); } }); // جمع جميع checkboxes في المجموعات المرتبطة const linkedCheckboxes = []; linkedContainers.forEach(function (container) { const checkboxes = container.querySelectorAll('input[type="checkbox"]'); checkboxes.forEach(function (cb) { linkedCheckboxes.push(cb); }); }); // عند اختيار أي checkbox في المجموعات المرتبطة → إلغاء الباقي linkedCheckboxes.forEach(function (checkbox) { checkbox.addEventListener('change', function () { if (this.checked) { linkedCheckboxes.forEach(function (other) { if (other !== checkbox) other.checked = false; }); } }); }); }, 300); }); document.addEventListener('DOMContentLoaded', function () { // الانتظار حتى تحميل العنصر setTimeout(function () { // العثور على قسم المنتجات الأحدث const productsSection = document.getElementById('best-offers-2-slider'); if (productsSection) { // إنشاء HTML الزر const viewAllButtonHTML = `
عرض جميع المنتجات
`; // إضافة الزر بعد قسم المنتجات productsSection.insertAdjacentHTML('afterend', viewAllButtonHTML); } }, 500); }); document.addEventListener('DOMContentLoaded', function () { // الانتظار حتى تحميل الصفحة setTimeout(function () { // إضافة الستايلات const style = document.createElement('style'); style.textContent = ` /* تصميم الـ checkboxes البسيط */ .s-product-options-multiple-options-wrapper { display: flex !important; flex-wrap: wrap; gap: 10px !important; align-items: flex-start; } .s-product-options-multiple-options-wrapper label { display: inline-flex !important; align-items: center; padding: 8px 16px !important; margin: 0 !important; background: rgba(240, 245, 255, 0.95); border: 2px solid #d0d9e8; border-radius: 20px; cursor: pointer; transition: all 0.25s ease; position: relative; backdrop-filter: blur(5px); flex: 0 1 calc(50% - 5px); min-width: fit-content; } .s-product-options-multiple-options-wrapper label:nth-child(3) { flex: 0 1 100%; } .s-product-options-multiple-options-wrapper label:hover { border-color: #007b82; background: rgba(0, 123, 130, 0.06); transform: scale(1.03); } /* تصميم الـ checkbox نفسه */ .s-product-options-multiple-options-wrapper input[type="checkbox"] { appearance: none; -webkit-appearance: none; width: 16px; height: 16px; border: 2px solid #b0bcd0; border-radius: 4px; margin-left: 8px; cursor: pointer; position: relative; transition: all 0.25s ease; flex-shrink: 0; background: transparent; } .s-product-options-multiple-options-wrapper input[type="checkbox"]:hover { border-color: #007b82; } /* عند التحديد */ .s-product-options-multiple-options-wrapper input[type="checkbox"]:checked { background: #007b82; border-color: #007b82; } /* علامة الصح */ .s-product-options-multiple-options-wrapper input[type="checkbox"]:checked::after { content: '✓'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #ffffff; font-size: 11px; font-weight: bold; } /* تصميم النص */ .s-product-options-multiple-options-wrapper label > div { font-size: 14px; font-weight: 500; color: #1a2340; transition: color 0.25s ease; white-space: nowrap; } /* عند التحديد */ .s-product-options-multiple-options-wrapper input[type="checkbox"]:checked ~ div { color: #007b82; font-weight: 600; } /* تصميم الـ label المحدد */ .s-product-options-multiple-options-wrapper label:has(input:checked) { background: rgba(0, 123, 130, 0.08); border-color: #007b82; box-shadow: 0 0 12px rgba(0, 123, 130, 0.2); } /* للموبايل */ @media (max-width: 640px) { .s-product-options-multiple-options-wrapper label { flex: 0 1 100%; padding: 10px 14px !important; justify-content: space-between; } .s-product-options-multiple-options-wrapper label > div { font-size: 13px; } } `; document.head.appendChild(style); // منطق اختيار واحد فقط const checkboxWrappers = document.querySelectorAll('.s-product-options-multiple-options-wrapper'); checkboxWrappers.forEach(function (wrapper) { const checkboxes = wrapper.querySelectorAll('input[type="checkbox"]'); checkboxes.forEach(function (checkbox) { checkbox.addEventListener('change', function () { if (this.checked) { // إلغاء تحديد باقي الـ checkboxes في نفس المجموعة checkboxes.forEach(function (otherCheckbox) { if (otherCheckbox !== checkbox) { otherCheckbox.checked = false; } }); } }); }); }); }, 600); }); // إخفاء العنصر القديم فوراً قبل أي شيء (function () { const hideStyle = document.createElement('style'); hideStyle.id = 'temp-hide-description'; hideStyle.textContent = ` .product__description { opacity: 0 !important; pointer-events: none !important; } `; document.head.appendChild(hideStyle); })(); document.addEventListener('DOMContentLoaded', function () { // تنفيذ فوري بدون تأخير setTimeout(function () { // العثور على عنصر الوصف const descriptionContainer = document.querySelector('.product__description'); if (descriptionContainer) { // إضافة الستايلات const style = document.createElement('style'); style.textContent = ` /* تصميم الصندوق بنفس أسلوب المرجع */ .product__description { background: #ffffff !important; border: 1.5px solid rgba(0, 123, 130, 0.2) !important; border-radius: 12px !important; padding: 0 !important; margin-bottom: 20px !important; overflow: hidden !important; transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1); opacity: 1 !important; pointer-events: all !important; } .product__description:hover { border-color: rgba(0, 123, 130, 0.35) !important; } /* عنوان الصندوق */ .product-features-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; cursor: pointer; transition: all 0.3s ease; user-select: none; border-bottom: 1.5px solid rgba(0, 123, 130, 0.15); } .product-features-header:hover { background: rgba(0, 123, 130, 0.05); } .product-features-title { display: flex; align-items: center; gap: 12px; margin: 0; font-size: 17px; font-weight: 700; color: #007b82; } .product-features-icon { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: rgba(0, 123, 130, 0.1); border-radius: 6px; font-size: 16px; color: #007b82; } .product-features-toggle { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; transition: all 0.3s ease; } .product-features-toggle i { font-size: 16px; color: #007b82; transition: transform 0.3s ease; } .product-features-header.collapsed .product-features-toggle i { transform: rotate(-180deg); } /* معاينة النص */ .product-features-preview { padding: 14px 18px; max-height: 80px; overflow: hidden; transition: max-height 0.4s ease, opacity 0.3s ease; position: relative; } .product-features-preview.hidden { max-height: 0; padding: 0 18px; opacity: 0; } .product-features-preview-text { color: rgba(68, 76, 94, 0.85); font-size: 14px; line-height: 1.7; text-align: right; margin: 0; } .product-features-preview::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 30px; background: linear-gradient(to bottom, transparent, rgba(0, 123, 130, 0.04)); pointer-events: none; } /* محتوى الصندوق */ .product-features-content { padding: 0; max-height: 0; overflow: hidden; transition: max-height 0.4s ease; } .product-features-content.expanded { max-height: 2000px; padding: 20px 18px; } /* تنسيق المحتوى */ .article--main { max-height: none !important; line-height: 1.8 !important; direction: rtl; text-align: right; } .article--main h1, .article--main h2, .article--main h3 { color: #007b82 !important; margin-top: 20px; margin-bottom: 12px; font-weight: 700; } .article--main h1 { font-size: 19px; margin-top: 0; } .article--main h3 { font-size: 17px; margin-top: 24px; } .article--main p { color: #444c5e !important; margin-bottom: 14px; line-height: 1.9 !important; text-align: right; } .article--main ul { list-style: none; padding: 0; margin: 16px 0; } .article--main ul li { position: relative; padding-right: 28px; margin-bottom: 12px; color: #444c5e !important; line-height: 1.8; text-align: right; } .article--main ul li::before { content: '✓'; position: absolute; right: 0; top: 2px; color: #007b82; font-weight: bold; font-size: 16px; } /* إخفاء الزر القديم */ #btn-show-more { display: none !important; } /* للموبايل */ @media (max-width: 640px) { .product-features-header { padding: 12px 16px; } .product-features-title { font-size: 16px; gap: 10px; } .product-features-icon { width: 26px; height: 26px; font-size: 15px; } .product-features-preview { padding: 12px 16px; } .product-features-content.expanded { padding: 18px 16px; } .article--main h1 { font-size: 17px; } .article--main h3 { font-size: 16px; } } `; document.head.appendChild(style); // الحصول على المحتوى الأصلي const article = descriptionContainer.querySelector('.article--main'); let previewText = ''; if (article) { // استخراج أول فقرتين للمعاينة const firstP = article.querySelector('p'); if (firstP) { previewText = firstP.textContent.trim().substring(0, 120) + '...'; } } // إنشاء العنوان const header = document.createElement('div'); header.className = 'product-features-header collapsed'; header.innerHTML = `
مزايا المنتج
`; // إنشاء معاينة النص const preview = document.createElement('div'); preview.className = 'product-features-preview'; preview.innerHTML = `

${previewText}

`; // إنشاء محتوى الصندوق const content = document.createElement('div'); content.className = 'product-features-content'; // نقل المحتوى الأصلي if (article) { content.appendChild(article); } // مسح المحتوى القديم وإضافة الجديد descriptionContainer.innerHTML = ''; descriptionContainer.appendChild(header); descriptionContainer.appendChild(preview); descriptionContainer.appendChild(content); // إضافة وظيفة الفتح والإغلاق header.addEventListener('click', function () { header.classList.toggle('collapsed'); content.classList.toggle('expanded'); preview.classList.toggle('hidden'); }); // إزالة ستايل الإخفاء المؤقت const tempHide = document.getElementById('temp-hide-description'); if (tempHide) { tempHide.remove(); } } }, 100); // تقليل التأخير إلى 100ms فقط }); document.addEventListener('DOMContentLoaded', function () { var CART_URL = '/cart'; var REMOVE_ALERT_DURATION = 5000; var _removing = false; // ════════════════════════════════════════ // 1 — Toast إضافة المنتج (SweetAlert2) // ════════════════════════════════════════ var swalObserver = new MutationObserver(function (mutations) { mutations.forEach(function (m) { m.addedNodes.forEach(function (node) { if (node.nodeType !== 1) return; var toast = node.classList && node.classList.contains('swal2-toast') ? node : node.querySelector && node.querySelector('.swal2-toast'); if (!toast || toast.dataset.ci) return; toast.dataset.ci = '1'; if (_removing) { setTimeout(function () { var c = toast.closest('.swal2-container'); if (c) c.remove(); else toast.remove(); }, 20); return; } setTimeout(function () { buildAddToast(toast); }, 60); }); }); }); swalObserver.observe(document.body, { childList: true, subtree: true }); function buildAddToast(toast) { var name = getProductName(); var header = document.createElement('div'); header.className = 'cart-toast-header'; header.innerHTML = '
' + '' + '
' + '
' + 'تمت الإضافة إلى السلة ✓' + (name ? '' + name + '' : '') + '
' + ''; var divider = document.createElement('div'); divider.className = 'cart-toast-divider'; var actions = document.createElement('div'); actions.className = 'cart-toast-actions'; actions.innerHTML = '' + '' + '' + '' + '' + '' + 'إتمام الطلب' + ''; var progress = toast.querySelector('.swal2-timer-progress-bar-container'); toast.insertBefore(header, progress || null); toast.insertBefore(divider, progress || null); toast.insertBefore(actions, progress || null); header.querySelector('.cart-toast-close').addEventListener('click', function () { var c = toast.closest('.swal2-container'); if (c) c.remove(); else toast.remove(); }); } // ════════════════════════════════════════ // 2 — اعتراض أزرار الحذف // ════════════════════════════════════════ function interceptRemoveButtons() { var sel = [ 'button[class*="remove"]', 'button[class*="delete"]', 'a[class*="remove"]', '[class*="cart"] [class*="remove"]', '[class*="cart"] [class*="delete"]', '[data-remove]', '[data-delete]' ].join(','); document.querySelectorAll(sel).forEach(function (btn) { if (btn.dataset.ri) return; btn.dataset.ri = '1'; btn.addEventListener('click', function () { _removing = true; // ── قراءة الاسم من عنصر المنتج في السلة ── var name = getCartItemName(btn); showRemoveAlert(name); setTimeout(function () { _removing = false; }, 4000); }, false); }); } var domObserver = new MutationObserver(function () { setTimeout(interceptRemoveButtons, 300); }); domObserver.observe(document.body, { childList: true, subtree: true }); interceptRemoveButtons(); // ════════════════════════════════════════ // 3 — تنبيه الإزالة // ════════════════════════════════════════ function showRemoveAlert(name) { var old = document.getElementById('crt-wrap'); if (old) old.remove(); var nameHTML = name ? '' + name + '' : ''; var wrap = document.createElement('div'); wrap.id = 'crt-wrap'; wrap.innerHTML = '
' + '
' + '
' + '' + '' + '' + '' + '' + '
' + '
' + 'تمت إزالة المنتج من السلة' + nameHTML + '🔥 لا تفوّت هذا المنتج — الكميات محدودة!' + '
' + '' + '
' + '
' + '
'; document.body.appendChild(wrap); setTimeout(function () { var bar = document.getElementById('crt-bar'); if (bar) { bar.style.transition = 'width ' + (REMOVE_ALERT_DURATION / 1000) + 's linear'; bar.style.width = '0%'; } }, 50); document.getElementById('crt-close-btn').addEventListener('click', dismissAlert); setTimeout(dismissAlert, REMOVE_ALERT_DURATION); } function dismissAlert() { var w = document.getElementById('crt-wrap'); if (!w) return; w.style.animation = 'crt-slideOut 0.3s ease forwards'; setTimeout(function () { if (w && w.parentNode) w.remove(); }, 320); } // ════════════════════════════════════════ // helpers // ════════════════════════════════════════ // اسم المنتج في صفحة المنتج — من Salla config أولاً function getProductName() { // المحاولة 1: Salla config API try { if (window.salla && salla.config && typeof salla.config.get === 'function') { var n = salla.config.get('product.name') || salla.config.get('product')?.name; if (n && n.trim()) return truncate(n.trim()); } } catch (e) {} // المحاولة 2: selectors خاصة بسلة var sallaSelectors = [ '[class*="product__name"]', '[class*="product__title"]', '.s-product-name', '[data-product-name]', '[data-name]' ]; for (var i = 0; i < sallaSelectors.length; i++) { var el = document.querySelector(sallaSelectors[i]); if (el) { var t = (el.dataset.productName || el.dataset.name || el.innerText || '').trim(); if (t.length > 1) return truncate(t); } } // فشل → لا اسم return null; } // اسم المنتج من عنصر السلة عند الحذف function getCartItemName(btn) { var itemEl = btn.closest('[data-id]') || btn.closest('[class*="cart-item"]') || btn.closest('[class*="cart__item"]') || btn.closest('[class*="item"]') || btn.parentElement; if (!itemEl) return null; // selectors خاصة بسلة داخل عنصر المنتج var nameSelectors = [ '[class*="product__name"]', '[class*="product-name"]', '[class*="item__name"]', '[class*="item-name"]', '[data-product-name]', '[data-name]', 'h3', 'h4', 'p[class*="name"]', 'a[class*="name"]' ]; for (var i = 0; i < nameSelectors.length; i++) { var el = itemEl.querySelector(nameSelectors[i]); if (el) { var t = (el.dataset.productName || el.dataset.name || el.innerText || '').trim(); if (t.length > 1) return truncate(t); } } return null; // فشل → لا اسم } function truncate(str) { return str.length > 32 ? str.substring(0, 30) + '…' : str; } }); document.addEventListener('DOMContentLoaded', function () { // ══════════════════════════════════════ // فتح مودال تسجيل الدخول // ══════════════════════════════════════ function openLoginModal() { try { if (window.salla && salla.event && typeof salla.event.dispatch === 'function') { salla.event.dispatch('login::open'); } else { window.location.href = '/login'; } } catch (e) { window.location.href = '/login'; } } // ══════════════════════════════════════ // تحسين فورم المستخدم المسجّل // ══════════════════════════════════════ function enhanceLoggedInForm() { document.querySelectorAll('.s-comment-form-wrapper').forEach(function (wrapper) { if (wrapper.dataset.enhanced) return; wrapper.dataset.enhanced = '1'; // ─ رأس الفورم ─ var header = document.createElement('div'); header.className = 'sc-form-header'; header.innerHTML = '
' + '' + '' + '' + '
' + '
' + 'شارك تجربتك مع هذا المنتج' + 'رأيك يُساعد العملاء الآخرين على اتخاذ قرارهم بثقة' + '
'; // إدراج الرأس قبل الـ wrapper مباشرةً wrapper.parentNode.insertBefore(header, wrapper); // ─ label الـ textarea ─ var content = wrapper.querySelector('.s-comment-form-content'); var textarea = wrapper.querySelector('.s-comment-form-input'); if (content && textarea) { var lbl = document.createElement('div'); lbl.className = 'sc-textarea-label'; lbl.innerHTML = '' + '' + '' + '' + '' + '' + 'اكتب تعليقك أو سؤالك'; content.insertBefore(lbl, textarea); // ─ عداد الأحرف ─ var maxLen = parseInt(textarea.getAttribute('maxlength') || '500', 10); var counter = document.createElement('div'); counter.className = 'sc-char-count'; counter.textContent = '0 / ' + maxLen; content.appendChild(counter); textarea.addEventListener('input', function () { var len = textarea.value.length; counter.textContent = len + ' / ' + maxLen; counter.classList.remove('sc-char-warn', 'sc-char-limit'); if (len >= maxLen) counter.classList.add('sc-char-limit'); else if (len >= maxLen * 0.8) counter.classList.add('sc-char-warn'); }); } // ─ نص تحفيزي في زر الإرسال ─ var action = wrapper.querySelector('.s-comment-form-action'); if (action) { var hint = document.createElement('div'); hint.className = 'sc-action-hint'; hint.innerHTML = '' + '' + '' + 'تعليقك يُنشر فور مراجعته'; action.insertBefore(hint, action.firstChild); } }); } // ══════════════════════════════════════ // بطاقة الزائر // ══════════════════════════════════════ function initGuestCommentCard() { document.querySelectorAll('salla-comment-form.hydrated').forEach(function (el) { if (el.querySelector('form')) { enhanceLoggedInForm(); return; } if (el.dataset.guestInjected) return; el.dataset.guestInjected = '1'; var card = document.createElement('div'); card.className = 'sc-guest-card'; card.innerHTML = '
' + '' + '' + '' + '
' + '
' + 'ما رأيك في هذا المنتج؟' + 'انضم لعملائنا وشارك تجربتك — تقييمك يبني ثقة المتجر' + '
' + '' + '' + '' + '' + '' + '
' + '
' + ''; el.parentNode.insertBefore(card, el.nextSibling); card.querySelector('.sc-guest-btn').addEventListener('click', openLoginModal); }); } // تشغيل أولي initGuestCommentCard(); // مراقبة الـ DOM لحالة hydration متأخرة var obs = new MutationObserver(function () { initGuestCommentCard(); }); obs.observe(document.body, { childList: true, subtree: true }); });