document.addEventListener("DOMContentLoaded", function() { var currentPath = window.location.pathname; var isHomePage = currentPath === "/" || currentPath === "" || currentPath === "/ar" || currentPath === "/ar/" || currentPath === "/en" || currentPath === "/en/"; if (isHomePage) { // 1. حقن كود الاتصال الذكي الخاص بـ Mailchimp var mcScript = document.createElement("script"); mcScript.id = "mcjs"; mcScript.text = `!function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0],m.async=1,m.src=i,p.parentNode.insertBefore(m,p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/6f2b048c78fd39418e0ab35c8/62170c3be5621360e01f15440.js");`; document.head.appendChild(mcScript); // 2. إنشاء إطار مخفي (Hidden Iframe) لمعالجة الإرسال في الخلفية وبقاء العميل في المتجر if (!document.getElementById("mailchimp-hidden-iframe")) { var iframe = document.createElement("iframe"); iframe.name = "mailchimp-hidden-iframe"; iframe.id = "mailchimp-hidden-iframe"; iframe.style.display = "none"; document.body.appendChild(iframe); } // 3. إنشاء حاوية النشرة البريدية var newsletterSection = document.createElement("div"); newsletterSection.className = "custom-newsletter-container"; newsletterSection.innerHTML = `
`; // 4. تحديد مكان الظهور (قبل الفوتر مباشرة) var footerElement = document.querySelector("footer") || document.getElementById("footer") || document.querySelector(".site-footer"); if (footerElement) { footerElement.parentNode.insertBefore(newsletterSection, footerElement); } // 5. إضافة تأثير إشعار النجاح الفوري عند الضغط دون مغادرة الصفحة var form = document.getElementById("custom-mc-form"); if (form) { form.addEventListener("submit", function() { setTimeout(function() { alert("تم اشتراكك بنجاح في برقية وردية ✨ أهلًا بكِ في عالمنا الوردي!"); var emailInput = document.getElementById("custom-mc-email"); if (emailInput) emailInput.value = ""; // تفريغ الحقل بعد الاشتراك }, 1000); // تظهر الرسالة بعد ثانية واحدة من الضغط }); } } });