/*****كود خصم 25%***/ (function () { function injectPromoCard() { // 1. التأكد من عدم تكرار إضافة الكارت if (document.getElementById("custom-salla-promo-card")) return; // 2. البحث عن عناصر سلة المضمونة في صفحة المنتج const targetAnchor = document.querySelector('.product-form') || document.querySelector('.product-single__policy') || document.querySelector('salla-add-product-button') || document.querySelector('.salla-product-options') || document.querySelector('[class*="tabby"]'); if (targetAnchor) { const card = document.createElement("div"); card.id = "custom-salla-promo-card"; card.setAttribute("dir", "rtl"); card.innerHTML = `
%25 على القطعة الثانية

أضيفي قطعة ثانية ووّفري أكثر

يشمل جميع منتجات المتجر باستخدام كوبون سارة
`; // إدراج الكارت قبل زر الشراء/خيارات المنتج targetAnchor.parentNode.insertBefore(card, targetAnchor); } } // تشغيل المحاولة فوراً وعند اكتمال التحميل injectPromoCard(); window.addEventListener('load', injectPromoCard); // متابعة أي تغيرات في الصفحة (عشان التصفح السريع في سلة SPA) const observer = new MutationObserver(injectPromoCard); observer.observe(document.body, { childList: true, subtree: true }); })(); // 1. تصفير الحواف (Padding) لشرائح السلايدر document.addEventListener("DOMContentLoaded", function () { function zeroSwiperPadding() { const wrappers = document.querySelectorAll("salla-products-slider .swiper-wrapper, .swiper-wrapper"); wrappers.forEach(function (wrapper) { wrapper.style.setProperty("padding", "0px", "important"); }); } zeroSwiperPadding(); setTimeout(zeroSwiperPadding, 500); setTimeout(zeroSwiperPadding, 1200); }); // 2. إظهار إشعار الشحن الفوري عند اختيار المقاس document.addEventListener("change", function (event) { const target = event.target; if (target && target.matches('.s-product-options-option-container input[type="radio"]')) { const container = target.closest('.s-product-options-option-container') || target.closest('.s-product-options-option'); if (container) { let msg = container.querySelector(".fast-shipping-notice"); if (!msg) { msg = document.createElement("div"); msg.className = "fast-shipping-notice"; msg.style.cssText = ` margin-top: 12px; padding: 10px 14px; background-color: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; border-radius: 8px; font-size: 14px; font-weight: bold; text-align: right; display: block; `; msg.innerHTML = "شحن فوري يصل لباب بيتك خلال 1 الى 7 ايام"; container.appendChild(msg); } else { msg.style.display = "block"; } } } }); // 3. ضبط الهوامش للشاشات الكبيرة (Desktop) document.addEventListener("DOMContentLoaded", function () { const customStyle = document.createElement("style"); customStyle.innerHTML = ` @media (min-width: 1024px) { salla-products-slider, .s-slider-block, .s-block, .s-products-list { margin-left: 0 !important; } } `; document.head.appendChild(customStyle); }); // 4. تطبيق الحواف الدائرية (Border Radius) للأزرار على الجوال document.addEventListener("DOMContentLoaded", function () { function applyMobileRadius() { const isMobile = window.innerWidth <= 768; // زر الشراء السريع داخل Shadow DOM const widgets = document.querySelectorAll("salla-mini-checkout-widget"); widgets.forEach(widget => { if (widget.shadowRoot) { const fastBtn = widget.shadowRoot.querySelector(".s-fast-checkout-button"); if (fastBtn) { if (isMobile) { fastBtn.style.setProperty("border-radius", "8px", "important"); } else { fastBtn.style.removeProperty("border-radius"); } } } }); // زر إضافة للسلة const addCartButtons = document.querySelectorAll("salla-button, .s-button-element"); addCartButtons.forEach(btn => { if (isMobile) { btn.style.setProperty("border-radius", "8px", "important"); } else { btn.style.removeProperty("border-radius"); } if (btn.shadowRoot) { const innerBtn = btn.shadowRoot.querySelector(".s-button-element, button"); if (innerBtn) { if (isMobile) { innerBtn.style.setProperty("border-radius", "8px", "important"); } else { innerBtn.style.removeProperty("border-radius"); } } } }); } applyMobileRadius(); window.addEventListener("resize", applyMobileRadius); setTimeout(applyMobileRadius, 500); setTimeout(applyMobileRadius, 1200); }); // 5. تحويل ضغط البانر إلى أيقونة المستخدم document.addEventListener("DOMContentLoaded", function () { const btn = document.querySelector(".abayat-banner-with-text-btn"); const targetBtn = document.querySelector('button[aria-label="user-icon"]'); if (btn && targetBtn) { btn.removeAttribute("href"); btn.addEventListener("click", function (e) { e.preventDefault(); targetBtn.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, view: window })); }); } }); // 6. قسم مدة التوصيل وتحديد المدينة document.addEventListener("DOMContentLoaded", function () { // 1. الشرط الأساسي: تأكد أولاً أننا في صفحة المنتج فقط // (يمكن التأكد من رابط الصفحة أو من وجود حاوي صفحة المنتج الرئيسية) const isProductPage = document.body.classList.contains('product-single') || document.querySelector('.product-single') || window.location.pathname.includes('/products/'); if (!isProductPage) { return; // الخروج فوراً إن لم نكن في صفحة المنتج } // 2. البحث عن العناصر داخل نطاق صفحة المنتج فقط وليس كامل المستند const productContainer = document.querySelector('.product-single') || document.body; const taxText = productContainer.querySelector('.color-grey'); const priceBox = productContainer.querySelector('.abayat-price'); // إعادة ترتيب السعر if (taxText && priceBox && taxText.textContent.includes("السعر شامل الضريبة")) { taxText.parentNode.insertBefore(priceBox, taxText); } // تحديد العنصر المستهدف فقط داخل صفحة المنتج let targetForDelivery = null; if (taxText && taxText.textContent.includes("السعر شامل الضريبة")) { targetForDelivery = taxText; } else { targetForDelivery = priceBox || productContainer.querySelector(".product-price"); } // 3. حقن صندوق التوصيل if (targetForDelivery && !document.querySelector("#fixed-delivery-box")) { const deliveryHTML = `
التوصيل خلال يومين عمل في جدة
تحديد المدينة
`; targetForDelivery.insertAdjacentHTML("afterend", deliveryHTML); const citySelect = document.getElementById("modern-city-select"); const cityText = document.getElementById("city-pill-text"); const daysText = document.getElementById("delivery-days-pill"); if (citySelect) { citySelect.addEventListener("change", function () { const city = this.value; cityText.textContent = city; daysText.textContent = (city === "جدة") ? "يومين عمل" : "من 4 الى 7 ايام عمل"; }); } } }); // 7. دليل القياسات وقسم رقم الموديل function waitForElement(selector, callback) { const found = document.querySelector(selector); if (found) return callback(found); const observer = new MutationObserver(() => { const el = document.querySelector(selector); if (el) { observer.disconnect(); callback(el); } }); observer.observe(document.body, { childList: true, subtree: true }); } waitForElement(".product-single .s-product-options-option-container:last-of-type", (target) => { if (document.querySelector(".custom-size-guide")) return; // 1. إنشاء قسم دليل القياسات const sizeGuideSection = document.createElement("section"); sizeGuideSection.className = "custom-size-guide s-product-options-option-container bg-white p-5 rounded-md mb-5"; sizeGuideSection.innerHTML = `
دليل القياسات عرض دليل القياسات
`; // 2. إدراج قسم دليل القياسات بعد العنصر المستهدف target.after(sizeGuideSection); // 3. البحث عن قسم رقم الموديل ونقله ليكون فوق دليل القياسات مباشرة waitForElement('.sicon-barcode', (iconEl) => { // الوصول للـ div الأب المباشر لقسم رقم الموديل const modelSection = iconEl.closest('.mb-4.flex'); if (modelSection && sizeGuideSection.parentNode) { // إعادة ترتيب العناصر: نقل قسم الموديل ليصبح قبل قسم المقاسات sizeGuideSection.parentNode.insertBefore(modelSection, sizeGuideSection); } }); }); // 8. التبويبات المخصصة للمنتج والتقييمات document.addEventListener("DOMContentLoaded", function () { const productDescriptionEl = document.querySelector(".product__description"); const productReviews = document.querySelector(".s-before-reviews"); const reviewsWrapper = document.querySelector(".s-blocks-wrapper.s-before-reviews"); if (!productDescriptionEl || !productReviews || !reviewsWrapper) return; const productContent = productDescriptionEl.innerHTML; const productReviewsContent = productReviews.innerHTML; const newSection = document.createElement("section"); newSection.className = "product-details-section"; newSection.innerHTML = `
تفاصيل المنتج
${productContent}
تقييمات المنتج

${productReviewsContent}

`; reviewsWrapper.parentNode.insertBefore(newSection, reviewsWrapper); }); // 9. إضافة صورة الطقطق الياباني تلقائياً عند وجود النص /*(function () { const SEARCH_TEXT = "اضافة طقطق ياباني"; const IMG_URL = "https://aldhafiri-law.sa/wp-content/uploads/2026/07/105daccc-00d3-4f7d-b41e-9349a0362f9d-500x500-tZe4jQGyZFAVBxZ60WmZRucF2ZuROhT0H4yYDGUl.webp"; function findTargetElement() { const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); let node; while ((node = walker.nextNode())) { if (node.textContent && node.textContent.includes(SEARCH_TEXT)) { return node.parentElement; } } return null; } function injectImage() { const target = findTargetElement(); if (!target || target.querySelector(".custom-japanese-img")) return; const img = document.createElement("img"); img.src = IMG_URL; img.alt = SEARCH_TEXT; img.classList.add("custom-japanese-img"); img.style.maxWidth = "100%"; img.style.display = "block"; img.style.marginBottom = "10px"; target.prepend(img); } injectImage(); new MutationObserver(injectImage).observe(document.body, { childList: true, subtree: true }); })(); */ // 10. تعديل كلاسات شرائح السلايدر document.addEventListener("DOMContentLoaded", function () { document.querySelectorAll('.abayat-slider-simple .swiper-slide').forEach(slide => { slide.classList.remove('w-full', 'h-full'); }); }); // 11. أحداث التبويبات والأكورديون document.addEventListener("click", function (e) { const tabBtn = e.target.closest(".tab-btn"); if (tabBtn) { document.querySelectorAll(".tab-btn").forEach(b => b.classList.remove("active")); tabBtn.classList.add("active"); const targetId = tabBtn.dataset.tab; document.querySelectorAll(".accordion-item").forEach(item => { item.classList.remove("active"); if (item.querySelector(".accordion-content")?.id === targetId) { item.classList.add("active"); } }); } const accTitle = e.target.closest(".accordion-title"); if (accTitle) { accTitle.parentElement.classList.toggle("active"); } }); // 12. الملاحظ المحّد المزود بـ Debounce للعناصر الديناميكية في الفوتر والأسهم والعناوين function handleDynamicUI() { // إضافات العناوين document.querySelectorAll("salla-products-slider .s-slider-block__title-right h2").forEach((heading) => { if (!heading.nextElementSibling?.classList.contains("enhanced-title-border")) { heading.insertAdjacentHTML("afterend", ''); } }); // أسهم الرابط document.querySelectorAll("a.s-slider-block__display-all").forEach((link) => { if (!link.querySelector(".sicon-keyboard_arrow_left")) { const icon = document.createElement("i"); icon.className = "sicon-keyboard_arrow_left text-xl rtl:group-hover:-translate-x-2 ltr:group-hover:translate-x-2 transition-transform duration-300"; link.appendChild(icon); } }); // زر الواتساب العائم const footer = document.querySelector(".store-footer__inner.abayat-store-footer__inner"); if (footer && !document.querySelector(".floating-whatsapp")) { const whatsapp = document.createElement("a"); whatsapp.href = "https://wa.me/966534345688"; whatsapp.target = "_blank"; whatsapp.rel = "noopener"; whatsapp.className = "floating-whatsapp"; whatsapp.setAttribute("aria-label", "WhatsApp"); whatsapp.innerHTML = ``; footer.parentNode.insertBefore(whatsapp, footer); } // أيقونات التواصل الاجتماعي في الفوتر const socialTarget = document.querySelector(".abayat-copyright > div"); if (socialTarget && !socialTarget.querySelector(".s-social-list")) { const wrapper = document.createElement("div"); wrapper.innerHTML = ` `; socialTarget.appendChild(wrapper.firstElementChild); } } handleDynamicUI(); new MutationObserver(handleDynamicUI).observe(document.body, { childList: true, subtree: true }); // 13. شعار الفوتر document.addEventListener("DOMContentLoaded", function () { const link = document.querySelector(".store-footer__inner .container > div:first-of-type a"); if (link && !link.querySelector("img[alt='Sura. logo']")) { link.insertAdjacentHTML("beforeend", ` Sura. logo `); } }); // 14. زر المشاركة document.addEventListener("click", function(e) { const shareBtn = e.target.closest("[class*='share']"); if (!shareBtn) return; setTimeout(() => { let url = decodeURIComponent(window.location.href); if (navigator.share) { navigator.share({ title: document.title, text: document.title + "\n" + url, url: url }).catch(() => {}); } }, 300); }); // 15. روابط التواصل المعززة (تم إصلاح حلقة التأخير وإيقاف المؤقت بشكل صحيح) document.addEventListener("DOMContentLoaded", function () { const html = `
واتساب الهاتف البريد الإلكتروني
`; let contactInterval; function addContacts() { const target = document.querySelector(".s-contacts.hydrated"); if (target && !target.querySelector(".enhanced_rounded_contacts")) { target.insertAdjacentHTML("beforeend", html); if (contactInterval) clearInterval(contactInterval); } } contactInterval = setInterval(addContacts, 500); addContacts(); }); // 16. تعديل تصميم أداة تمارا (Tamara Widget) داخل Shadow DOM const tamaraObserver = new MutationObserver(() => { const widget = document.querySelector("tamara-widget"); if (!widget?.shadowRoot) return; const shadow = widget.shadowRoot; const wrapper = shadow.querySelector(".content-wrapper"); const logo = shadow.querySelector(".tamara-inline-badge"); if (wrapper && logo && wrapper.firstElementChild !== logo) { wrapper.insertBefore(logo, wrapper.firstChild); logo.style.marginRight = "12px"; logo.style.marginLeft = "0"; } }); tamaraObserver.observe(document.body, { childList: true, subtree: true });