// Google Form injection document.addEventListener("DOMContentLoaded", function () { const headings = document.querySelectorAll("h1"); headings.forEach(h1 => { if (h1.textContent.trim() === "نموذج طلب صيانة") { const contentEntry = h1.closest(".content--single-page")?.querySelector(".content-entry"); if (contentEntry) { contentEntry.innerHTML = `

الرجاء قراءة سياسة الضمان بعناية: سياسة الضمان

`; } } }); }); // Countdown Timer document.addEventListener('DOMContentLoaded', function () { const timerWrapper = document.createElement('div'); timerWrapper.className = "timerWrapper"; timerWrapper.style.position = 'relative'; timerWrapper.style.width = '100%'; timerWrapper.style.height = '500px'; timerWrapper.style.maxHeight = '600px'; timerWrapper.style.margin = '1rem auto -2rem'; timerWrapper.style.borderRadius = '12px'; timerWrapper.style.transition = 'opacity 0.5s ease'; const timerIframe = document.createElement('iframe'); timerIframe.src = 'https://rabab13.github.io/Timer'; timerIframe.style.width = '100%'; timerIframe.style.height = '100%'; timerIframe.style.border = 'none'; timerIframe.scrolling = 'no'; const overlay = document.createElement('div'); overlay.style.position = 'absolute'; overlay.style.top = '0'; overlay.style.left = '0'; overlay.style.width = '100%'; overlay.style.height = '70%'; overlay.style.cursor = 'pointer'; overlay.style.zIndex = '10'; overlay.addEventListener('click', () => { window.location.href = 'https://homesfurniture.sa/ar'; }); // Assemble timerWrapper.appendChild(timerIframe); timerWrapper.appendChild(overlay); function checkTimerExpired() { const days = timerIframe.contentDocument?.querySelector('.days')?.textContent; const hours = timerIframe.contentDocument?.querySelector('.hours')?.textContent; const minutes = timerIframe.contentDocument?.querySelector('.minutes')?.textContent; const seconds = timerIframe.contentDocument?.querySelector('.seconds')?.textContent; if (days === '00' && hours === '00' && minutes === '00' && seconds === '00') { timerWrapper.style.opacity = '0'; setTimeout(() => { timerWrapper.style.display = 'none'; }, 500); return true; } return false; } function isPastDeadline() { const now = new Date(); const deadline = new Date('2025-10-05T23:59:59'); return now >= deadline; } if (isPastDeadline()) { timerWrapper.style.display = 'none'; return; } // Set up periodic checking const timerCheckInterval = setInterval(() => { try { if (checkTimerExpired()) { clearInterval(timerCheckInterval); } } catch (e) { console.log('Could not access timer content:', e); clearInterval(timerCheckInterval); } }, 1000); // Handle iframe load timerIframe.onload = function () { if (!checkTimerExpired()) { const timerCheckInterval = setInterval(() => { try { if (checkTimerExpired()) { clearInterval(timerCheckInterval); } } catch (e) { console.log('Could not access timer content:', e); } }, 1000); } }; const section = document.querySelectorAll('section'); if (section.length >= 1) { const secondSection = section[0]; secondSection.parentNode.insertBefore(timerWrapper, secondSection.nextSibling); } else { document.body.appendChild(timerWrapper); } }); // GIF Icon Color document.addEventListener("DOMContentLoaded", function () { const icons = document.querySelectorAll('.image-wrap lord-icon'); icons.forEach(icon => { icon.setAttribute('colors', 'primary:#e3b967,secondary:#c39337'); }); }); //-------------- // Promotion Titles function updatePromotionTitles() { const items = document.querySelectorAll('.container--product-single'); items.forEach(item => { const listItems = item.querySelectorAll('li'); const supTitle = item.querySelector('.promotion-title'); const quantityEl = item.querySelector('.text-green-500'); const salePriceEl = item.querySelector('.sale-price'); const discountEl = item.querySelector('#discount-amount-value'); const countdownEl = document.querySelector('salla-count-down'); console.log(countdownEl); console.log('val', discountEl) if (!supTitle) return; let stockValue = null; // Check remaining stock listItems.forEach(li => { const strong = li.querySelector('strong'); const span = li.querySelector('span'); const strongText = strong?.textContent.trim(); const spanText = span?.textContent.trim(); if (strongText === "المتبقي:" && spanText) { const numericStock = parseInt(spanText); if (!isNaN(numericStock)) { stockValue = numericStock; } } }); const isAvailable = quantityEl?.textContent.includes("متوفر"); // Check sale price let salePrice = null; if (salePriceEl) { const priceText = salePriceEl.textContent.replace(/[^\d]/g, ''); salePrice = parseInt(priceText); } // Check discount let discountValue = null; if (discountEl) { const discountText = discountEl.textContent.replace(/[^\d]/g, ''); discountValue = parseInt(discountText); } // Apply rules if (countdownEl !== null ) { supTitle.textContent = "عرض لفتره محدوده!"; } else if (salePrice !== null && salePrice < 500) { supTitle.textContent = "أسعار خياليه!"; } else if (stockValue === 0) { supTitle.textContent = "ستتوفر قريبا!"; } else if (stockValue > 0 && stockValue < 5) { supTitle.textContent = "قارب على النفاذ!"; } else if (stockValue > 0 && stockValue < 5) { supTitle.textContent = "عرض خيالى!"; } else { supTitle.textContent } }); } setTimeout(updatePromotionTitles, 500); //------------- document.addEventListener("DOMContentLoaded", function () { const timers = document.querySelectorAll('salla-count-down[date="2025-10-04"]'); console.log(timers) timers.forEach(timer => { function updateTimer() { let targetDate = timer.getAttribute("date"); if (!targetDate) return; console.log('TD',targetDate) let now = new Date(); let dateObj = new Date(targetDate); while (dateObj <= now) { dateObj.setDate(dateObj.getDate() + 4); } // Format YYYY-MM-DD let formattedDate = dateObj.toISOString().split("T")[0]; // Update attribute timer.setAttribute("date", formattedDate); // Re-render countdown (force refresh if component supports it) if (typeof timer.connectedCallback === "function") { timer.connectedCallback(); } } // Run once at page load updateTimer(); // Keep checking every minute in case it expires while user is on the page setInterval(updateTimer, 60 * 1000); }); });