// إضافة نسبة الخصم في قائمة المنتجات
var productItems = document.getElementsByClassName("product-item");
Array.from(productItems).forEach(function(item) {
var priceBefore = item.querySelector("div.product-info > div > span.currency-value.before > span.value");
var priceAfter = item.querySelector("div.product-info > div > span.currency-value.after > span.value");
if (priceBefore && priceAfter) {
var priceBeforeValue = parseFloat(priceBefore.textContent.replace(/,/g, ''));
var priceAfterValue = parseFloat(priceAfter.textContent.replace(/,/g, ''));
if (!isNaN(priceBeforeValue) && !isNaN(priceAfterValue) && priceBeforeValue > 0) {
var discountPercentage = Math.round((100 - (priceAfterValue * 100) / priceBeforeValue));
var discountPP = document.createElement("span");
discountPP.classList.add("discount_pp");
discountPP.textContent = discountPercentage + "%";
item.style.position = "relative";
item.appendChild(discountPP);
}
}
});
// إضافة نجوم التقييم بعد عناوين المنتجات
const productTitles = document.querySelectorAll(".products-grid .product-item .product-details h3");
productTitles.forEach(function(title) {
const rating = document.createElement("div");
rating.classList.add("star-rating");
rating.innerHTML = '★★★★★';
title.parentNode.insertBefore(rating, title.nextSibling);
});
// إضافة تأثير الاهتزاز لزر الإرسال في صفحة المنتج الفردي
var singleSubmit = document.querySelector('.single-product .single-submit');
if (singleSubmit) {
setInterval(function(){
singleSubmit.classList.toggle('shaked');
}, 5000);
}
});