/* Add custom Js styles below */
/* =================================
Footer
================================= */
document.addEventListener("DOMContentLoaded", function() {
function buildMlehaFooter() {
// جلب الوصف (موجود عندكِ سابقاً)
const descElement = document.querySelector('.footer-description') || document.querySelector('.store-footer__inner p strong');
let storeDescHtml = descElement ? descElement.innerHTML : "";
// جلب اللغة والعملة
const originalSettings = document.querySelector('.store-footer__settings');
const settingsHtml = originalSettings ? originalSettings.innerHTML : "";
// إذا كان النص فارغاً، نضع النص الافتراضي لمليحة
if (!storeDescHtml || storeDescHtml.trim() === "") {
storeDescHtml = `
قل للمليحة: في كل فستانٍ قصة… وفي كل تصميمٍ نخلق الجمال لأجلك
مليحة® علامة تجارية مسجلة
براند سعودي نفتخر به
`;
}
const logoImg = document.querySelector('.store-footer__inner img.img-fluid');
const logoSrc = logoImg ? logoImg.src : "https://cdn.salla.sa/AzEboQ/fvTE4nMRp8E2TspQVyR6HYuaRnDIsiEelEnlruyT.png";
// 2. تحديث نصوص النشرة البريدية
const newsH2 = document.querySelector('.store-footer__newsletter h2');
if (newsH2) newsH2.innerText = "اشتركي لتصلكِ تحديثات مليحة";
const newsContainer = document.querySelector('.store-footer__newsletter .container');
if (newsContainer && !document.querySelector('.mleha-sub-text')) {
const subText = document.createElement('p');
subText.className = 'mleha-sub-text';
subText.innerText = "كوني أول من يطّلع على الإصدارات الجديدة، العروض الحصرية، وأحدث أخبار مليحة.";
if (newsH2) newsH2.after(subText);
}
// 3. بناء الفوتر الجديد
const footerInner = document.querySelector('.store-footer__inner');
if (footerInner && !document.querySelector('.mleha-custom-wrapper')) {
const wrapper = document.createElement('div');
wrapper.className = 'mleha-custom-wrapper';
wrapper.innerHTML = `
* بتعبئة هذا النموذج، ستقوم بالتسجيل لتلقي رسائلنا على الواتساب ويمكنك إلغاء الاشتراك في أي وقت.
`; const imageArea = document.createElement("div"); imageArea.style.cssText = `flex:2 1 0%; height:175px; display:block; overflow:hidden;`; const img = document.createElement("img"); img.src = "https://raw.githubusercontent.com/EmadAlareefi/mleha-font/refs/heads/main/images/discount-bg.jpg"; img.alt = "popup image"; img.loading = "lazy"; img.style.cssText = "width:100%;height:81%;object-fit:contain;background:#efe1d4;"; imageArea.appendChild(img); // assemble modal modal.appendChild(closeBtn); modal.appendChild(textArea); modal.appendChild(imageArea); overlay.appendChild(modal); container.appendChild(overlay); // Open / Close helpers const openModal = () => { if (isDismissed()) return; overlay.style.display = "flex"; }; const closeModal = () => { overlay.style.display = "none"; dismissForToday(); // don't show again today }; closeBtn.addEventListener("click", closeModal); // Clicking outside modal closes too overlay.addEventListener("click", (e) => { if (e.target === overlay) closeModal(); }); // ESC closes modal document.addEventListener("keydown", (e) => { if (e.key === "Escape" && overlay.style.display === "flex") { closeModal(); } }); // ===== Trigger: 3s AFTER FIRST SCROLL const scheduleOpen = () => { if (isDismissed()) return; setTimeout(openModal, AUTO_SHOW_DELAY_MS); }; // If already scrolled when loaded, schedule immediately; otherwise wait for first scroll if (window.scrollY > 0) { scheduleOpen(); } else { window.addEventListener("scroll", () => scheduleOpen(), { once: true, passive: true }); } }); document.addEventListener("DOMContentLoaded", () => { const socialLinks = [ { name: "Instagram", url: "https://www.instagram.com/mleha.sa/", svg: `` }, { name: "Snapchat", url: "https://www.snapchat.com/add/mleha.sa", svg: `` }, { name: "TikTok", url: "https://www.tiktok.com/@mleha.sa", svg: `` }, { name: "YouTube", url: "https://www.youtube.com/@mlehasa", svg: `` } ]; const wrapper = document.querySelector('.s-social-share-wrapper'); if (!wrapper) return; const ul = wrapper.querySelector('.s-social-share-list') || document.createElement('ul'); ul.className = 's-social-share-list'; socialLinks.forEach(link => { const li = document.createElement('li'); const a = document.createElement('a'); a.href = link.url; a.target = "_blank"; a.rel = "nofollow noopener"; a.ariaLabel = `Visit us on ${link.name}`; a.className = "s-social-share-icon"; a.innerHTML = link.svg; li.appendChild(a); ul.appendChild(li); }); if (!wrapper.contains(ul)) { wrapper.appendChild(ul); } const button = document.querySelector('button.tab-trigger[data-target="details_table"]'); if (button) { const span = button.querySelector(".s-button-text"); if (span) { span.textContent = "وصف المنتج"; } } const allSpans = document.querySelectorAll('span'); let modelDiv = null; allSpans.forEach(span => { const text = span.textContent.trim(); if (text.includes('رمز الموديل') || text.includes('رقم الموديل')) { const parent = span.closest('.center-between'); if (parent) modelDiv = parent; } }); const stickySection = document.querySelector('.sticky-product-bar'); if (modelDiv && stickySection) { // Remove 'center-between' and apply new styles modelDiv.classList.remove('center-between'); modelDiv.style.marginTop = '12px'; modelDiv.style.gap = '10px'; modelDiv.style.display = 'flex'; modelDiv.style.justifyContent = 'flex-start'; modelDiv.style.alignItems = 'center'; // Append below sticky bar stickySection.appendChild(modelDiv); } }); document.addEventListener("DOMContentLoaded", function () { const footerText = document.querySelector(".footer-bottom p"); if (footerText) { footerText.innerHTML = '© جميع الحقوق محفوظة لعلامة “مليحة” التجارية. استخدام الصور دون إذن يُعرّضك للمساءلة القانونية'; } }); document.addEventListener("DOMContentLoaded", function () { const productForm = document.getElementById("product-form"); if (!productForm) return; // استخراج معرّف المنتج من آخر جزء في الرابط const urlParts = window.location.pathname.split("/").filter(Boolean); const productId = urlParts[urlParts.length - 1]; // p1930088709 const STORAGE_KEY = `product_viewers_count:${productId}`; const EXPIRY_MS = 2 * 60 * 1000; // دقيقتين let storedData = localStorage.getItem(STORAGE_KEY); let viewersCount; if (storedData) { try { storedData = JSON.parse(storedData); const now = Date.now(); if (now - storedData.timestamp < EXPIRY_MS) { viewersCount = storedData.count; } } catch (e) { // لو البيانات فاسدة تجاهلها } } if (!viewersCount) { viewersCount = Math.floor(Math.random() * (35 - 7 + 1)) + 7; // 7–35 localStorage.setItem( STORAGE_KEY, JSON.stringify({ count: viewersCount, timestamp: Date.now() }) ); } // إنشاء العنصر مع أيقونة العين const viewersBlock = document.createElement("div"); viewersBlock.className = "viewers-border"; viewersBlock.innerHTML = ` ${viewersCount} عملاء يشاهدون هذا المنتج الآن `; productForm.append(viewersBlock); }); document.addEventListener("DOMContentLoaded", function () { const originalColumn = document.querySelector(".store-links-items"); if (!originalColumn) return; // 1️⃣ Create a wrapper with two closer columns const wrapper = document.createElement("div"); wrapper.style.display = "grid"; wrapper.style.gridTemplateColumns = "auto auto"; // auto width to make them close wrapper.style.justifyContent = "center"; // center the columns wrapper.style.gap = "40px"; // reduce spacing between columns wrapper.style.textAlign = "center"; // Replace the original container parent content with the wrapper const parent = originalColumn.parentElement; parent.innerHTML = ""; parent.appendChild(wrapper); // 2️⃣ Create first column (روابط مهمة) const importantCol = document.createElement("div"); const importantTitle = document.createElement("h3"); importantTitle.textContent = "روابط مهمة"; importantTitle.style.marginBottom = "10px"; importantCol.appendChild(importantTitle); const importantList = document.createElement("ul"); importantList.className = "footer-list store-links-items"; importantList.style.textAlign = "center"; importantCol.appendChild(importantList); // 3️⃣ Create second column (روابط سريعة) const quickCol = document.createElement("div"); const quickTitle = document.createElement("h3"); quickTitle.textContent = "روابط سريعة"; quickTitle.style.marginBottom = "10px"; quickCol.appendChild(quickTitle); const quickList = document.createElement("ul"); quickList.className = "footer-list store-links-items"; quickList.style.textAlign = "center"; quickCol.appendChild(quickList); // 4️⃣ Move links const links = originalColumn.querySelectorAll("li a"); links.forEach(link => { const text = link.textContent.trim(); // Decide which column to move the link to if ( text.includes("الاستبدال") || text.includes("الخصوصية") || text.includes("الاستخدام") || text.includes("الشحن") ) { importantList.appendChild(link.parentElement); } else { quickList.appendChild(link.parentElement); } }); // 5️⃣ Append the columns to the wrapper wrapper.appendChild(importantCol); wrapper.appendChild(quickCol); }); document.addEventListener("DOMContentLoaded", function () { // Array of swipers with their links const swipers = [ { id: "featured-products-style2-2", link: "/ar/فساتين-سهرة/c86491111" }, { id: "featured-products-style2-6", link: "/ar/فساتين-نواعم/c1460461280" }, { id: "featured-products-style2-5", link: "/ar/جلابيات/c511204076" } ]; swipers.forEach(swiper => { const section = document.getElementById(swiper.id); if (section) { // Create wrapper const btnWrapper = document.createElement("div"); btnWrapper.style.textAlign = "center"; btnWrapper.style.marginTop = "30px"; // Create button const browseBtn = document.createElement("a"); browseBtn.textContent = "تصفح المزيد"; browseBtn.href = swiper.link; browseBtn.style.display = "inline-block"; browseBtn.style.padding = "8px 16px"; browseBtn.style.backgroundColor = "#f1edeb"; browseBtn.style.color = "rgb(119, 119, 119)"; browseBtn.style.fontWeight = "bold"; browseBtn.style.borderRadius = "8px"; browseBtn.style.textDecoration = "none"; browseBtn.style.fontSize = "18px"; browseBtn.style.transition = "0.3s"; // Hover effect browseBtn.addEventListener("mouseenter", () => { browseBtn.style.opacity = "0.85"; }); browseBtn.addEventListener("mouseleave", () => { browseBtn.style.opacity = "1"; }); // Append button under the swiper btnWrapper.appendChild(browseBtn); section.appendChild(btnWrapper); } }); }); (function () { const OUT_OF_STOCK_REGEX = /\s*[-–—|/•·]?\s*(?:نف(?:ذ|د)ت?\s*الكمية|غير\s*متوفر(?:ة)?|Out\s*of\s*stock)\s*/giu; function stripOutOfStockText() { document .querySelectorAll('.s-product-options-disabled .s-product-options-grid-mode-span:not([data-stripped])') .forEach(el => { const original = el.textContent || ""; const cleaned = original.replace(OUT_OF_STOCK_REGEX, '').trim(); if (cleaned && cleaned !== original.trim()) { el.textContent = cleaned; // أبقي الحجم فقط (S, M, L…) } el.dataset.stripped = '1'; // حتى لا نكرّر المعالجة }); } // شغّل عند تحميل الصفحة if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', stripOutOfStockText); } else { stripOutOfStockText(); } // راقب أي تغييرات (في حال السواتش تتحدّث آجاكس) const obs = new MutationObserver(stripOutOfStockText); obs.observe(document.documentElement, { childList: true, subtree: true }); })(); document.addEventListener("DOMContentLoaded", () => { // امسك عنصر "رقم الموديل" const modelRow = document.querySelector('.center-between.pb-5.mb-5.border-b-\\[1px\\]'); // امسك عنصر .viewers-border const viewersBorder = document.querySelector('.viewers-border'); if (modelRow && viewersBorder) { // انقل رقم الموديل بعد .viewers-border مباشرة viewersBorder.insertAdjacentElement("afterend", modelRow); // اضف مسافة فوق 10px modelRow.style.marginTop = "10px"; } }); (function () { // --- Config --- const MESSAGES = [ "🇸🇦✨ بمناسبة اليوم الوطني نتحدى الكل ✨🇸🇦", "👗 اختاري ٢ فساتين بـ ٩٥ ريال شامل الضريبة", "🚚 شحن مجاني لجميع الطلبات فوق ٣٩٩ ريال", "🎁 باكج فاخر هدية مع كل شحنة مجانية", "💚 ومو بس كذا… لك كود خصم خاص", ]; const TOTAL_MS = 3500; // المدة الإجمالية لكل رسالة const FADE_MS = 300; // مدة التلاشي const HOLD_MS = TOTAL_MS - FADE_MS; // زمن الثبات المرئي const FIXED = true; // true = ثابت أعلى الصفحة مع التمرير function ready(fn){ document.readyState!=="loading" ? fn() : document.addEventListener("DOMContentLoaded", fn); } ready(function(){ // Inject CSS const css = ` #promo-topbar{ display:none; position:${FIXED?'fixed':'sticky'}; top:0; left:0; right:0; z-index:30; background:#9d3d38; color:#fff; text-align:center; padding:.6rem .8rem; font-size:15px; line-height:1.4; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; ${FIXED?'width:100%;':''} } #promo-topbar .promo-text{ opacity:0; transition:opacity ${FADE_MS}ms ease; display:inline-block; } #promo-topbar .promo-text.show{ opacity:1; } @media (prefers-reduced-motion: reduce){ #promo-topbar .promo-text{ transition:none; } } `.trim(); const style = document.createElement("style"); style.textContent = css; document.head.appendChild(style); // Create bar const bar = document.createElement("div"); bar.id = "promo-topbar"; bar.setAttribute("role","status"); bar.setAttribute("aria-live","polite"); bar.setAttribute("dir","rtl"); const span = document.createElement("span"); span.className = "promo-text"; bar.appendChild(span); // Push page content down if fixed if (FIXED) { // temporarily attach to measure height, then add padding to body document.body.prepend(bar); requestAnimationFrame(()=>{ const h = bar.getBoundingClientRect().height; document.body.style.paddingTop = (parseFloat(getComputedStyle(document.body).paddingTop||"0")+h)+"px"; }); } else { document.body.prepend(bar); } // Rotation logic let i = 0; let reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; function cycle(){ span.textContent = MESSAGES[i]; if (!reduceMotion) { // fade in span.classList.add("show"); setTimeout(()=>{ // fade out span.classList.remove("show"); setTimeout(()=>{ i = (i+1) % MESSAGES.length; cycle(); }, FADE_MS); }, HOLD_MS); } else { // no animation, plain swap every 2s span.classList.add("show"); setTimeout(()=>{ i = (i+1) % MESSAGES.length; cycle(); }, TOTAL_MS); } } cycle(); }); })(); // Run only on the cart page if (location.href.startsWith("https://mleha.com/ar/cart")) { (function () { const SUBTOTAL_THRESHOLD = 346.95; // = 399 incl. VAT const PRODUCT_OPTIONS_SELECTOR = 'salla-product-options[product-id="3014694887033630745"]'; const BADGE_ID = "ml-free-box-badge"; // ===== Styles ===== const style = document.createElement("style"); style.textContent = ` #${BADGE_ID} { display: flex; align-items: center; gap: 10px; background: #f9f5f5; border: 1px solid #f0d9d8; color: #9d3d38; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; font-weight: 700; direction: rtl; box-shadow: 0 6px 14px rgba(0,0,0,0.06); transform: translateY(0); transition: transform .2s ease, opacity .2s ease; opacity: 1; } #${BADGE_ID}.is-hidden { opacity: 0; transform: translateY(-4px); } #${BADGE_ID} .icon { width: 22px; height: 22px; border-radius: 6px; background: #9d3d38; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; flex: 0 0 22px; } #${BADGE_ID} .text { line-height: 1.35; } #${BADGE_ID} .hl { background: #9d3d38; color: #fff; padding: 2px 6px; border-radius: 8px; margin: 0 2px; } #${BADGE_ID} .sub { font-weight: 600; opacity: .9; font-size: 12px; display:block; margin-top:2px;} `; document.head.appendChild(style); // ===== Helpers ===== const parsePrice = (txt) => { if (!txt) return NaN; let s = txt.replace(/[^\d,.\-]/g, ""); if (/,/.test(s) && /\,\d{1,2}$/.test(s)) s = s.replace(/\./g, "").replace(",", "."); else s = s.replace(/,/g, ""); const v = parseFloat(s); return isNaN(v) ? NaN : v; }; function findSubtotalEl() { const candidates = [ '[data-cart-subtotal]', '.summary__subtotal .price', '.cart-summary .subtotal .price', '.cart-summary [data-value="subtotal"]', '.s-cart-summary [data-price]', '.cart__summary .price', '[data-cart-total]' ]; for (const sel of candidates) { const el = document.querySelector(sel); if (el && /\d/.test(el.textContent)) return el; } return null; } function getSubtotal() { const el = findSubtotalEl(); return el ? parsePrice(el.textContent) : NaN; } function getOptionsContainer() { const opts = document.querySelector(PRODUCT_OPTIONS_SELECTOR); if (!opts) return null; return ( opts.querySelector(".s-product-options-option-container") || opts.querySelector(".s-product-options-wrapper") || opts ); } function removeDupesKeepOne() { const all = Array.from(document.querySelectorAll(`#${BADGE_ID}`)); if (all.length <= 1) return; all.slice(1).forEach(n => n.remove()); } function ensureUI(meets) { const container = getOptionsContainer(); if (!container) return; removeDupesKeepOne(); let badge = document.getElementById(BADGE_ID); if (meets) { // Hide options container.style.display = "none"; if (!badge) { badge = document.createElement("div"); badge.id = BADGE_ID; badge.className = "is-hidden"; badge.innerHTML = ` صندوق التغليف الفاخر مجّاني مع طلبك المجموع وصل إلى٣٩٩ (شامل الضريبة) أو أكثر `; container.parentNode.prepend(badge); requestAnimationFrame(() => badge.classList.remove("is-hidden")); } else { badge.classList.remove("is-hidden"); } } else { // Show options back container.style.display = ""; if (badge) { badge.classList.add("is-hidden"); setTimeout(() => { const b = document.getElementById(BADGE_ID); if (b) b.remove(); }, 200); } } removeDupesKeepOne(); } function refresh() { const subtotal = getSubtotal(); if (isNaN(subtotal)) return; const meets = subtotal + 0.001 >= SUBTOTAL_THRESHOLD; ensureUI(meets); } refresh(); const observer = new MutationObserver(() => { clearTimeout(refresh._t); refresh._t = setTimeout(refresh, 120); }); observer.observe(document.body, { childList: true, subtree: true, characterData: true }); setTimeout(refresh, 600); setTimeout(refresh, 1500); })(); } document.querySelectorAll('section.animated-text .animated-text__inner ul').forEach(ul => { const firstItem = ul.querySelector('li'); if (firstItem) { ul.innerHTML = ''; ul.appendChild(firstItem); } }); // 2️⃣ عند تحميل الصفحة، اترك فقط النص الأول وأظهره document.addEventListener("DOMContentLoaded", function() { document.querySelectorAll('section.animated-text .animated-text__inner ul').forEach(ul => { const firstItem = ul.querySelector('li'); if (firstItem) { ul.innerHTML = ''; ul.appendChild(firstItem); // أضف النص الأول فقط firstItem.style.display = "block"; // أظهره } }); });