/* بداية كود مميزات المتجر وعلامات الثقة */
(() => {
const target = document.querySelector('.flex.bg-white.p-5.sm\\:pb-0.rounded-md.rounded-b-none');
if (!target) return;
const paymentIcon = ``;
const replacementIcon = ``;
const returnIcon = ``;
const box = document.createElement('div');
box.innerHTML = `
${paymentIcon}
دفع آمن ومشفر
${replacementIcon}
30 يوم استبدال
${returnIcon}
30 يوم استرجاع
`;
target.insertAdjacentElement('beforebegin', box);
})();
/* نهاية كود مميزات المتجر وعلامات الثقة */
/* بداية كود رابط دليل المقاسات */
(() => {
const requiredOptionName = 'مقاس البسطار';
function addFeaturesBox(container) {
if (document.querySelector('.size-info')) return;
const box = document.createElement('div');
box.className = 'size-info salla-product-option';
box.style.direction = 'rtl';
box.style.marginTop = '15px';
box.innerHTML = `
`;
container.appendChild(box);
}
function tryInject() {
const allLabels = document.querySelectorAll('.s-product-options-option-label b');
for (const label of allLabels) {
if (label.textContent.includes(requiredOptionName)) {
const container = label.closest('.s-product-options-option-container');
if (container) {
addFeaturesBox(container);
return true;
}
}
}
return false;
}
if (!tryInject()) {
const targetContainer = document.querySelector('.product-option-selector, .s-product-options-wrapper') || document.body;
const observer = new MutationObserver((mutations, obs) => {
if (tryInject()) {
obs.disconnect();
}
});
observer.observe(targetContainer, { childList: true, subtree: true });
}
})();
/* نهاية كود رابط دليل المقاسات */
/* بداية كود قسم الأكثر مبيعاً مع الاستثناء */
(() => {
'use strict';
const excludedCategory = "gAqjBj";
const excludedCategoryName = "المشتريات والتوريدات الحكومية";
const mainContainerSelector = '.s-products-list-wrapper.s-products-list-filters-results';
const productItemSelector = '.s-product-card-entry.s-product-card-vertical.s-product-card-fit-height';
const filterSelectId = 'product-filter';
function isExcludedPage() {
if (window.location.href.includes('/category/' + excludedCategory)) return true;
const breadcrumbs = document.querySelectorAll('.breadcrumb a, .breadcrumb span, [class*="breadcrumb"] a, [class*="breadcrumb"] span');
for (const item of breadcrumbs) {
if (item.textContent.trim() === excludedCategoryName) return true;
}
return false;
}
function removeTopSellingAndRestore() {
const section = document.querySelector('.top-selling-section');
if (section) {
const grid = section.querySelector('.top-selling-grid');
const mainContainer = document.querySelector(mainContainerSelector);
if (grid && mainContainer) {
const movedProducts = grid.querySelectorAll(productItemSelector);
movedProducts.forEach(card => {
mainContainer.insertBefore(card, mainContainer.firstChild);
});
}
section.remove();
}
}
function setFilterToBestSell() {
if (isExcludedPage()) return false;
const filter = document.getElementById(filterSelectId);
if (!filter) return false;
if (filter.value !== 'bestSell') {
filter.value = 'bestSell';
filter.dispatchEvent(new Event('change', { bubbles: true }));
return true;
}
return true;
}
function createTopSellingSection() {
if (isExcludedPage()) {
removeTopSellingAndRestore();
return;
}
if (document.querySelector('.top-selling-section')) return;
const mainContainer = document.querySelector(mainContainerSelector);
if (!mainContainer) return;
const allProducts = mainContainer.querySelectorAll(productItemSelector);
if (allProducts.length === 0) return;
const section = document.createElement('div');
section.className = 'top-selling-section';
section.innerHTML = `
الأكثر مبيعاً
`;
const grid = section.querySelector('.top-selling-grid');
const topThreeToMove = Array.from(allProducts).slice(0, 3);
topThreeToMove.forEach(card => {
grid.appendChild(card);
const images = card.querySelectorAll('img');
images.forEach(img => {
if (img.dataset.src) { img.src = img.dataset.src; }
if (img.dataset.srcset) { img.srcset = img.dataset.srcset; }
img.classList.remove('lazy', 'lazyloading');
img.classList.add('lazyloaded');
img.style.opacity = '1';
});
});
mainContainer.before(section);
}
const observer = new MutationObserver(() => {
if (isExcludedPage()) {
removeTopSellingAndRestore();
return;
}
const mainContainer = document.querySelector(mainContainerSelector);
if (!mainContainer) return;
const products = mainContainer.querySelectorAll(productItemSelector);
if (products.length > 0 && mainContainer.offsetHeight > 0) {
setFilterToBestSell();
if (!document.querySelector('.top-selling-section')) {
createTopSellingSection();
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
})();
/* نهاية كود قسم الأكثر مبيعاً مع الاستثناء */
/* بداية كود تغيير إضافة للسلة الى عرض سعر في كروت المنتجات */
(() => {
'use strict';
const newButtonText = "طلب عرض سعر";
function applyExactCardInterception() {
const productCards = document.querySelectorAll('custom-salla-product-card');
for (let i = 0; i < productCards.length; i++) {
const card = productCards[i];
if (card.querySelector('.custom-card-quote-btn')) continue;
const sallaAddBtn = card.querySelector('salla-add-product-button');
if (!sallaAddBtn) continue;
const productType = sallaAddBtn.getAttribute('product-type');
if (productType === 'service' || productType === 'digital') {
const titleElement = card.querySelector('.s-product-card-content-title a');
if (!titleElement) continue;
const productUrl = titleElement.href;
const footerSpace = card.querySelector('.s-product-card-content-footer');
if (footerSpace) {
footerSpace.style.position = 'relative';
const customOverlayBtn = document.createElement('a');
customOverlayBtn.href = productUrl;
customOverlayBtn.className = 'custom-card-quote-btn s-button-primary-outline';
customOverlayBtn.innerHTML = `
${newButtonText}
`;
customOverlayBtn.addEventListener('click', (e) => {
e.stopPropagation();
});
footerSpace.appendChild(customOverlayBtn);
card.dataset.quoteOverlayApplied = 'true';
}
}
}
}
const startObserver = () => {
const observer = new MutationObserver(applyExactCardInterception);
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['product-type', 'class']
});
applyExactCardInterception();
};
if (document.body) {
startObserver();
} else {
document.addEventListener('DOMContentLoaded', startObserver);
}
})();
/* نهاية كود تغيير إضافة للسلة الى عرض سعر في كروت المنتجات */
/* بداية كود استبدال زر السلة في صفحة المنتج بزر عرض سعر */
(() => {
'use strict';
const targetCategoryCode = "gAqjBj";
const targetCategoryName = "المشتريات والتوريدات الحكومية";
const quotationText = "طلب عرض سعر";
function isProductInTargetCategory() {
const schemas = document.querySelectorAll('script[type="application/ld+json"]');
for (const script of schemas) {
try {
const text = script.innerText;
if (text.includes('/category/' + targetCategoryCode) || text.includes(`"name": "${targetCategoryName}"`)) {
return true;
}
} catch (e) {}
}
const breadcrumbs = document.querySelectorAll('.breadcrumb a, .breadcrumb span, [class*="breadcrumb"] a, [class*="breadcrumb"] span');
for (const item of breadcrumbs) {
if (item.textContent.trim() === targetCategoryName) return true;
}
return false;
}
function applyQuotationFlow() {
if (!isProductInTargetCategory()) return;
if (!document.getElementById('custom-fast-quote-style')) {
const style = document.createElement('style');
style.id = 'custom-fast-quote-style';
style.innerHTML = `
.product-single__aside section.flex.bg-white.p-5.sm\\:pb-0.rounded-md.rounded-b-none,
.form.product-form section.flex.bg-white.p-5.sm\\:pb-0.rounded-md.rounded-b-none,
.product-single__aside .sticky-product-bar__quantity,
.form.product-form .sticky-product-bar__quantity {
display: none !important;
}
.product-single__aside salla-add-product-button salla-button,
.form.product-form salla-add-product-button salla-button {
display: none !important;
opacity: 0 !important;
visibility: hidden !important;
}
.product-single__aside salla-mini-checkout-widget,
.product-single__aside .s-add-product-button-mini-checkout,
.form.product-form salla-mini-checkout-widget,
.form.product-form .s-add-product-button-mini-checkout {
width: 100% !important;
display: block !important;
position: relative !important;
}
.product-single__aside salla-mini-checkout-widget::after,
.form.product-form salla-mini-checkout-widget::after {
content: "${quotationText}";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #ebc607 !important;
color: #000000 !important;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 16px;
border-radius: 6px;
box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
z-index: 99999 !important;
pointer-events: none !important;
}
`;
document.head.appendChild(style);
}
}
const startProductObserver = () => {
const productFormContainer = document.querySelector('.product-single__aside, .form.product-form') || document.body;
const observer = new MutationObserver(applyQuotationFlow);
observer.observe(productFormContainer, { childList: true, subtree: true });
applyQuotationFlow();
};
if (document.body) {
startProductObserver();
} else {
document.addEventListener('DOMContentLoaded', startProductObserver);
}
})();
/* نهاية كود استبدال زر السلة في صفحة المنتج بزر عرض سعر */
/* بداية كود وسائل الدفع الموحد (المنتج والفوتر) */
(() => {
const paymentMethods = [
{ name: 'Mada', fileName: 'mada.png' },
{ name: 'Credit Card', fileName: 'credit_card.png' },
{ name: 'Mastercard',
svg: ''
},
{ name: 'Bank Transfer', fileName: 'bank.png' },
{ name: 'STC Pay', fileName: 'stc_pay.png' },
{ name: 'Apple Pay', fileName: 'apple_pay.png' },
{ name: 'Tamara', fileName: 'tamara_installment.png' },
{ name: 'Google Pay', fileName: 'google_pay.png' },
];
const imageBaseUrl = 'https://mahally.com/images/payments/';
const productTarget = document.querySelector('.form.product-form');
if (productTarget) {
const productListHTML = paymentMethods.map(method => {
let content = method.svg ? method.svg : `
`;
return `${content}`;
}).join('');
const productWrapper = document.createElement('div');
productWrapper.className = 'custom-payment-wrapper';
productWrapper.innerHTML = ``;
productTarget.insertAdjacentElement('afterend', productWrapper);
}
if (!document.getElementById('hide-salla-payments-style')) {
const style = document.createElement('style');
style.id = 'hide-salla-payments-style';
style.innerHTML = `
salla-payments.s-payments-list-wrap,
.s-payments-list-wrap,
salla-payments[class*="s-payments"] {
display: none !important;
opacity: 0 !important;
visibility: hidden !important;
height: 0 !important;
overflow: hidden !important;
}
`;
document.head.appendChild(style);
}
function fixFooterPayments() {
const originalWrap = document.querySelector('salla-payments, .s-payments-list-wrap');
if (!originalWrap) return false;
if (document.querySelector('.custom-payment-wrapper-2')) return true;
const footerListHTML = paymentMethods.map(method => {
let content = method.svg ? method.svg : `
`;
return `${content}`;
}).join('');
const footerWrapper = document.createElement('div');
footerWrapper.className = 'custom-payment-wrapper-2';
footerWrapper.innerHTML = ``;
originalWrap.insertAdjacentElement('afterend', footerWrapper);
return true;
}
if (!fixFooterPayments()) {
const footerObserver = new MutationObserver((mutations, obs) => {
if (fixFooterPayments()) {
obs.disconnect();
}
});
footerObserver.observe(document.body, {
childList: true,
subtree: true
});
}
})();
/* نهاية كود وسائل الدفع الموحد */