// إضافة شارة أصلي 100% وأقل سعر تحت variant-inventory
function addAuthenticBadge() {
// البحث عن العنصر المستهدف
const variantInventory = document.querySelector('#variant-inventory');
if (!variantInventory) {
return;
}
// التحقق من وجود الشارة مسبقاً لتجنب التكرار
const existingBadge = document.querySelector('.authentic-badge-container');
if (existingBadge) {
return;
}
// إنشاء العنصر الجديد
const badgeContainer = document.createElement('div');
badgeContainer.className = 'authentic-badge-container';
// إضافة المحتوى
badgeContainer.innerHTML = `
أصلي %100
أقل سعر بالسوق حتي الآن
`;
// إدراج العنصر الجديد بعد variant-inventory
variantInventory.insertAdjacentElement('afterend', badgeContainer);
}
// إنشاء شريط معلومات المنتج داخل الـ sticky product bar
function createProductInfoBar() {
// البحث عن العنصر المستهدف
const stickyProductBar = document.querySelector('.product-single .sticky-product-bar');
const quantityDiv = document.querySelector('.sticky-product-bar__quantity');
if (!stickyProductBar || !quantityDiv) {
return;
}
// التحقق من وجود الشريط مسبقاً لتجنب التكرار
const existingInfoBar = document.querySelector('.product-info-bar');
if (existingInfoBar) {
return;
}
// إنشاء العنصر الجديد
const productInfoBar = document.createElement('div');
productInfoBar.className = 'product-info-bar';
// إضافة المحتوى والأيقونات
productInfoBar.innerHTML = `
زمن التوصيل داخل تبوك : خلال 24 ساعة
زمن التوصيل خارج تبوك : خلال 3 ايام
ضمان ذهبي: استرجاع كامل المبلغ إذا كان المنتج غير أصلي
`;
// إدراج العنصر الجديد بعد الـ quantity div داخل الـ sticky product bar
quantityDiv.insertAdjacentElement('afterend', productInfoBar);
}
// إضافة جميع الستايلات
function addAllStyles() {
if (document.querySelector('#combined-styles')) {
return;
}
const allStyles = `
`;
document.head.insertAdjacentHTML('beforeend', allStyles);
}
// تشغيل جميع الوظائف عند تحميل الصفحة
function initAllElements() {
addAllStyles();
addAuthenticBadge();
createProductInfoBar();
}
// تشغيل عند تحميل الصفحة
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initAllElements);
} else {
initAllElements();
}
// مراقب واحد للتغييرات الديناميكية
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length > 0) {
// فحص شارة أصلي 100%
const variantInventory = document.querySelector('#variant-inventory');
const existingBadge = document.querySelector('.authentic-badge-container');
if (variantInventory && !existingBadge) {
setTimeout(addAuthenticBadge, 500);
}
// فحص شريط المعلومات
const stickyBar = document.querySelector('.product-single .sticky-product-bar');
const quantityDiv = document.querySelector('.sticky-product-bar__quantity');
const existingInfoBar = document.querySelector('.product-info-bar');
if (stickyBar && quantityDiv && !existingInfoBar) {
setTimeout(createProductInfoBar, 500);
}
}
});
});
// بدء المراقبة
observer.observe(document.body, {
childList: true,
subtree: false
});
// دالة تنظيف شاملة للعناصر المكررة
function cleanupDuplicates() {
// تنظيف شارات أصلي 100%
const allBadges = document.querySelectorAll('.authentic-badge-container');
if (allBadges.length > 1) {
for (let i = 1; i < allBadges.length; i++) {
allBadges[i].remove();
}
}
// تنظيف أشرطة المعلومات
const allInfoBars = document.querySelectorAll('.product-info-bar');
if (allInfoBars.length > 1) {
for (let i = 1; i < allInfoBars.length; i++) {
allInfoBars[i].remove();
}
}
}
// تشغيل التنظيف بعد التحميل
setTimeout(cleanupDuplicates, 1000);