/* ✅ JavaScript (بدون تعليقات/تقييمات/جداول وصف) */ document.addEventListener("DOMContentLoaded", function () { /* 1) إضافة كلاس loaded للصور بعد التحميل */ const images = document.querySelectorAll("img"); images.forEach((img) => { if (img.complete) { img.classList.add("loaded"); } else { img.addEventListener("load", () => img.classList.add("loaded")); } }); /* 2) زر واتساب عائم */ const whatsappNumber = "+966581755735"; // غيّره لرقم متجرك الجديد const whatsappBtn = document.createElement("div"); whatsappBtn.innerHTML = ` WhatsApp `; document.body.appendChild(whatsappBtn); const style = document.createElement("style"); style.innerHTML = ` .whatsapp-button{ position:fixed; bottom:20px; right:20px; width:60px; height:60px; background:#25d366; border-radius:50%; display:flex; align-items:center; justify-content:center; box-shadow:0 4px 10px rgba(0,0,0,.3); transition:transform .3s; animation:bounce 1.5s infinite; z-index:9999; } .whatsapp-button img{width:35px;height:35px} .whatsapp-button:hover{transform:scale(1.1)} @keyframes bounce{0%,100%{transform:translateY(0)}50%{transform:translateY(-10px)}} `; document.head.appendChild(style); }); /* 3) محسّن صور سلة (WebP + Lazy + Cloudflare image resizing) */ (function () { "use strict"; console.log("🔄 جاري تحميل محسّن صور سلة..."); var supportsWebP = false; var testImg = new Image(); testImg.onload = testImg.onerror = function () { supportsWebP = testImg.height === 1; if (supportsWebP) { console.log("✅ المتصفح يدعم WebP - بدء التحسين"); init(); } else { console.log("❌ المتصفح لا يدعم WebP"); } }; testImg.src = "data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAwA0JaQAA3AA/vuUAAA="; function init() { var TARGET_HOSTS = ["cdn.salla.sa", "cdn.salla.network", "cdn.assets.salla.network"]; var processed = new WeakSet(); var count = 0; function shouldOptimize(url) { if (!url || typeof url !== "string") return false; if (url.startsWith("data:")) return false; if (url.endsWith(".svg")) return false; if (url.indexOf("/cdn-cgi/image/") > -1) return false; if (url.indexOf("s-empty.png") > -1) return false; try { var fullUrl = url.startsWith("//") ? "https:" + url : url; var urlObj = new URL(fullUrl, window.location.origin); return TARGET_HOSTS.some(function (host) { return urlObj.hostname === host; }); } catch (e) { return false; } } function getWidth(img) { try { var w = parseInt(img.getAttribute("width")); if (w > 0) return Math.min(w * 1.5, 2000); var rect = img.getBoundingClientRect(); if (rect.width > 0) return Math.min(Math.round(rect.width * 1.5), 2000); if (img.naturalWidth) return Math.min(img.naturalWidth, 2000); return 800; } catch (e) { return 800; } } function optimize(url, width) { if (!shouldOptimize(url)) return url; try { var fullUrl = url.startsWith("//") ? "https:" + url : url; var urlObj = new URL(fullUrl, window.location.origin); width = Math.max(200, Math.min(width || 800, 2000)); var optimized = urlObj.origin + "/cdn-cgi/image/w=" + width + ",q=85,f=webp,fit=scale-down" + urlObj.pathname + urlObj.search; count++; if (count <= 5) console.log("✨ صورة #" + count + ": " + url.substring(0, 40) + "..."); return optimized; } catch (e) { return url; } } function processImg(img) { if (processed.has(img)) return; processed.add(img); try { var width = getWidth(img); var dataSrc = img.getAttribute("data-src"); if (dataSrc && shouldOptimize(dataSrc)) img.setAttribute("data-src", optimize(dataSrc, width)); if (img.src && shouldOptimize(img.src)) { var newSrc = optimize(img.src, width); if (newSrc !== img.src) img.src = newSrc; } var dataLazy = img.getAttribute("data-lazy"); if (dataLazy && shouldOptimize(dataLazy)) img.setAttribute("data-lazy", optimize(dataLazy, width)); var dataCfsrc = img.getAttribute("data-cfsrc"); if (dataCfsrc && shouldOptimize(dataCfsrc)) img.setAttribute("data-cfsrc", optimize(dataCfsrc, width)); if (img.hasAttribute("srcset")) { var srcset = img.getAttribute("srcset"); if (srcset) { var firstUrl = srcset.split(",")[0].trim().split(" ")[0]; if (shouldOptimize(firstUrl)) img.removeAttribute("srcset"); } } if (!img.loading || img.loading === "auto") img.loading = "lazy"; img.decoding = "async"; } catch (e) { console.error("❌ خطأ في معالجة صورة:", e); } } function processAll() { var images = document.querySelectorAll("img"); console.log("📊 وجدنا " + images.length + " صورة في الصفحة"); for (var i = 0; i < images.length; i++) processImg(images[i]); console.log("✅ تم تحسين " + count + " صورة"); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", processAll); } else { processAll(); } var observer = new MutationObserver(function (mutations) { var toProcess = []; for (var i = 0; i < mutations.length; i++) { var m = mutations[i]; if (m.type === "childList" && m.addedNodes) { for (var j = 0; j < m.addedNodes.length; j++) { var node = m.addedNodes[j]; if (node.nodeType !== 1) continue; if (node.tagName === "IMG") toProcess.push(node); else if (node.querySelectorAll) { var imgs = node.querySelectorAll("img"); for (var k = 0; k < imgs.length; k++) toProcess.push(imgs[k]); } } } else if (m.type === "attributes" && m.target && m.target.tagName === "IMG") { toProcess.push(m.target); } } if (toProcess.length > 0) { setTimeout(function () { for (var i = 0; i < toProcess.length; i++) processImg(toProcess[i]); }, 100); } }); observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ["src", "data-src", "data-lazy", "data-cfsrc", "srcset"], }); window.addEventListener("salla::loaded", function () { setTimeout(processAll, 1000); }); window.SallaImageOptimizer = { refresh: processAll, stats: function () { return { optimized: count, total: document.querySelectorAll("img").length, format: "WebP" }; }, isActive: function () { return supportsWebP; }, }; console.log("✅ محسّن الصور شغال! اكتب SallaImageOptimizer.stats() للإحصائيات"); } })();