document.addEventListener("DOMContentLoaded", function () { if (document.querySelector(".custom-saffron-footer")) return; const footerHTML = ` `; document.body.insertAdjacentHTML("beforeend", footerHTML); }); // 1. حقن CSS لإخفاء شريط جوجل بدون التأثير على الموقع الأصلي (function injectAdvancedTranslationFixStyles() { const styleId = 'google-translate-super-fix'; if (!document.getElementById(styleId)) { const style = document.createElement('style'); style.id = styleId; style.innerHTML = ` iframe.goog-te-banner-frame, .goog-te-banner-frame.skiptranslate, .goog-te-banner-frame { display: none !important; visibility: hidden !important; height: 0px !important; opacity: 0 !important; border: none !important; } body.translated-ltr, html.translated-ltr { top: 0px !important; margin-top: 0px !important; position: static !important; } .goog-tooltip, .goog-tooltip:hover { display: none !important; } .goog-text-highlight { background-color: transparent !important; border: none !important; box-shadow: none !important; } `; document.head.appendChild(style); } })(); // 2. تهيئة سكربت ترجمة جوجل في الخلفية (function initGoogleTranslateSystem() { if (!document.getElementById('google_translate_element')) { const translateDiv = document.createElement('div'); translateDiv.id = 'google_translate_element'; translateDiv.style.display = 'none'; document.body.appendChild(translateDiv); } window.googleTranslateElementInit = function () { new google.translate.TranslateElement({ pageLanguage: 'ar', includedLanguages: 'en', autoDisplay: false }, 'google_translate_element'); }; if (!document.getElementById('google-translate-script')) { const gtScript = document.createElement('script'); gtScript.id = 'google-translate-script'; gtScript.type = 'text/javascript'; gtScript.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'; document.head.appendChild(gtScript); } })(); // 3. منطق التفاعل وإغلاق النافذة التلقائي document.addEventListener('DOMContentLoaded', function () { // دالة تنظيف كوكيز جوجل function clearGoogleTranslateCookies() { const hostname = window.location.hostname; const domains = [hostname, '.' + hostname, '']; const paths = ['/', window.location.pathname]; domains.forEach(domain => { paths.forEach(path => { const domainAttr = domain ? `; domain=${domain}` : ''; document.cookie = `googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}${domainAttr};`; document.cookie = `googtrans=/ar/en; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}${domainAttr};`; }); }); } function enforceTopPosition() { document.body.style.top = '0px'; document.body.style.marginTop = '0px'; document.documentElement.style.top = '0px'; document.documentElement.style.marginTop = '0px'; } function switchToEnglish() { const googleSelect = document.querySelector('.goog-te-combo'); if (googleSelect) { googleSelect.value = 'en'; googleSelect.dispatchEvent(new Event('change')); document.documentElement.dir = 'ltr'; enforceTopPosition(); } } // دالة إغلاق النافذة المنبثقة (Popup) فوراً وبشكل مضمون function closeLocalizationModal() { // 1. الضغط على زر X تلقائياً const closeBtn = document.querySelector('.s-modal-close, [data-modal-close], .s-localization-modal-close'); if (closeBtn) { closeBtn.click(); } // 2. إغلاق الـ Web Component الخاص بسلة إذا كان مستخدماً const sallaModal = document.querySelector('salla-modal[open], salla-modal'); if (sallaModal && typeof sallaModal.close === 'function') { sallaModal.close(); } // 3. إخفاء إضافي سريع في حال وجود كلاسات نشطة للـ Modal setTimeout(() => { const activeModal = document.querySelector('.s-modal-body, .s-localization-modal-inner'); if (activeModal) { const modalContainer = activeModal.closest('salla-modal, .s-modal, .modal'); if (modalContainer) { modalContainer.style.display = 'none'; modalContainer.removeAttribute('open'); } } }, 50); } // الاستماع للضغط على زر "موافق" window.addEventListener('click', function (e) { const confirmBtn = e.target.closest('.s-modal-body button:not(.s-modal-close), .s-localization-modal-inner button, .s-modal-footer button'); if (confirmBtn) { const englishRadio = document.getElementById('lang-en'); const isTranslateActive = document.cookie.includes('googtrans') || document.documentElement.classList.contains('translated-ltr'); // 🟡 الحالة 1: اختيار الإنجليزية -> تفعيل الترجمة وإغلاق النافذة فوراً if (englishRadio && englishRadio.checked) { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); switchToEnglish(); closeLocalizationModal(); // إغلاق النافذة تلقائياً } // 🔵 الحالة 2: اختيار العربية والموقع مترجم بإنكليزي جوجل -> إعادة تحميل الصفحة للنسخة العربية else if (isTranslateActive) { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); clearGoogleTranslateCookies(); window.location.reload(); } // 🟢 الحالة 3: اختيار العربية والموقع أصلاً عربي -> ترك سلوك سلة الافتراضي كما هو } }, true); // مراقبة الفراغات فقط أثناء تفعيل الترجمة const observer = new MutationObserver(function () { if (document.cookie.includes('googtrans') || document.documentElement.classList.contains('translated-ltr')) { if (document.body.style.top !== '0px' || document.body.style.marginTop !== '0px') { enforceTopPosition(); } } }); observer.observe(document.body, { attributes: true, attributeFilter: ['style'] }); observer.observe(document.documentElement, { attributes: true, attributeFilter: ['style'] }); });