/* كود عرض البراند */
document.addEventListener("DOMContentLoaded", function () {
const brandAnchor = document.querySelector('a[href*="/brand-"] img.object-contain');
let linkUrl;
if (brandAnchor && brandAnchor.parentElement.tagName === 'A') {
linkUrl = brandAnchor.parentElement.href;
} else {
const brandName = brandAnchor?.getAttribute('alt') || brandAnchor?.getAttribute('title') || 'brand';
const brandSlug = brandName.toLowerCase().replace(/\s+/g, '-');
linkUrl = window.location.origin + '/' + brandSlug;
}
const box = document.createElement("div");
box.className = "brand-box";
box.innerHTML = `
`;
const parent = brandAnchor.parentElement;
parent.insertAdjacentElement('afterend', box);
brandAnchor.remove();
});
/* كود عرض الوصف*/
document.addEventListener("DOMContentLoaded", () => {
const descArticle = document.querySelector('.product__description article');
if (!descArticle) return;
const paragraphs = Array.from(descArticle.querySelectorAll('p'));
if (paragraphs.length === 0) return;
const existingTable = descArticle.querySelector('table');
if (existingTable) existingTable.remove();
const table = document.createElement('table');
table.style.width = '100%';
table.style.borderCollapse = 'collapse';
table.style.marginTop = '10px';
table.style.fontFamily = "'Tajawal', sans-serif";
table.style.fontSize = '14px';
table.style.color = '#333';
paragraphs.forEach(p => {
const text = p.textContent.trim();
if (text) {
const tr = document.createElement('tr');
const td = document.createElement('td');
td.style.border = '1px solid #ccc';
td.style.padding = '8px';
td.textContent = text;
tr.appendChild(td);
table.appendChild(tr);
}
});
descArticle.innerHTML = '';
descArticle.appendChild(table);
});
/* كود الواتس اب */
const style = document.createElement('style');
style.textContent = `
#whatsapp-button {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #25D366;
color: white;
border-radius: 50%;
width: 60px;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
font-size: 30px;
cursor: pointer;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
z-index: 9999;
transition: background-color 0.3s ease;
}
#whatsapp-button:hover {
background-color: #1ebe57;
}
`;
document.head.appendChild(style);
const whatsappButton = document.createElement('div');
whatsappButton.id = 'whatsapp-button';
whatsappButton.title = 'تواصل عبر واتساب';
whatsappButton.innerHTML = `
`;
const phoneNumber = '966592328585';
whatsappButton.addEventListener('click', () => {
window.open(`https://wa.me/${phoneNumber}`, '_blank');
});
document.body.appendChild(whatsappButton);