/* Add custom Js styles below */
/* =========================================================
1) إشعارات وهمية (عدد الزوار الآن)
يظهر أسفل الشاشة ويعطي إحساس نشاط حقيقي
========================================================= */
(function(){
const CFG = {
min: 86,
max: 3451,
position: 'br',
firstShowAfter: [1800, 4200],
visibleFor: [5200, 8200],
hiddenFor: [9000, 15000],
updateEvery: [3800, 6200],
step: [2, 16],
upBias: 0.62,
rareJumpChance: 0.05,
rareJump: [18, 55],
excludePaths: ['cart','checkout','payment','thank','success'],
title: 'نشاط مباشر',
subtitle: 'يشاهدون هذا الآن',
};
const rand = (a,b)=> Math.floor(Math.random()*(b-a+1))+a;
const pick = ([a,b])=> rand(a,b);
if (CFG.excludePaths.some(p => location.pathname.includes(p))) return;
const toast = document.createElement('div');
toast.className = "fv-toast";
toast.innerHTML = `
${CFG.title} ·
${CFG.subtitle}
`;
document.body.appendChild(toast);
const countEl = document.getElementById("fvCount");
let current = rand(120,260);
function update(){
current += (Math.random() < CFG.upBias ? 1 : -1) * rand(2,16);
current = Math.max(CFG.min, Math.min(CFG.max, current));
countEl.textContent = current;
}
function show(){
toast.style.display = "block";
update();
setTimeout(hide, pick(CFG.visibleFor));
}
function hide(){
toast.style.display = "none";
setTimeout(show, pick(CFG.hiddenFor));
}
setTimeout(show, pick(CFG.firstShowAfter));
})();
/* =========================================================
2) مزايا المنتج (تحت الوصف)
تغليف – شحن – ضمان + زر واتساب
========================================================= */
(function () {
const phone = "966559715165";
function getProductName() {
const h1 = document.querySelector("h1");
return h1 ? h1.textContent.trim() : "";
}
function item(icon, title, sub) {
return `
`;
}
function createSection() {
const section = document.createElement("section");
section.id = "elite-benefits";
section.innerHTML = `
مزايا تليق بذوقك
${item("✨","تغليف فاخر مجاني","لمسة راقية")}
${item("📦","شحن سريع","24–72 ساعة")}
${item("✨","جودة عالية","منتج مختار بعناية")}
تواصل واتساب
`;
return section;
}
function inject() {
if (document.getElementById("elite-benefits")) return;
const desc = document.querySelector('[class*="description"]');
if (!desc) return;
desc.insertAdjacentElement("afterend", createSection());
}
new MutationObserver(inject).observe(document.body,{childList:true,subtree:true});
inject();
})();
// الشحن والاستفسار عن الشحن
/* =========================================================
استفسار الشحن الاحترافي
يظهر 3 ثواني ثم يختفي، ويرجع بعد 6-7 ثواني
عند الضغط يفتح خيارات: داخل الرياض / خارج الرياض
========================================================= */
(function () {
if (window.__AF_SHIPPING_WIDGET__) return;
window.__AF_SHIPPING_WIDGET__ = true;
const WA = "966559715165";
function openWhatsApp(text) {
window.open(
"https://wa.me/" + WA + "?text=" + encodeURIComponent(text + "\n\nالرابط: " + location.href),
"_blank"
);
}
function createWidget() {
const chip = document.createElement("div");
chip.className = "af-ship-chip";
chip.innerHTML = "🚚 استفسار الشحن";
const overlay = document.createElement("div");
overlay.className = "af-ship-overlay";
const sheet = document.createElement("div");
sheet.className = "af-ship-sheet";
sheet.innerHTML = `
تفاصيل الشحن
`;
document.body.appendChild(chip);
document.body.appendChild(overlay);
document.body.appendChild(sheet);
const main = sheet.querySelector(".af-step-main");
const riyadh = sheet.querySelector(".af-step-riyadh");
const delegate = sheet.querySelector(".af-step-delegate");
const summary = sheet.querySelector(".af-summary");
const summaryText = sheet.querySelector(".af-summary-text");
let finalMsg = "";
function showOnly(el) {
[main, riyadh, delegate, summary].forEach(x => x.style.display = "none");
el.style.display = "grid";
}
function openSheet() {
chip.classList.add("af-chip-stop");
overlay.classList.add("show");
sheet.classList.add("show");
showOnly(main);
}
function closeSheet() {
overlay.classList.remove("show");
sheet.classList.remove("show");
}
function showSummary(text) {
finalMsg = text;
summaryText.innerHTML = text;
showOnly(summary);
}
chip.onclick = openSheet;
overlay.onclick = closeSheet;
sheet.querySelector(".af-close").onclick = closeSheet;
sheet.querySelector('[data-area="riyadh"]').onclick = () => showOnly(riyadh);
sheet.querySelector('[data-area="outside"]').onclick = () => {
showSummary("خارج الرياض • شركة توصيل • 24–94 ساعة");
};
sheet.querySelector('[data-type="company"]').onclick = () => {
showSummary("داخل الرياض • شركة توصيل عادي • 24–60 ساعة");
};
sheet.querySelector('[data-type="delegate"]').onclick = () => showOnly(delegate);
sheet.querySelector(".af-back").onclick = () => showOnly(main);
sheet.querySelector(".af-back-riyadh").onclick = () => showOnly(riyadh);
sheet.querySelector(".af-edit").onclick = () => showOnly(main);
sheet.querySelectorAll(".af-result").forEach(btn => {
btn.onclick = () => showSummary(btn.dataset.msg);
});
sheet.querySelector(".af-wa").onclick = () => {
openWhatsApp("استفسار عن الشحن:\n" + finalMsg);
};
}
createWidget();
})();
/* تأخير ظهور الإشعارات الوهمية + استفسار الشحن 15 إلى 20 ثانية */
(function(){
document.body.classList.add("af-delay-widgets");
const style = document.createElement("style");
style.textContent = `
body.af-delay-widgets .fv-toast,
body.af-delay-widgets .af-ship-chip{
display:none !important;
opacity:0 !important;
visibility:hidden !important;
}
`;
document.head.appendChild(style);
const delay = Math.floor(Math.random() * (20000 - 15000 + 1)) + 15000;
setTimeout(function(){
document.body.classList.remove("af-delay-widgets");
}, delay);
})();
/* مزامنة ظهور واختفاء (الزوار + الشحن) */
(function(){
function showBoth(){
const toast = document.querySelector(".fv-toast");
const chip = document.querySelector(".af-ship-chip");
if (toast){
toast.classList.remove("fv-hide");
toast.classList.add("fv-show");
}
if (chip){
chip.style.opacity = "1";
chip.style.transform = "translateY(0)";
}
}
function hideBoth(){
const toast = document.querySelector(".fv-toast");
const chip = document.querySelector(".af-ship-chip");
if (toast){
toast.classList.remove("fv-show");
toast.classList.add("fv-hide");
}
if (chip){
chip.style.opacity = "0";
chip.style.transform = "translateY(15px)";
}
}
function cycle(){
showBoth();
setTimeout(()=>{
hideBoth();
// يرجع بعد 7 ثواني
setTimeout(cycle, 7000);
}, 5000); // مدة الظهور
}
// يبدأ بعد 15 ثانية
setTimeout(cycle, 15000);
})();
/* يخفي زر استفسار الشحن بعد إغلاق نافذة الشحن */
(function(){
document.addEventListener("click", function(e){
const isClose =
e.target.closest(".af-close") ||
e.target.closest(".af-ship-overlay");
if (!isClose) return;
const chip = document.querySelector(".af-ship-chip");
if (chip){
chip.classList.remove("af-chip-stop");
chip.style.opacity = "0";
chip.style.visibility = "hidden";
chip.style.pointerEvents = "none";
chip.style.transform = "translateY(15px)";
}
}, true);
})();
/* حل احترافي: إخفاء زر الشحن مؤقت بعد الإغلاق ويرجع */
(function(){
function hideChip(){
const chip = document.querySelector(".af-ship-chip");
if(!chip) return;
chip.style.opacity = "0";
chip.style.pointerEvents = "none";
// يرجع بعد 6 ثواني
setTimeout(()=>{
chip.style.opacity = "1";
chip.style.pointerEvents = "auto";
}, 6000);
}
// زر X
document.addEventListener("click", function(e){
if(e.target.closest(".af-close")){
hideChip();
}
});
// الضغط خارج النافذة
document.addEventListener("click", function(e){
if(e.target.closest(".af-ship-overlay")){
hideChip();
}
});
})();
/* =========================================================
تأخير ظهور زر الشحن بعد الإغلاق (20 ثانية)
========================================================= */
(function(){
let delayAfterClose = false;
function hideChipWithDelay(){
const chip = document.querySelector(".af-ship-chip");
if(!chip) return;
// اخفاء
chip.style.opacity = "0";
chip.style.pointerEvents = "none";
delayAfterClose = true;
// يرجع بعد 20 ثانية
setTimeout(()=>{
chip.style.opacity = "1";
chip.style.pointerEvents = "auto";
delayAfterClose = false;
}, 20000);
}
// زر X
document.addEventListener("click", function(e){
if(e.target.closest(".af-close")){
hideChipWithDelay();
}
});
// الضغط خارج النافذة
document.addEventListener("click", function(e){
if(e.target.closest(".af-ship-overlay")){
hideChipWithDelay();
}
});
})();
/* تحويل مواصفات الوصف إلى بطاقات */
(function(){
function runSpecs(){
if(document.querySelector(".af-specs")) return;
const desc =
document.querySelector(".product__description") ||
document.querySelector(".product-description") ||
document.querySelector("[class*='description']") ||
document.querySelector("[class*='Description']");
if(!desc) return;
const text = desc.innerText || "";
if(!text.includes(":") && !text.includes(":")) return;
const lines = text.split(/\n+/).filter(line => line.includes(":") || line.includes(":"));
if(!lines.length) return;
let html = ``;
lines.forEach(line=>{
const parts = line.split(/:|:/);
if(parts.length < 2) return;
html += `
${parts[0].trim()}
${parts.slice(1).join(":").trim()}
`;
});
html += `
`;
desc.insertAdjacentHTML("afterend", html);
}
setInterval(runSpecs, 1000);
})();