document.addEventListener("DOMContentLoaded", function () { // 1) وظيفة إعادة هيكلة الكروت + تعديل الزر function restructureCards() { const productCards = document.querySelectorAll(".s-product-card-content-wrapper"); productCards.forEach((card) => { const priceBox = card.querySelector(".s-product-card-sale-price"); const footer = card.querySelector(".s-product-card-content-footer"); if (priceBox && footer) { // لو لسه ما تعملش إعادة الهيكلة if (!card.querySelector(".custom-card-bottom")) { const bottomWrapper = document.createElement("div"); bottomWrapper.classList.add("custom-card-bottom"); // ننقل السعر + زر السلة bottomWrapper.appendChild(priceBox); bottomWrapper.appendChild(footer); const mainContent = card.querySelector(".s-product-card-content-main"); if (mainContent) { mainContent.insertAdjacentElement("afterend", bottomWrapper); } } } // إزالة كلمة "إضافة للسلة" من الزر const buttonText = card.querySelector(".s-product-card-content-footer .s-button-text span"); if (buttonText && buttonText.textContent.includes("إضافة للسلة")) { buttonText.textContent = ""; // نمسح النص ونسيب الأيقونة } }); } // نكرر لحد ما الكروت تبقى موجودة وبعدين نوقف const interval = setInterval(() => { const cards = document.querySelectorAll(".s-product-card-content-wrapper"); if (cards.length > 0) { restructureCards(); clearInterval(interval); } }, 1000); // مراقبة إضافية للـ DOM للتأكد من إضافة العنصر لما الصفحة تكمل تحميل const checkAndAddGrid = function() { if (document.querySelector('.custom-grid')) return; let targetSection = document.querySelector('#featured-products-style2-15'); if (!targetSection) { targetSection = document.querySelector('section.featured-products-style2'); } if (!targetSection) { targetSection = document.querySelector('section.s-block-tabs.s-block--tabs-produtcs'); } if (!targetSection) { const productSliders = document.querySelectorAll('salla-products-slider'); if (productSliders.length > 0) { const lastSlider = productSliders[productSliders.length - 1]; targetSection = lastSlider.closest('section'); } } if (targetSection) { const blockHTML = `
`; targetSection.insertAdjacentHTML("beforebegin", blockHTML); } }; setTimeout(checkAndAddGrid, 2000); const gridObserver = new MutationObserver(checkAndAddGrid); gridObserver.observe(document.body, { childList: true, subtree: true }); const observer = new MutationObserver(() => { restructureCards(); }); observer.observe(document.body, { childList: true, subtree: true }); // 2) استبدال صور الأفاتار بـ SVG const avatarContainers = document.querySelectorAll('.testimonial__avatar'); const svgIconHTML = ``; avatarContainers.forEach((container) => { container.innerHTML = svgIconHTML; }); // 3) وظيفة إنشاء البولتس باستخدام HTML function createPaginationBullets(swiperContainer, swiper) { const existingPagination = swiperContainer.querySelector('.custom-pagination'); if (existingPagination) { existingPagination.remove(); } const swiperPagination = swiperContainer.querySelector('.swiper-pagination'); if (swiperPagination) { swiperPagination.remove(); } const style = document.createElement('style'); style.innerHTML = `.custom-pagination { position: relative; margin-top: 20px; display: flex; justify-content: center; align-items: center; gap: 8px; } .custom-pagination-bullet { background: #cbd5e1; width: 6px; height: 6px; border-radius: 50%; opacity: 1; transition: all 0.3s ease-in-out; cursor: pointer; } .custom-pagination-bullet-active { background: #000; width: 20px; height: 6px; border-radius: 999px; box-shadow: 0 3px 6px rgba(0,0,0,0.3); }`; document.head.appendChild(style); const slides = swiperContainer.querySelectorAll('.swiper-slide'); const slideCount = slides.length; const paginationContainer = document.createElement('div'); paginationContainer.classList.add('custom-pagination'); for (let i = 0; i < slideCount; i++) { const bullet = document.createElement('div'); bullet.classList.add('custom-pagination-bullet'); if (i === 0) bullet.classList.add('custom-pagination-bullet-active'); bullet.addEventListener('click', function() { document.querySelectorAll('.custom-pagination-bullet').forEach(b => { b.classList.remove('custom-pagination-bullet-active'); }); this.classList.add('custom-pagination-bullet-active'); swiper.slideTo(i); }); paginationContainer.appendChild(bullet); } swiperContainer.appendChild(paginationContainer); return paginationContainer; } // 4) تهيئة Swiper مع البولتس const swiperEl = document.querySelector('.testimonialSwiper'); if (swiperEl) { const isMobile = window.innerWidth <= 768; const swiper = new Swiper('.testimonialSwiper', { centeredSlides: true, slidesPerView: 'auto', loop: true, spaceBetween: 0, allowTouchMove: isMobile, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, autoplay: { delay: 3000, disableOnInteraction: false, }, }); createPaginationBullets(swiperEl, swiper); swiper.on('slideChange', function() { const activeIndex = this.realIndex; document.querySelectorAll('.custom-pagination-bullet').forEach((bullet, index) => { if (index === activeIndex) { bullet.classList.add('custom-pagination-bullet-active'); } else { bullet.classList.remove('custom-pagination-bullet-active'); } }); }); window.addEventListener('resize', function() { const isMobileNow = window.innerWidth <= 768; swiper.params.allowTouchMove = isMobileNow; swiper.update(); }); } }); document.addEventListener("DOMContentLoaded", function() { const tabs = document.querySelectorAll(".tabs .tab-trigger"); tabs.forEach(tab => { if (tab.textContent.trim() === "عنوان الصف الثاني") { const textEl = tab.querySelector(".s-button-text"); if (textEl) textEl.style.display = "none"; tab.style.border = "none"; } }); }); document.addEventListener("DOMContentLoaded", function () { function applySliderFix() { const sliders = document.querySelectorAll(".swiper-wrapper.s-slider-swiper-wrapper:has(.s-products-slider-card)"); sliders.forEach((slider, index) => { if (index < 3) { slider.style.display = "flex"; slider.style.justifyContent = "center"; } }); } applySliderFix(); const observer = new MutationObserver(() => { applySliderFix(); }); observer.observe(document.body, { childList: true, subtree: true }); }); (function(){ const AUTOPLAY_DELAY = 3000; const MAX_TRIES = 60; const TRY_INTERVAL = 200; function enableAutoplayOnSwiper(swiperEl) { if (!swiperEl) return; if (swiperEl.dataset.autoplayApplied === '1') return; let tries = 0; const tryEnable = () => { const swiper = swiperEl.swiper; if (swiper) { try { swiper.params.autoplay = swiper.params.autoplay || {}; swiper.params.autoplay.delay = AUTOPLAY_DELAY; swiper.params.autoplay.disableOnInteraction = false; if (swiper.autoplay && typeof swiper.autoplay.start === 'function') { swiper.autoplay.start(); } swiperEl.dataset.autoplayApplied = '1'; clearInterval(timer); return; } catch (err) { console.error('Error enabling autoplay:', err); } } tries++; if (tries >= MAX_TRIES) clearInterval(timer); }; const timer = setInterval(tryEnable, TRY_INTERVAL); tryEnable(); } function initAllProductSliders() { const sliders = Array.from(document.querySelectorAll(".s-products-slider-wrapper .swiper")); sliders.slice(3).forEach(enableAutoplayOnSwiper); } document.addEventListener('DOMContentLoaded', function () { initAllProductSliders(); const observer = new MutationObserver(mutations => { for (const m of mutations) { m.addedNodes.forEach(node => { if (node.nodeType !== 1) return; if (node.matches && node.matches('.s-products-slider-wrapper .swiper')) { const all = Array.from(document.querySelectorAll(".s-products-slider-wrapper .swiper")); const index = all.indexOf(node); if (index > 2) enableAutoplayOnSwiper(node); } else if (node.querySelectorAll) { node.querySelectorAll('.s-products-slider-wrapper .swiper').forEach(el => { const all = Array.from(document.querySelectorAll(".s-products-slider-wrapper .swiper")); const index = all.indexOf(el); if (index > 2) enableAutoplayOnSwiper(el); }); } }); } }); observer.observe(document.body, { childList: true, subtree: true }); }); })(); document.addEventListener("DOMContentLoaded", function () { function insertImages() { const texts = document.querySelectorAll('.tabs .s-button-text'); texts.forEach(textEl => { if (textEl.textContent.trim() === "مجموعة القمر") { // نتأكد إننا ما ضفناش الصور قبل كده if (document.querySelector(".custom-3-images")) return; const tabsContainer = textEl.closest(".tabs"); if (tabsContainer) { const imagesHTML = ` `; tabsContainer.insertAdjacentHTML("beforebegin", imagesHTML); } } }); } // نراقب التغييرات في الصفحة (عشان لو العناصر اتبنت بعدين) const observer = new MutationObserver(() => { insertImages(); }); observer.observe(document.body, { childList: true, subtree: true }); // كمان ننفذ الكود أول مرة مباشرة insertImages(); });