const uaeWa = "971588874870"; // 👈 (يبدء برمز الدولة بدون +) رقم الإمارات // ==================== Main ==================== // ========== Get Country ========== let countryCode = null; fetch("https://ipapi.co/json/") .then(res => res.json()) .then(data => { countryCode = data.country_code; // الآن صار عندنا countryCode متاح لأي كود آخر }) .catch(err => console.error("خطأ في جلب موقع العميل:", err)); const checkCountryInt = setInterval(() => { if (countryCode) { // ننتظر لما يكون عندنا كود البلد clearInterval(checkCountryInt); // ========== Change Currency To Default ========== let openBtn = document.querySelector(`button[onclick*="salla.event.dispatch('localization::open')"]`); if (openBtn && !localStorage.getItem("currencyChosenToDefault")) { const countryCurrencyMap = { "SA": "SAR", "AE": "AED", "KW": "KWD", "QA": "QAR", "BH": "BHD", "IQ": "IQD", "OM": "OMR", "YE": "YER", "EG": "EGP", "SD": "SDG", "LY": "LYD", "DZ": "DZD", "TN": "TND", "MA": "MAD", "PS": "ILS", "AU": "AUD", "EU": "EUR", "JO": "JOD", "US": "USD", "SE": "SEK", "CN": "CNY", "GB": "GBP", "IN": "INR", "JP": "JPY", "PK": "PKR", "TR": "TRY", "CA": "CAD", "MY": "MYR", "MR": "MRU" }; let targetCurrency = countryCurrencyMap[countryCode]; if (!targetCurrency) return; localStorage.setItem("currencyChosenToDefault", "true"); let modalContainer; const modalContainerInt = setInterval(() => { modalContainer = document.querySelector('salla-modal:has(.s-localization-modal-inner)'); if (modalContainer) { clearInterval(modalContainerInt); modalContainer.classList.add('temp-hid'); openBtn.click(); const currencyCheckInt = setInterval(() => { let currencyInputs = document.querySelectorAll('.s-localization-modal-input'); if (currencyInputs.length > 0) { clearInterval(currencyCheckInt); let matchedInput = Array.from(currencyInputs).find(input => input.value === targetCurrency); if (matchedInput && !matchedInput.checked) { matchedInput.click(); modalContainer.querySelector('.s-localization-modal-inner > .s-button-wrap').click(); } else { modalContainer.querySelector('.s-modal-close')?.click(); modalContainer.classList.remove('temp-hid'); } } }, 100); } }, 100); } // ========== WA Num ========== let waNumAnc; const waNumAncInt = setInterval(() => { waNumAnc = document.querySelector('.store-footer [href="https://birqsa.com/whatsapp/send"]'); if (waNumAnc) { clearInterval(waNumAncInt); let waNum = waNumAnc.querySelector('[class="unicode"]').textContent.replace(/^\+/, ''); if (countryCode === "AE" && uaeWa) waNum = uaeWa; waNumAnc.href = `https://api.whatsapp.com/send/?phone=${waNum}` waNumAnc.querySelector('[class="unicode"]').textContent = `+${waNum}` const telNumAnc = document.querySelector('.store-footer [href="tel:+966508907871"]'); telNumAnc.href = `tel:+${waNum}`; telNumAnc.querySelector('[class="unicode"]').textContent = `+${waNum}` // ========== Custom WhatsApp Icon ========== const waIcon = document.createElement('div'); waIcon.className = 'float-wa'; waIcon.innerHTML = ` يا هلا👋 عندك سؤال؟ تواصل معنا `; const waIconBtn = document.createElement('button'); waIconBtn.className = 'hide-msg-btn sicon-cancel'; waIconBtn.onclick = () => waIcon.classList.add('hidden-msg'); waIcon.append(waIconBtn); const prodOptCont = document.querySelector('.page-container.product-has-options .main-content') prodOptCont ? prodOptCont.append(waIcon) : document.body.append(waIcon); // ========== New Customer PopUp ========== const popupKey = 'newCusPopupClosedAt'; const hoursToWait = 24; const now = Date.now(); const lastClosedAt = localStorage.getItem(popupKey); // Check if popup was closed within the last 24 hours const shouldShowPopup = !lastClosedAt || (now - Number(lastClosedAt)) > hoursToWait * 60 * 60 * 1000; if (shouldShowPopup) { const newCusPopUp = document.createElement('div'); newCusPopUp.className = 'new-cus-popup'; // When popup is clicked, hide and store close time newCusPopUp.onclick = () => { newCusPopUp.classList.remove('show'); localStorage.setItem(popupKey, Date.now().toString()); }; const nCPCont = document.createElement('div'); newCusPopUp.append(nCPCont); const nCPLink = document.createElement('a'); const waMssg = encodeURIComponent("أرغب بكود خصم"); nCPLink.href = `https://api.whatsapp.com/send/?phone=${waNum}&text=${waMssg}`; const nCPImg = document.createElement('img'); nCPImg.src = "https://i.ibb.co/zh71tT41/image.jpg"; nCPImg.alt = "Whatsapp"; nCPLink.append(nCPImg); const nCPIcon = document.createElement('i'); nCPIcon.className = 'sicon-cancel'; nCPCont.append(nCPLink, nCPIcon); document.body.append(newCusPopUp); // Show popup after 30 seconds setTimeout(() => { newCusPopUp.classList.add('show'); }, 30000); } } }, 100); } }, 100); // ==================== Product Page ==================== if (document.body.classList.contains('product-single')) { const desc = document.querySelector('.article--main'); // ========== Sort Sections ========== const sortCont = document.createElement('div'); sortCont.className ='sort-cont'; const elementOrder = ['.main-link', '.product__description + div:has(> a)', 'div:has(>salla-installment)']; elementOrder.forEach(classSelc => { const e = document.querySelector(classSelc); if (e) sortCont.append(e); }); desc ? document.getElementById('product-details-tab').after(sortCont) : document.getElementById('single-product-form').before(sortCont); if (desc) { // ========== Read More ========== if (desc.clientHeight > 320) { document.querySelector('.product__description').style.display = 'none'; desc.classList.add('read-more-close'); const readMoreWrap = document.createElement('div'); readMoreWrap.className = 'read-more-wrap'; const readMoreBtn = document.createElement('button'); readMoreBtn.className = 'read-more-btn'; readMoreBtn.textContent = 'قراءة المزيد'; readMoreWrap.append(readMoreBtn); desc.after(readMoreWrap); readMoreBtn.onclick = function () { readMoreWrap.style.display = 'none'; desc.classList.remove('read-more-close'); } } // ========== Custom special Offer ========== const pElements = Array.from(desc.querySelectorAll("p")); const startIndex = pElements.findIndex(p => p.textContent.includes("بداية تعديل العرض الخاص")); if (startIndex !== -1) { let offerName = ""; let offerTit = ""; let relatedProductNames = []; for (let i = startIndex; i < pElements.length; i++) { const p = pElements[i]; const text = p.textContent.trim(); if (text.startsWith("العنوان:")) { offerName = text.replace("العنوان:", "").trim(); } else if (text.startsWith("الوصف:")) { offerTit = text.replace("الوصف:", "").trim(); } else if (text && text !== "بداية تعديل العرض الخاص") { relatedProductNames.push(text); } p.remove(); } if (offerName && relatedProductNames.length > 0) { const parent = document.querySelector('.main-content'); const sallaOffer = document.createElement('salla-offer'); sallaOffer.className = 'hydrated'; parent.append(sallaOffer); const sallaOfferWrapper = document.createElement('div'); sallaOfferWrapper.className = 's-offer-wrapper'; sallaOffer.append(sallaOfferWrapper); const sallaOfferBadge = document.createElement('p'); sallaOfferBadge.className = 's-offer-corner-badge'; sallaOfferBadge.textContent = offerName; sallaOfferWrapper.append(sallaOfferBadge); const sallaOfferSlider = document.createElement('salla-slider'); sallaOfferSlider.id = 'offer-slider'; sallaOfferSlider.className = 'cus s-slider-wrapper carousel-slider s-slider-horizontal'; sallaOfferSlider.direction = 'rtl'; if (offerTit) { sallaOfferSlider.blockTitle = offerTit; } sallaOfferWrapper.append(sallaOfferSlider); const checkInterval = setInterval(() => { const allRelatedProducts = [...document.querySelectorAll("#similar-slider .s-product-card-entry")]; if (allRelatedProducts.length) { let offerSectionProducts = []; relatedProductNames.forEach(name => { allRelatedProducts.forEach(rp => { const titleEl = rp.querySelector('.s-product-card-content-title a'); if (titleEl && titleEl.textContent.trim() === name) { allRelatedProducts.splice(allRelatedProducts.indexOf(rp), 1); offerSectionProducts.push(rp); } }); }); if (offerSectionProducts.length) { clearInterval(checkInterval); const swiperInterval = setInterval(() => { const offerSwiper = sallaOfferSlider.querySelector('.swiper-wrapper'); if (offerSwiper) { clearInterval(swiperInterval); for (let i = 0; i < offerSectionProducts.length; i++) { const slide = document.createElement('div'); slide.className = 's-offer-slide-one-fourth swiper-slide'; slide.role = 'group'; slide.ariaLabel = `${i + 1} / ${offerSectionProducts.length}`; slide.append(offerSectionProducts[i]); offerSwiper.append(slide); } document.querySelector('.s-products-slider-slider').update(); } }, 100); } } }, 100); } } } }