/* Add custom Js code below */
document.addEventListener("DOMContentLoaded", function () {
// ✅ إنشاء اللودر
const loader = document.createElement('div');
loader.id = 'loaderr';
loader.style.cssText = `
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
background: #142c44;
display: flex;
justify-content: center;
align-items: center;
z-index: 999999;
transition: opacity 2s ease; /* ← أبطأ */
`;
// ✅ شكل اللوجو + 4 دواير متحركة
loader.innerHTML = `
×
اهلا بك في متجرنا!
نتمنى لك رحلة تجارة ممتعة🤩
`;
document.body.appendChild(overlay);
// دالة لإخفاء الرسالة وتخزين الحالة
function dismissMessage() {
localStorage.setItem("wpMessageDismissed", "true");
overlay.remove();
}
// زر إغلاق الرسالة
overlay.querySelector(".wp-close").addEventListener("click", dismissMessage);
// لكل زرار، لما يضغط، يخزن الحالة ويحول للينك بدون فتح تاب جديد
overlay.querySelectorAll(".wp-btn").forEach(btn => {
btn.addEventListener("click", function (e) {
e.preventDefault(); // منع الانتقال السريع
dismissMessage();
window.location.href = this.href; // تحويل في نفس الصفحة
});
});
});
document.addEventListener("DOMContentLoaded", function () {
// 1️⃣ إنشاء زر الأيقونة
const infoBtn = document.createElement("div");
infoBtn.innerHTML = `
`;
document.body.appendChild(infoBtn);
// 2️⃣ إنشاء البوكس
const faqBox = document.createElement("div");
faqBox.style.cssText = `
position: fixed;
bottom: 170px;
left: 20px;
width: 300px;
background: #142c44;
border-radius: 16px;
box-shadow: 0 6px 16px white;
padding: 15px;
font-family: sans-serif;
direction: rtl;
display: none;
z-index: 9999;
max-height: 400px;
overflow-y: auto;
`;
// 3️⃣ محتوى الأسئلة
const faqs = [
{ q: "🚚 الشحن والتوصيل", a: "مدة التوصيل من 7-14 يوم عمل حسب موقعك." },
{ q: "💳 الدفع ", a: "نوفر طرق دفع امنة ومتنوعة ." },
{ q: "🎁 المنتجات والإرجاع", a: "كل منتجاتنا أصلية ونوفر سياسة إرجاع سهلة." },
];
faqs.forEach(item => {
const qDiv = document.createElement("div");
qDiv.style.cssText = `
padding: 10px;
border-bottom: 1px solid white;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
font-weight: bold;
color:white;
`;
qDiv.innerHTML = `
${item.q} ⯈ `;
const aDiv = document.createElement("div");
aDiv.textContent = item.a;
aDiv.style.cssText = `
display: none;
padding: 8px;
font-size: 14px;
color: white;
background: #142c44;
border-radius: 8px;
margin-top: 5px;
`;
qDiv.addEventListener("click", () => {
const arrow = qDiv.querySelector("span:last-child");
if (aDiv.style.display === "none") {
aDiv.style.display = "block";
arrow.style.transform = "rotate(90deg)";
} else {
aDiv.style.display = "none";
arrow.style.transform = "rotate(0deg)";
}
});
faqBox.appendChild(qDiv);
faqBox.appendChild(aDiv);
});
document.body.appendChild(faqBox);
// 4️⃣ إظهار/إخفاء البوكس عند الضغط على الأيقونة
infoBtn.addEventListener("click", () => {
faqBox.style.display = faqBox.style.display === "none" ? "block" : "none";
});
});
document.addEventListener("DOMContentLoaded", () => {
const whatsappNumber = "+966509225017";
// إنشاء العنصر العائم
const whatsappFloat = document.createElement("div");
whatsappFloat.className = "whatsapp-float";
// أيقونة الواتساب
const whatsappIcon = document.createElement("img");
whatsappIcon.src = "https://i.ibb.co/wZrVWv1J/image.gif";
whatsappIcon.alt = "WhatsApp";
whatsappIcon.className = "whatsapp-icon";
whatsappIcon.setAttribute("loading", "lazy");
// النافذة المنبثقة
const whatsappPopup = document.createElement("div");
whatsappPopup.className = "whatsapp-popup";
whatsappPopup.style.display = "none";
whatsappPopup.innerHTML = `
`;
// تجميع العناصر
whatsappFloat.appendChild(whatsappPopup);
whatsappFloat.appendChild(whatsappIcon);
document.body.appendChild(whatsappFloat);
// ستايلات الواتساب
const whatsappStyle = document.createElement("style");
whatsappStyle.textContent = `
.whatsapp-float { position: fixed; bottom: 20px; left: 20px; z-index: 10000; }
.whatsapp-icon { width: 80px; height: 80px; cursor: pointer; transition: transform 0.3s; }
.whatsapp-icon:hover { transform: scale(1.1); }
.whatsapp-popup { position: fixed; bottom: 100px; left: 20px; width: 300px; background: #142c44; border-radius: 8px; box-shadow: 0 4px 12px white; z-index: 10001; overflow: hidden; }
.popup-header { display: flex; justify-content: space-between; align-items: center; background-color: black; color: white; padding: 10px; }
.avatar-container { display: flex; align-items: center; }
.avatar-img { width: 40px; height: 40px; border-radius: 50%; margin-right: 10px; }
.support-text { font-size: 16px; font-weight: bold; }
.close-popup { background: none; border: none; font-size: 20px; color: white; cursor: pointer; }
.chat-body { max-height: 300px; overflow-y: auto; padding: 10px; background-color: #e5ddd5; }
.chat-message { margin-bottom: 10px; }
.chat-message.sent { text-align: right; }
.chat-message p { display: inline-block; background: #dcf8c6; padding: 10px; border-radius: 10px; max-width: 80%;color:white; }
.chat-footer { display: flex; align-items: center; padding: 10px; background: white; border-top: 1px solid #ccc; }
.chat-input { flex: 1; padding: 10px; border-radius: 20px; border: 1px solid #ccc; }
.whatsapp-button { background: black; color: white; border: none; border-radius: 50%; width: 50px; height: 50px; display: flex; justify-content: center; align-items: center; margin-left: 10px; cursor: pointer; }
`;
document.head.appendChild(whatsappStyle);
// فتح / إغلاق المحادثة
whatsappIcon.addEventListener("click", () => {
whatsappPopup.style.display = whatsappPopup.style.display === "none" ? "block" : "none";
if (whatsappPopup.style.display === "block") {
const chatBody = document.getElementById("chat-body");
chatBody.innerHTML = `
أهلاً بك! نحن هنا لمساعدتك لو تحتاج ترشيح منتج أرسل رقم "1"
`;
}
});
document.querySelector(".close-popup").addEventListener("click", () => {
whatsappPopup.style.display = "none";
});
// الردود الآلية
function getReply(message) {
const m = message.toLowerCase().trim();
if (m === "1") return "form"; // افتح النموذج
if (m.includes("السلام")) return "وعليكم السلام! كيف يمكنني مساعدتك؟";
if (m.includes("مرحبا")) return "مرحبًا! كيف أقدر أساعدك؟";
return "شكراً لتواصلك! سيتم توجيهك للدعم الفني.";
}
// إرسال رسالة
function sendMessage() {
const input = document.getElementById("whatsapp-message");
const msg = input.value.trim();
if (!msg) return;
const chatBody = document.getElementById("chat-body");
chatBody.innerHTML += `
`;
input.value = "";
setTimeout(() => {
const reply = getReply(msg);
if (reply === "form") {
showProductForm();
} else {
chatBody.innerHTML += `
`;
setTimeout(() => {
window.location.href = `https://wa.me/${whatsappNumber}?text=${encodeURIComponent(msg)}`;
}, 2000);
}
}, 1000);
}
document.getElementById("send-whatsapp").addEventListener("click", sendMessage);
document.getElementById("whatsapp-message").addEventListener("keypress", e => {
if (e.key === "Enter") sendMessage();
});
// نموذج ترشيح منتج
function showProductForm() {
const formDiv = document.createElement("div");
formDiv.id = "product-details";
formDiv.innerHTML = `
أرغب بترشيح منتج
إرسال
إلغاء
`;
formDiv.style.cssText = `
position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
background:#142c44; padding: 20px; border-radius: 15px; z-index: 10002;
box-shadow: 0 0 10px white; width: 320px;
`;
document.body.appendChild(formDiv);
document.getElementById("cancelProductDetails").addEventListener("click", () => {
formDiv.remove();
});
document.getElementById("submitProductDetails").addEventListener("click", () => {
const name = document.getElementById("customerName").value.trim();
const prod = document.getElementById("productName").value.trim();
const link = document.getElementById("productLink").value.trim();
if (name && prod) {
const message = `السلام عليكم، أود ترشيح منتج:\nالاسم: ${name}\nالمنتج: ${prod}\nالرابط: ${link || "غير متوفر"}`;
window.location.href = `https://wa.me/${whatsappNumber}?text=${encodeURIComponent(message)}`;
formDiv.remove();
} else {
alert("يرجى ملء الحقول المطلوبة.");
}
});
}
});