document.addEventListener("DOMContentLoaded", function () { const totalEl = document.querySelector('.s-cart-summary-total'); if (!totalEl) { console.log('لم يتم العثور على المجموع الكلي.'); return; // إذا لم يوجد العنصر، لا تفعل شيء } // دالة لفحص المجموع الكلي وعرض التنبيه عند توافر الشروط function checkTotalValue() { const totalValue = parseFloat(totalEl.textContent.replace(/[^\d.]/g, '')); if (isNaN(totalValue) || totalValue < 300) { return false; // إذا كانت القيمة أقل من 300، لا يظهر التنبيه } return true; // إذا كانت القيمة أكبر من أو تساوي 300، يظهر التنبيه } // إنشاء التنبيه المنبثق const alertSection = document.createElement('div'); alertSection.id = 'alert_section'; const hideAlertAdvertising = document.createElement('div'); hideAlertAdvertising.id = 'hideAlertAdvertising'; hideAlertAdvertising.style = 'position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); z-index: 9998;'; const alertWrapper = document.createElement('div'); alertWrapper.id = 'alert_wrapper'; alertWrapper.style = ` text-align: center; width: 50%; max-width: 500px; margin: 0 auto; background-color: #ffffff; border-radius: 16px; padding: 1.5rem; z-index: 99999; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.7); opacity: 0; transition: transform 0.5s ease, opacity 0.5s ease; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); `; const alertCloseIcon = document.createElement('div'); alertCloseIcon.id = 'alert_close_icon'; alertCloseIcon.style = 'position: absolute; top: 10px; left: 10px; cursor: pointer;'; const closeButton = document.createElement('button'); closeButton.innerHTML = ` cancel `; alertCloseIcon.appendChild(closeButton); const alertMainTitle = document.createElement('div'); alertMainTitle.id = 'alert_main_title'; const mainTitle = document.createElement('h2'); mainTitle.textContent = 'هديتك'; mainTitle.style = 'margin-bottom: 10px;'; alertMainTitle.appendChild(mainTitle); const alertTitle = document.createElement('div'); alertTitle.id = 'alert_title'; const title = document.createElement('p'); title.textContent = 'مبروك عليك عضوية المساعدة على الطريق والشحن المجاني'; title.style = 'font-size: 1.2rem;'; alertTitle.appendChild(title); alertWrapper.appendChild(alertCloseIcon); alertWrapper.appendChild(alertMainTitle); alertWrapper.appendChild(alertTitle); alertSection.appendChild(hideAlertAdvertising); alertSection.appendChild(alertWrapper); document.body.appendChild(alertSection); // إظهار التنبيه function showAlert() { setTimeout(function() { alertSection.style.display = 'flex'; }, 200); alertWrapper.style.transform = 'translate(-50%, -50%) scale(1)'; alertWrapper.style.opacity = '1'; } // إغلاق التنبيه function closeAlert() { alertWrapper.style.transform = 'translate(-50%, -50%) scale(0.7)'; alertWrapper.style.opacity = '0'; setTimeout(function () { alertSection.style.display = 'none'; }, 500); } alertCloseIcon.addEventListener('click', closeAlert); hideAlertAdvertising.addEventListener('click', closeAlert); // عرض التنبيه مباشرة إذا تم التحقق من الشرط function handleDisplayAlert() { if (checkTotalValue()) { showAlert(); } } // في حال كان المحتوى الحالي يفي بالشرط عند تحميل الصفحة handleDisplayAlert(); // إضافة تنسيق مخصص const style = document.createElement('style'); style.innerHTML = ` #hideAlertAdvertising { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); z-index: 9998; } @media (min-width: 768px) { #alert_section { width: 400px; height: auto; } } @media (max-width: 768px) { #alert_section { width: 90%; height: auto; } } #alert_main_title { color: #cec2ba; } #alert_title { color: #8B0000; } /* تنسيق خاص للزر داخل هذه النافذة فقط */ #alert_section #alert_close_icon button { left: 1%; top: 6%; } @media (max-width: 767px) { #alert_wrapper { width: 85% !important; } } `; document.head.appendChild(style); });