/* Add custom Js styles below */ document.addEventListener("DOMContentLoaded", function() { if (window.location.pathname !== '/') { return; } const customStyles = ` `; const YOUR_PRODUCT_ID = "2047803630"; const donationHTML = ` ${customStyles}

تبرع سريع

مبلغ المساهمة
ر.س
`; const oldBtn = document.getElementById('quick-donation__trigger'); const oldModal = document.getElementById('quick-donation'); if(oldBtn) oldBtn.remove(); if(oldModal) oldModal.remove(); const appBody = document.getElementById('app') || document.body; appBody.insertAdjacentHTML('afterbegin', donationHTML); const triggerBtn = document.getElementById('quick-donation__trigger'); const modalDiv = document.getElementById('quick-donation'); const closeBtn = document.getElementById('close-donation-modal'); const submitBtn = document.getElementById('quick-donation__submit'); const amountField = document.getElementById('donation-amount-field'); const presetRadios = document.querySelectorAll('input[name="predefiend-amountes"]'); const errorMsg = document.getElementById('donation-error'); const prodIdInput = document.getElementById('donation-product-id'); const openMenu = () => { modalDiv.classList.add('is-open'); triggerBtn.style.right = '-60px'; }; const closeMenu = () => { modalDiv.classList.remove('is-open'); triggerBtn.style.right = '0'; }; if(triggerBtn && modalDiv) { triggerBtn.addEventListener('click', (e) => { e.preventDefault(); openMenu(); }); if(closeBtn) { closeBtn.addEventListener('click', (e) => { e.preventDefault(); closeMenu(); }); } modalDiv.addEventListener('click', (e) => { if (e.target === modalDiv) closeMenu(); }); } presetRadios.forEach(radio => { radio.addEventListener('change', function() { if(this.checked) amountField.value = this.value; }); }); if(submitBtn) { submitBtn.addEventListener('click', function() { errorMsg.style.display = 'none'; const productId = prodIdInput.value; const amount = amountField.value; if(!amount || amount <= 0) { errorMsg.innerText = 'يرجى تحديد مبلغ التبرع'; errorMsg.style.display = 'block'; return; } const btnText = submitBtn.querySelector('.btn-text'); const btnLoader = submitBtn.querySelector('.btn-loader'); if(btnText) btnText.style.display = 'none'; if(btnLoader) btnLoader.style.display = 'inline-block'; submitBtn.setAttribute('disabled', 'true'); submitBtn.style.opacity = '0.7'; const itemData = { id: productId, quantity: 1, donation_amount: parseFloat(amount) }; try { salla.cart.api.addItem(itemData) .then((response) => { window.location.href = 'https://salla.sa/kahatain.org/cart'; }) .catch((err) => { console.error('Error:', err); if(btnText) btnText.style.display = 'inline-block'; if(btnLoader) btnLoader.style.display = 'none'; submitBtn.removeAttribute('disabled'); submitBtn.style.opacity = '1'; let serverMsg = 'حدث خطأ غير متوقع'; if(err.response && err.response.data && err.response.data.error && err.response.data.error.message){ serverMsg = err.response.data.error.message; } else if (err.message) { serverMsg = err.message; } errorMsg.innerText = serverMsg; errorMsg.style.display = 'block'; }); } catch (e) { console.log('Salla API Error:', e); alert("حدث خطأ في الاتصال بسلة. تأكد أن مكتبة سلة محملة."); } }); } }); document.addEventListener("DOMContentLoaded", function() { function formatMoneyNumbers() { const targets = document.querySelectorAll('.s-progress-bar-target-section span'); targets.forEach(span => { if (span.getAttribute('data-formatted') === 'true') return; let originalText = span.textContent; let formattedText = originalText.replace(/\d+/g, function(num) { return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "،"); }); span.textContent = formattedText; span.setAttribute('data-formatted', 'true'); }); } formatMoneyNumbers(); const observer = new MutationObserver(function(mutations) { formatMoneyNumbers(); }); observer.observe(document.body, { childList: true, subtree: true }); }); document.addEventListener("DOMContentLoaded", function() { function formatInjazCounters() { const counters = document.querySelectorAll('.injaz_count'); const counterObserver = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { let target = mutation.target; if (target.nodeType === 3) { target = target.parentNode; } if (target.classList.contains('injaz_count')) { let originalText = target.textContent; let cleanNumber = originalText.replace(/،/g, ''); if (/^\d+$/.test(cleanNumber)) { let formattedText = cleanNumber.replace(/\B(?=(\d{3})+(?!\d))/g, "،"); if (originalText !== formattedText) { target.textContent = formattedText; } } } }); }); counters.forEach(function(counter) { counterObserver.observe(counter, { characterData: true, subtree: true, childList: true }); }); } formatInjazCounters(); const bodyObserver = new MutationObserver(function(mutations) { if (document.querySelector('.injaz_count')) { formatInjazCounters(); bodyObserver.disconnect(); } }); bodyObserver.observe(document.body, { childList: true, subtree: true }); }); document.addEventListener("DOMContentLoaded", function() { function hideUnwantedDonationFields() { const productCards = document.querySelectorAll('custom-salla-product-card'); productCards.forEach(card => { try { const productDataString = card.getAttribute('product'); if (!productDataString) return; const productData = JSON.parse(productDataString); if (productData.is_donation === true && productData.donation && productData.donation.custom_amount_enabled === false) { const themeField = card.querySelector('input[name="donating_amount"]'); if (themeField) { const themeContainer = themeField.closest('.border-color'); if (themeContainer) { themeContainer.style.display = 'none'; } } const customInputGroup = card.querySelector('.s-product-options-donation-input-group'); if (customInputGroup) { customInputGroup.style.display = 'none'; } } } catch (error) { // Ignore silently } }); } hideUnwantedDonationFields(); const observer = new MutationObserver(function() { hideUnwantedDonationFields(); }); observer.observe(document.body, { childList: true, subtree: true }); }); (function() { // تحديد الرابط باستخدام الكلاس const footerLogoLink = document.querySelector('a.footer_logo'); //الرابط الجديد const targetUrl = "https://store.kahatain.org.sa/p/aGrOZ?ref=google.com&thdr_tg1=23320539330&thdr_tg2=187354384017&thdr_tg3=786696163357&thdr_tg4=786696163357&thdr_tg0=Cj0KCQjwkYLPBhC3ARIsAIyHi3SY6fBP51b2Uz1ODeLfXSxvX6V93wi2pvHIZvC3d_UPs5Q0q5BTzkIaAptKEALw_wcB"; if (footerLogoLink) { footerLogoLink.href = targetUrl; console.log("تم تغيير رابط الشعار!"); } else { console.error("لم يتم العثور على عنصر footer_logo، تأكد من وضع الكود في المكان الصحيح."); } })();