<div class="delivery-countdown-wrapper" style="display: flex; align-items: flex-start; gap: 10px; font-family: inherit; margin: 15px 0;">
<div class="icon" style="min-width: 20px; color: #555;">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" style="width: 22px; height: 22px;">
<rect x="1" y="3" width="15" height="13"></rect>
<polygon points="16 8 20 8 23 11 23 16 16 16 16 8"></polygon>
<circle cx="5.5" cy="18.5" r="2.5"></circle>
<circle cx="18.5" cy="18.5" r="2.5"></circle>
</svg>
</div>
<div class="text" style="font-size: 15px; line-height: 1.5; color: #333;">
اطلب خلال الساعات والدقائق القادمة لتصلك الشحنة بين تاريخ التسليم الأول وتاريخ التسليم الثاني.
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
// --- إعدادات التخصيص ---
const cutoffHour = 14; // حدد وقت انتهاء الشحن اليومي هنا بصيغة 24 ساعة (على سبيل المثال، 14 = 2:00 مساءً)
const minDeliveryDays = 1; // الحد الأدنى لعدد أيام التوصيل
const maxDeliveryDays = 3; // الحد الأقصى لعدد الأيام اللازمة للتسليم
// ------------------------------
دالة تحديث العد التنازلي() {
const now = new Date();
let target = new Date(now);
target.setHours(cutoffHour, 0, 0, 0);
// إذا تجاوز الوقت الحالي وقت الإغلاق، فأعد ضبط المؤقت لوقت الإغلاق غدًا
إذا كان (الآن > الهدف) {
target.setDate(target.getDate() + 1);
}
const diff = target - now;
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
document.getElementById("cd-hours").textContent = hours;
document.getElementById("cd-Minutes").textContent = Minions;
}
دالة تنسيق التاريخ(التاريخ) {
const days = ["الأحد", "الاثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"];
const months = ["يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"];
const dayName = days[date.getDay()];
const dayOfMonth = date.getDate();
const monthName = months[date.getMonth()];
// أضف لاحقة الترتيب (st, nd, rd, th)
let suffix = "th";
إذا كان (dayOfMonth % 10 === 1 && dayOfMonth !== 11) suffix = "st";
وإلا إذا كان (dayOfMonth % 10 === 2 && dayOfMonth !== 12) فإن اللاحقة = "nd"؛
وإلا إذا كان (dayOfMonth % 10 === 3 && dayOfMonth !== 13) فإن اللاحقة = "rd"؛
إرجاع `${dayName}, ${dayOfMonth}${suffix} ${monthName}`;
}
دالة setDeliveryDates() {
const now = new Date();
// إذا تم تقديم الطلب بعد الموعد النهائي، أضف يومًا إلى تقدير وقت التسليم
إذا كانت الساعة الحالية أكبر من أو تساوي ساعة القطع، {
now.setDate(now.getDate() + 1);
}
const date1 = new Date(now);
date1.setDate(date1.getDate() + minDeliveryDays);
const date2 = new Date(now);
date2.setDate(date2.getDate() + maxDeliveryDays);
document.getElementById("delivery-date-1").textContent = formatDate(date1);
document.getElementById("delivery-date-2").textContent = formatDate(date2);
}
// تهيئة القيم فوراً
تحديث العد التنازلي();
تحديد مواعيد التسليم();
// قم بتحديث مؤقت العد التنازلي كل 60 ثانية
setInterval(updateCountdown, 60000);
});
</script>