/* Add custom JS code below */
(function () {
var PHONE = "966535618331"; // رقم الواتساب بالصيغة الدولية بدون + أو 00
if (!/\/cart\/?$/.test(location.pathname)) return;
var css =
"#khaled-cart-quote{margin-top:10px;width:100%}" +
"#khaled-cart-quote a{display:flex;align-items:center;justify-content:center;gap:8px;" +
"width:100%;padding:14px 16px;border-radius:8px;font-weight:700;font-size:16px;" +
"text-decoration:none;color:#fff!important;background:#25D366;transition:.2s}" +
"#khaled-cart-quote a:hover{background:#1ebe5a}" +
"#khaled-cart-quote i{font-size:22px;line-height:1}";
var st = document.createElement("style");
st.textContent = css;
document.head.appendChild(st);
function clean(t) { return (t || "").replace(/\s+/g, " ").trim(); }
function buildMessage() {
var lines = ["مرحباً، أريد عرض سعر عن المنتجات التالية:", ""];
var items = document.querySelectorAll("section.cart-item");
items.forEach(function (it, i) {
var a = it.querySelector("h1 a, h2 a, a.text-base");
var name = clean(a && a.textContent);
var qtyEl = it.querySelector("input.s-quantity-input-input, input[name='quantity']");
var qty = (qtyEl && qtyEl.value) || "1";
var link = a ? a.href : "";
lines.push((i + 1) + "- " + name + "\nالكمية: " + qty + (link ? "\n" + link : ""));
});
lines.push("", "رابط السلة: " + location.origin + "/cart");
return lines.join("\n");
}
function build() {
var box = document.createElement("div");
box.id = "khaled-cart-quote";
box.innerHTML =
'' +
'اطلب عرض سعر';
box.querySelector("a").addEventListener("click", function (e) {
e.preventDefault();
window.open("https://wa.me/" + PHONE + "?text=" + encodeURIComponent(buildMessage()), "_blank");
});
return box;
}
function ensure() {
if (document.getElementById("khaled-cart-quote")) return;
var action = document.querySelector(".s-cart-summary-card-action");
if (!action) return;
action.appendChild(build());
}
ensure();
/* السلة بتتعمل لها re-render، فنراقب ونرجّع الزرار لو اتشال */
new MutationObserver(ensure).observe(document.body, { childList: true, subtree: true });
})();
/* Add custom JS code below */
(function () {
/* ====== إعدادات ====== */
var PHONE = "966535618331"; // رقم واتساب متجرك بالصيغة الدولية بدون + أو 00
var HIDE_PRICE = false; // true = يخفي السعر
/* يشتغل في صفحات المنتج بس */
if (!/\/p\d+\/?$/.test(location.pathname)) return;
function init() {
if (document.getElementById("khaled-quote-box")) return;
var h1 = document.querySelector("h1");
var og = document.querySelector('meta[property="og:title"]');
var name = (h1 && h1.textContent.trim()) || (og && og.content) || document.title;
var url = location.origin + location.pathname;
var text = "مرحباً، أريد عرض سعر عن: " + name + "\nرابط الصفحة: " + url;
var link = "https://wa.me/" + PHONE + "?text=" + encodeURIComponent(text);
var box = document.createElement("div");
box.id = "khaled-quote-box";
box.innerHTML =
'' +
'اطلب عرض سعر';
/* الإدراج بعد زر الإضافة للسلة الطبيعي */
var anchor =
document.querySelector("salla-add-product-button") ||
document.querySelector(".product-form") ||
h1;
if (!anchor) return;
anchor.parentNode.insertBefore(box, anchor.nextSibling);
}
/* الستايل */
var css = "\
#khaled-quote-box{display:flex;flex-direction:column;gap:10px;margin:12px 0;width:100%}\
#khaled-quote-box .kq-btn{display:flex;align-items:center;justify-content:center;gap:8px;\
width:100%;padding:14px 16px;border-radius:8px;font-weight:700;font-size:16px;\
text-decoration:none;color:#fff!important;transition:.2s}\
#khaled-quote-box .kq-quote{background:#25D366}\
#khaled-quote-box .kq-quote:hover{background:#1ebe5a}\
#khaled-quote-box .kq-quote i{font-size:22px;line-height:1}";
if (HIDE_PRICE) {
css += ".product-price,.product-entry__price,.total-price,.before-price{display:none!important}";
}
var st = document.createElement("style");
st.textContent = css;
document.head.appendChild(st);
var tries = 0;
var timer = setInterval(function () {
init();
if (document.getElementById("khaled-quote-box") || ++tries > 20) clearInterval(timer);
}, 400);
})();