/* Add custom JS code below */ document.addEventListener("DOMContentLoaded", () => { const targets = [ "p1867492367", "p1100496482", "p1970649443", "p71367265", "p351640894", ]; if (targets.some((id) => window.location.href.includes(id))) { const observer = new MutationObserver((_, obs) => { const wrapper = document.querySelector(".s-product-options-wrapper"); if (wrapper) { obs.disconnect(); // إضافة الستايل مرة واحدة if (!document.getElementById("ripple-style")) { document.head.insertAdjacentHTML( "beforeend", ` `, ); } // إضافة العنصر wrapper.insertAdjacentHTML( "beforeend", ` أضغط هنا لمعرفة نوع جهازك `, ); } }); observer.observe(document.body, { childList: true, subtree: true }); } }); document.addEventListener("DOMContentLoaded", async () => { const now = new Date(); const hour = now.getHours(), minutes = now.getMinutes(), day = now.getDay(); const excludedRanges = [{ from: "2026-05-25", to: "2026-05-28" }]; // جلب قيمة promotion_title من بيانات الصفحة (تأكد من مصدرها الفعلي لديك) const promotionTitle = window.product?.promotion_title || ""; // التحقق إذا لم يكن Free shipping لكي يكمل الحسابات الطبيعية const isOutOfStockSoon = (promotionTitle === "Free shipping"); let city = localStorage.getItem("user_city"); if (!city) { try { const res = await fetch("https://ipwho.is/"); const data = await res.json(); city = data.city || "Other"; localStorage.setItem("user_city", city); } catch (e) { city = "Other"; } } // 2. حساب أيام التوصيل (تعمل فقط إذا لم يكن المنتج Free shipping لتوفير الأداء) let deliveryDays = /Riyadh|Cairo/i.test(city) ? 0 : 2; if (hour >= 11) deliveryDays += 1; if (day === 4 && hour >= 11 && /Riyadh/i.test(city)) deliveryDays += 1; if (day === 5) deliveryDays += 1; let deliveryDate = new Date(); const isExcluded = (date) => { const fmt = date.toISOString().split("T")[0]; return excludedRanges.some((r) => fmt >= r.from && fmt <= r.to); }; while (isExcluded(deliveryDate)) { deliveryDate.setDate(deliveryDate.getDate() + 1); } deliveryDate.setDate(deliveryDate.getDate() + deliveryDays); while (isExcluded(deliveryDate)) { deliveryDate.setDate(deliveryDate.getDate() + 1); } // 3. التاريخ والوقت const isToday = now.toDateString() === deliveryDate.toDateString(); const isTomorrow = new Date(now.getTime() + 86400000).toDateString() === deliveryDate.toDateString(); const dayDiff = Math.floor((deliveryDate - now) / 86400000); const weekdaysArabic = [ "الأحد", "الاثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت", ]; const monthsArabic = [ "يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر", ]; const deliveryText = isToday ? "اليوم" : isTomorrow ? "غدًا" : dayDiff <= 6 ? weekdaysArabic[deliveryDate.getDay()] : `${weekdaysArabic[deliveryDate.getDay()]} ${deliveryDate.getDate()} ${monthsArabic[deliveryDate.getMonth()]}`; const remainingHours = hour < 11 ? 10 - hour : 24 - hour + 10; const remainingMinutes = 59 - minutes; const countdownText = remainingHours > 0 && remainingMinutes > 0 ? `عند الطلب في غضون ${remainingHours} ساعة ${remainingMinutes} دقيقة` : remainingHours > 0 ? `عند الطلب في غضون ${remainingHours} ساعة` : remainingMinutes > 0 ? `عند الطلب في غضون ${remainingMinutes} دقيقة` : ""; // تحديد النصوص والألوان بناءً على حالة الـ promotion_title const displayMainText = isOutOfStockSoon ? "يتوفر قريباً" : `يوصلك ${deliveryText}`; const backgroundStyle = isOutOfStockSoon ? "background: linear-gradient(45deg, #ff000010, #ff4d4d40); border: 1px solid #ff4d4d;" : "background: linear-gradient(45deg, #edae6b00, #cb75e859);"; // 4. وظيفة الحقن (UI) const createUI = (selector, isCart = false) => { const target = document.querySelector(selector); if (!target) return; const html = `
`;
// تحديد مكان الأيقونة بدقة (الارتفاع 10% واليسار 10px)
iconDiv.style.position = "absolute";
iconDiv.style.bottom = "10%";
iconDiv.style.left = "10px";
iconDiv.style.zIndex = "10";
iconDiv.style.cursor = "pointer";
// 4. حقن الأيقونة داخل مربع الصورة
imageContainer.appendChild(iconDiv);
}
}
});
}
// تشغيل الفحص فوراً ومراقبته ديناميكياً مع السلايدر والتحميل المتأخر
addColorsIcon();
const observer = new MutationObserver(() => {
addColorsIcon();
});
observer.observe(document.body, { childList: true, subtree: true });
})();