document.addEventListener("DOMContentLoaded", function () {
// =================== 1. جدول المقاسات والتوصيل ===================
const tabsTarget = document.querySelector("#product-tabs-details > div");
if (tabsTarget) {
const html = `
أبها، خميس مشيط: 1 - 2 أيام عمل باقي مدن المملكة: 2-4 أيام عمل الرجاء ملاحظة أنه في ظل ظروف استثنائية، قد يتأثر وقت التوصيل. سيخبركم فريق خدمة العملاء لدينا بأي تأخير قد يحدث.📏 جدول المقاسات
المقاس
طول العباية (إنش)
العرض (إنش)
الكم (إنش)
50 50 21 25 52 52 22 26 54 54 23 27 56 56 24 28 58 58 25 29 60 60 26 30 🚚 التوصيل والإرجاع
أكمِل الطلب قبل انتهاء الوقت!';
cartTimerTarget.parentElement.insertBefore(timerDiv, cartTimerTarget);
let timeLeft = 592;
const interval = setInterval(() => {
const display = document.getElementById("countdown");
if (!display) return clearInterval(interval);
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
display.textContent = `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
if (timeLeft <= 0) {
clearInterval(interval);
timerDiv.innerHTML = "⏳ انتهت المهلة! أعد تحديث الصفحة لإكمال الطلب.";
}
timeLeft--;
}, 1000);
}
// =================== 6. يشتري المنتج الآن ===================
const productOptionsTarget = document.querySelector("#product-tabs-options");
if (productOptionsTarget) {
const faLink = document.createElement("link");
faLink.rel = "stylesheet";
faLink.href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css";
document.head.appendChild(faLink);
const min = 49, max = 94;
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
const wrapper = document.createElement("div");
wrapper.className = "product-view-wrapper";
const box = document.createElement("div");
box.className = "product-view-box";
box.innerHTML = `يشتري هذا المنتج الآن ${randomNumber} شخص`;
wrapper.appendChild(box);
productOptionsTarget.insertAdjacentElement("afterend", wrapper);
}
// =================== 7. بانر الطرحة والنقاب ===================
const metaElements = document.querySelectorAll('meta[property="product:category"]');
const targetCategories = ["ديڤا كولكشن", "عبايات بـ 94 ريال"];
const foundCategory = Array.from(metaElements).some(meta =>
targetCategories.some(cat => meta.content.includes(cat))
);
if (foundCategory) {
const offerTarget = document.querySelector(
".price.my-1"
);
if (offerTarget) {
const banner = document.createElement("div");
banner.className = "custom-offer-banner";
banner.innerHTML = "🎁 طرحة + نقاب هدية مع كل عباية!";
offerTarget.parentNode.insertBefore(banner, offerTarget.nextSibling);
}
}
});
document.addEventListener("DOMContentLoaded", function () {
const imgURL = "https://a.top4top.io/p_3531xbbfm1.jpg";
function addImage() {
const container = document.querySelector('.s-product-options-option-container[data-option-id="477996444"]');
if (container && !container.querySelector(".custom-img-added")) {
const img = document.createElement("img");
img.src = imgURL;
img.alt = "مناديل تنظيف العباية";
img.className = "custom-img-added";
img.style.maxWidth = "150px";
img.style.display = "block";
img.style.margin = "0 auto 10px"; // توسيط الصورة وإضافة مسافة تحتها
// إدخال الصورة قبل الليبل
container.prepend(img);
console.log("✅ تمت إضافة الصورة فوق النص بشكل صحيح");
}
}
// نستخدم MutationObserver لأن العناصر تنرسم متأخر
const observer = new MutationObserver(() => {
addImage();
});
observer.observe(document.body, { childList: true, subtree: true });
});
document.addEventListener("DOMContentLoaded", function () {
// نجيب العنصر اللي نبيه ننقله
var target = document.querySelector(
"#app > div.app-inner.flex.flex-col.min-h-full > div.container.mt-5 > div.flex.flex-col.items-start.lg\\:flex-row > div.main-content.flex-1.w-full > div"
);
// نجيب المكان الجديد (الـ container.mt-5)
var destination = document.querySelector(
"#app > div.app-inner.flex.flex-col.min-h-full > div.container.mt-5"
);
if (target && destination) {
destination.appendChild(target); // ينقله لآخر الـ container
}
});
// إنشاء عنصر الرسالة التوضيحية
document.addEventListener("DOMContentLoaded", () => {
if (location.pathname !== "/cart") return;
const container = document.createElement("div");
container.id = "my-conditional-offer";
container.innerHTML = `