/*****كود خصم 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 = `