(function () {
const debug = (...args) => {
try { console.log('[Salla Custom JS]', ...args); } catch (e) {}
};
function getLabel(textAr, textEn) {
const isArabic = document.documentElement.lang === 'ar' || document.dir === 'rtl';
return isArabic ? textAr : textEn;
}
function init() {
debug('Execution started');
try {
const buyNowBtn = document.querySelector('a[aria-label="Buy Now Button"]');
if (buyNowBtn) {
buyNowBtn.href = "https://o2organics.com/ar/%D9%81%D9%88%D8%B7-%D8%B5%D8%AD%D9%8A%D8%A9/c1869029752";
debug('Buy Now link updated');
}
} catch (e) { debug('Buy Now error', e); }
try {
const isArabic = document.documentElement.lang === 'ar' || document.dir === 'rtl';
const image = document.querySelector('.contact-section img');
if (isArabic && image) {
image.style.cssText += ';right:auto!important;left:0!important;transform:scaleX(-1)!important;';
debug('RTL image adjusted');
}
} catch (e) { debug('Image error', e); }
try {
const mkyLink = document.querySelector('a[aria-label="Go To MKY Communications"]');
if (mkyLink) {
mkyLink.style.display = "none";
debug('MKY link hidden');
}
} catch (e) { debug('MKY error', e); }
try {
const aboutUsForm = document.querySelector('[data-page-id="1710081791"]');
if (aboutUsForm) {
aboutUsForm.style.display = "none";
debug('About Us form hidden');
const customFormContainer = document.createElement('div');
customFormContainer.innerHTML = `
`;
aboutUsForm.parentNode.insertBefore(customFormContainer, aboutUsForm.nextSibling);
setTimeout(() => {
const form = document.getElementById("contactForm");
form.addEventListener("submit", async function (e) {
e.preventDefault();
const name = document.getElementById("name").value.trim();
const phone = document.getElementById("phone").value.trim();
const email = document.getElementById("email").value.trim();
const quantity = document.getElementById("quantity").value.trim();
const message = document.getElementById("message").value.trim();
// Hide errors
["name", "phone", "email", "quantity", "message"].forEach(id => {
document.getElementById(id + "Error").style.display = "none";
});
let isValid = true;
if (!name) { document.getElementById("nameError").style.display = "block"; isValid = false; }
if (!phone) { document.getElementById("phoneError").style.display = "block"; isValid = false; }
if (!email || !email.includes("@")) { document.getElementById("emailError").style.display = "block"; isValid = false; }
if (!quantity || isNaN(quantity)) { document.getElementById("quantityError").style.display = "block"; isValid = false; }
if (!message) { document.getElementById("messageError").style.display = "block"; isValid = false; }
if (!isValid) return;
const data = { name, phone, email, quantity, message };
try {
await fetch("https://script.google.com/macros/s/AKfycbw17o7vBJK4Y0NIk01mkGSwSvGC1BQmVVxwd2hOt7oKbEwkcD7WA4aA7GP3vBZG-9Ao/exec", {
method: "POST",
mode: 'no-cors',
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
});
alert(getLabel("تم إرسال الرسالة بنجاح!", "Message sent successfully!"));
form.reset();
} catch (err) {
console.error("Send Error:", err);
alert(getLabel("حدث خطأ أثناء إرسال الرسالة.", "There was an error sending your message."));
}
});
}, 100);
}
} catch (e) { debug('Form error', e); }
}
const observer = new MutationObserver(() => {
const foundElements =
document.querySelector('a[aria-label="Buy Now Button"]') &&
document.querySelector('.contact-section img') &&
document.querySelector('a[aria-label="Go To MKY Communications"]') &&
document.querySelector('[data-page-id="1710081791"]');
if (foundElements) {
observer.disconnect();
init();
}
});
observer.observe(document, { childList: true, subtree: true });
setTimeout(() => { observer.disconnect(); init(); }, 3000);
})();