// كود إرسال السلة للواتساب - نظيف ومحسّن (function() { const cartBottomActions = document.querySelector('.cart-bottom-actions'); if (!cartBottomActions) { return; } // إضافة فورم اختيار الشحن const shippingFormHTML = `
خيارات الشحن
`; cartBottomActions.insertAdjacentHTML('beforebegin', shippingFormHTML); // تفعيل تأثيرات CSS const labels = document.querySelectorAll('.shipping-options label'); labels.forEach(label => { label.addEventListener('click', function() { labels.forEach(l => { l.style.borderColor = '#e0e0e0'; l.style.backgroundColor = 'white'; }); this.style.borderColor = '#4CAF50'; this.style.backgroundColor = '#f0f8f0'; document.getElementById('shipping-error').style.display = 'none'; }); }); // تعديل وظيفة زر اتمام الطلب const checkoutButton = document.querySelector('salla-button[onclick*="salla.cart.submit"]'); if (!checkoutButton) { return; } // إخفاء الزر القديم checkoutButton.style.display = 'none'; // إنشاء زر جديد بالكامل const newButton = document.createElement('button'); newButton.className = 'btn--oval btn--md'; newButton.style.cssText = 'width: 100%; padding: 15px; font-size: 16px; background: #25D366; color: white; border: none; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-weight: 500;'; newButton.innerHTML = ` إتمام الطلب حالاً عبر الواتساب `; // إضافة الزر الجديد بعد القديم checkoutButton.parentElement.appendChild(newButton); newButton.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); const selectedShipping = document.querySelector('input[name="shipping"]:checked'); if (!selectedShipping) { document.getElementById('shipping-error').style.display = 'block'; document.querySelector('.shipping-options').scrollIntoView({ behavior: 'smooth', block: 'center' }); return; } const whatsappNumber = '966503210622'; const shippingType = selectedShipping.value; const shippingCost = shippingType === 'riyadh' ? 40 : 0; let message = 'فاتورة طلب جديد\n'; message += '━━━━━━━━━━━━━━━━━━━━\n\n'; const cartItems = document.querySelectorAll('.cart-product-entry'); if (cartItems.length === 0) { alert('السلة فاضية!'); return; } message += 'المنتجات:\n\n'; cartItems.forEach((item, index) => { const productName = item.querySelector('.title--small')?.textContent.trim(); const priceElement = item.querySelector('.cart-item-price'); // استخراج الأرقام فقط من السعر const priceText = priceElement ? priceElement.textContent.trim() : ''; const priceNumbers = priceText.replace(/[^\d٠-٩]/g, ''); const price = priceNumbers ? priceNumbers + ' ر.س' : ''; const quantity = item.querySelector('input[name="quantity"]')?.value; if (productName) { message += `${index + 1}. ${productName}\n`; message += ` الكمية: ${quantity}\n`; message += ` السعر: ${price}\n`; const productOptions = item.querySelectorAll('.s-product-options-option select'); if (productOptions.length > 0) { productOptions.forEach(select => { const optionLabel = select.closest('.s-product-options-option')?.querySelector('.s-product-options-option-label b')?.textContent.trim().replace('*', ''); const selectedOption = select.options[select.selectedIndex]?.text; if (optionLabel && selectedOption && selectedOption !== 'اختر') { message += ` ${optionLabel}: ${selectedOption}\n`; } }); } message += `\n`; } }); message += '━━━━━━━━━━━━━━━━━━━━\n\n'; message += '*طريقة الشحن:*\n'; if (shippingType === 'riyadh') { message += 'الشحن داخل الرياض\n\n'; } else { message += 'الشحن خارج الرياض\n\n'; } message += '━━━━━━━━━━━━━━━━━━━━\n\n'; const itemsCount = document.getElementById('cart-items-count')?.textContent.trim(); const subTotalElement = document.getElementById('cart-sub-total'); // استخراج الأرقام فقط من الإجمالي const subTotalRaw = subTotalElement ? subTotalElement.textContent.trim() : ''; const subTotalNumbers = subTotalRaw.replace(/[^\d٠-٩]/g, ''); const subTotalText = subTotalNumbers ? subTotalNumbers + ' ر.س' : ''; const subTotalMatch = subTotalText.match(/[\d٠-٩]+/g); let subTotal = 0; if (subTotalMatch) { const arabicToEnglish = str => str.replace(/[٠-٩]/g, d => '٠١٢٣٤٥٦٧٨٩'.indexOf(d)); subTotal = parseInt(arabicToEnglish(subTotalMatch.join(''))); } const finalTotal = subTotal + shippingCost; message += '*ملخص الفاتورة:*\n\n'; message += `عدد الأصناف: ${itemsCount}\n`; message += `مجموع المنتجات: ${subTotalText}\n`; if (shippingType === 'riyadh') { message += `تكلفة الشحن: ٤٠ ر.س\n\n`; message += `*الإجمالي النهائي: ${finalTotal} ر.س*\n\n`; } else { message += `\n*الإجمالي النهائي: ${subTotal} ر.س* + *تكلفة الشحن*\n\n`; } message += '━━━━━━━━━━━━━━━━━━━━\n\n'; message += '*الطلب جاهز للتأكيد*'; const encodedMessage = encodeURIComponent(message); const whatsappURL = `https://api.whatsapp.com/send?phone=${whatsappNumber}&text=${encodedMessage}`; window.open(whatsappURL, '_blank'); }); })(); /*********** document.addEventListener('DOMContentLoaded', function() { // التصنيفات المستهدفة const targetCategories = [ 'الاعلاف', 'اعلاف-غزلان', 'الحمام', 'اعلاف-الخيل', 'الأبل', 'خلطات-ومشكلات', 'الحبوب-الرفيعه', 'الاغنام-والحملان', 'الدجاج' ]; const categoryIds = [ '821387019', // الأعلاف '1977719926', // أعلاف غزلان '2120912229', // الحمام '404454773', // أعلاف الخيل '154301805', // الأبل '1062557292', // خلطات ومشكلات '329459810', // الحبوب الرفيعة '1103497569', // الأغنام والحملان '438094695' // الدجاج ]; // دالة للتحقق من التصنيف function isInTargetCategory() { const currentURL = window.location.href; const currentPath = window.location.pathname; // التحقق من صفحات التصنيفات const isInCategoryPage = targetCategories.some(cat => currentPath.includes(cat)) || categoryIds.some(id => currentURL.includes(`/c${id}`)); if (isInCategoryPage) return true; // التحقق من breadcrumbs في صفحات المنتجات const breadcrumbs = document.querySelectorAll('.breadcrumb a, nav[aria-label="breadcrumb"] a'); let isInTargetViaBreads = false; breadcrumbs.forEach(crumb => { const crumbText = crumb.textContent.trim(); const crumbHref = crumb.href || ''; if (targetCategories.some(cat => crumbText.includes(cat)) || categoryIds.some(id => crumbHref.includes(`/c${id}`))) { isInTargetViaBreads = true; } }); return isInTargetViaBreads; } // دالة لتعديل الأزرار المحددة فقط function modifyButtons() { if (!isInTargetCategory()) { console.log('Not in target category'); return; } console.log('In target category, modifying specific buttons'); // 1. تعديل أيقونات السلة الصغيرة في قائمة المنتجات (shopping bag icon) const iconButtons = document.querySelectorAll('.btn--add-to-cart .sicon-shopping-bag'); iconButtons.forEach(icon => { const button = icon.closest('button'); if (!button || button.hasAttribute('data-whatsapp-modified')) { return; } button.setAttribute('data-whatsapp-modified', 'true'); // استبدال الأيقونة بأيقونة WhatsApp مباشرة icon.className = 'fab fa-whatsapp'; icon.style.fontSize = '20px'; // حجم مناسب للأيقونة // جمع معلومات المنتج const productBlock = button.closest('.product-block'); let productTitle = ''; // البحث عن اسم المنتج في الهيكل المحدد if (productBlock) { const titleEl = productBlock.querySelector('.product-title h2'); if (titleEl) { productTitle = titleEl.textContent.trim(); } else { // محاولة البحث في هيكل آخر const productLink = productBlock.querySelector('.product-title'); if (productLink) { productTitle = productLink.textContent.trim(); } } } // استبدال الزر لإزالة الأحداث القديمة const newButton = button.cloneNode(true); button.parentNode.replaceChild(newButton, button); // إضافة حدث WhatsApp newButton.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); // رابط واتساب مع رسالة const whatsappMessage = encodeURIComponent(`السلام عليكم، أبغي استفسر عن منتج ${productTitle}`); const whatsappUrl = `https://wa.me/966503210622?text=${whatsappMessage}`; window.open(whatsappUrl, '_blank'); }); }); // 2. تعديل أزرار "إضافة للسلة" الكبيرة في صفحات المنتجات const mainAddButtons = document.querySelectorAll( '.s-add-product-button-main .s-button-text:not([data-whatsapp-modified])' ); mainAddButtons.forEach(buttonText => { // التأكد من أن النص يحتوي على "إضافة للسلة" if (!buttonText.textContent.includes('إضافة للسلة') && !buttonText.textContent.includes('أضف للسلة') && !buttonText.textContent.includes('اطلب عن طريق الواتساب')) { return; } const button = buttonText.closest('button'); if (!button || button.hasAttribute('data-whatsapp-modified')) { return; } button.setAttribute('data-whatsapp-modified', 'true'); buttonText.setAttribute('data-whatsapp-modified', 'true'); // تغيير النص buttonText.textContent = 'اطلب عن طريق الواتساب'; // جمع معلومات المنتج - البحث عن عنوان المنتج let productTitle = ''; const productTitleEl = document.querySelector('.product-details__title .title'); if (productTitleEl) { productTitle = productTitleEl.textContent.trim(); } else { // محاولة الحصول على العنوان من عناصر أخرى const altTitleEl = document.querySelector('.product-single__title, .product__title, h1'); if (altTitleEl) { productTitle = altTitleEl.textContent.trim(); } } // استبدال الزر const newButton = button.cloneNode(true); button.parentNode.replaceChild(newButton, button); // إضافة حدث WhatsApp newButton.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); // رابط واتساب مع رسالة const whatsappMessage = encodeURIComponent(`السلام عليكم، أبغي استفسر عن منتج ${productTitle}`); const whatsappUrl = `https://wa.me/966503210622?text=${whatsappMessage}`; window.open(whatsappUrl, '_blank'); }); }); console.log(`Modified ${iconButtons.length} icon buttons and ${mainAddButtons.length} main buttons`); } // إضافة Font Awesome إذا لم يكن موجود if (!document.querySelector('link[href*="font-awesome"]')) { const faLink = document.createElement('link'); faLink.rel = 'stylesheet'; faLink.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css'; document.head.appendChild(faLink); } // أنماط بسيطة للأيقونة فقط const style = document.createElement('style'); style.textContent = ` .fab.fa-whatsapp { color: inherit !important; line-height: 1 !important; display: inline-block !important; } `; document.head.appendChild(style); // التنفيذ console.log('WhatsApp modifier script starting...'); // تنفيذ متكرر modifyButtons(); setTimeout(modifyButtons, 500); setTimeout(modifyButtons, 1000); setTimeout(modifyButtons, 2000); // مراقبة التغييرات let debounceTimer; const observer = new MutationObserver(() => { clearTimeout(debounceTimer); debounceTimer = setTimeout(modifyButtons, 300); }); observer.observe(document.body, { childList: true, subtree: true }); // مراقبة تغيير الصفحات let lastUrl = location.href; new MutationObserver(() => { const url = location.href; if (url !== lastUrl) { lastUrl = url; setTimeout(modifyButtons, 100); } }).observe(document, {subtree: true, childList: true}); }); // تشغيل إضافي عند تحميل الصفحة بالكامل window.addEventListener('load', function() { setTimeout(() => { document.dispatchEvent(new Event('DOMContentLoaded')); }, 500); }); ****/