Limited Time Offer
00 Hours
00 Minutes
00 Seconds
document.addEventListener("DOMContentLoaded", async function () {
if (document.body.classList.contains("editor_enable")) return;
// ============================================
// 🌍 إعدادات المخزون - متاح في مصر فقط
// ============================================
// مفيش variants - المنتج متاح في مصر فقط، Out of Stock في السعودية
const STOCK_RULES = {
'EG': true, // متاح في مصر
'SA': false // Out of Stock في السعودية
};
// ============================================
// 💰 إعدادات الأسعار
// ============================================
const MANUAL_PRICES = {
'EG': {
originalPrice: "2000",
currentPrice: "999",
},
'SA': {
// السعودية - Out of Stock ومفيش سعر
originalPrice: null,
currentPrice: null,
}
};
// ============================================
// 🌍 تحديد الدولة من IP
// ============================================
async function detectUserCountry() {
console.log('🔍 Starting country detection...');
try {
try {
console.log('🌐 Checking IP via ipapi.co...');
const ipResponse = await fetch('https://ipapi.co/json/', {
method: 'GET',
cache: 'no-cache'
});
if (ipResponse.ok) {
const ipData = await ipResponse.json();
console.log('📍 IP Data:', ipData);
if (ipData.country_code) {
const country = ipData.country_code === 'SA' ? 'SA' : 'EG';
console.log('✅ Country from IP:', country, '(' + ipData.country_name + ')');
return country;
}
}
} catch (e) {
console.warn('⚠️ IP detection failed:', e.message);
}
try {
console.log('🌐 Checking Odoo GeoIP...');
const response = await fetch('/shop/country_infos/get');
if (response.ok) {
const data = await response.json();
if (data && data.country_code) {
console.log('✅ Country from Odoo GeoIP:', data.country_code);
return data.country_code === 'SA' ? 'SA' : 'EG';
}
}
} catch (e) {
console.warn('⚠️ Odoo GeoIP failed');
}
const urlParams = new URLSearchParams(window.location.search);
const countryParam = urlParams.get('country');
if (countryParam) {
console.log('✅ Country from URL:', countryParam);
return countryParam.toUpperCase() === 'SA' ? 'SA' : 'EG';
}
const odooLang = document.documentElement.lang || '';
if (odooLang.includes('SA') || odooLang === 'ar_SA' || odooLang === 'en_SA') {
console.log('✅ Saudi Arabia (from lang)');
return 'SA';
}
const priceText = document.body.innerText;
if (priceText.includes('SAR') || priceText.includes('ريال سعودي')) {
console.log('✅ Saudi Arabia (from currency)');
return 'SA';
}
} catch (error) {
console.error('❌ Error detecting country:', error);
}
console.log('✅ Default: Egypt');
return 'EG';
}
const userCountry = await detectUserCountry();
const htmlLang = (document.documentElement.lang || '').toLowerCase();
const currentLang = htmlLang.includes('en') ? 'en' : 'ar';
console.log('🌍 Final Country:', userCountry);
console.log('🌐 Language:', currentLang);
// ============================================
// 💰 إعدادات العملة والترجمة
// ============================================
const CONFIG = {
'SA': {
symbolAr: 'ريال',
symbolEn: 'SAR',
translations: {
ar: {
offerText: 'عرض محدود !',
buyNow: 'اشترِ الآن',
addToCart: 'أضف للسلة',
outOfStock: 'نفذت الكمية',
ratings: 'تقييم',
hours: 'ساعة',
minutes: 'دقيقة',
seconds: 'ثانية'
},
en: {
offerText: 'Limited Time Offer',
buyNow: 'Buy Now',
addToCart: 'Add to Cart',
outOfStock: 'Out of Stock',
ratings: 'ratings',
hours: 'Hours',
minutes: 'Minutes',
seconds: 'Seconds'
}
}
},
'EG': {
symbolAr: 'جنيه',
symbolEn: 'EGP',
translations: {
ar: {
offerText: 'عرض محدود !',
buyNow: 'اشترِ دلوقتي',
addToCart: 'اشترِ دلوقتي',
outOfStock: 'نفذت الكمية',
ratings: 'تقييم',
hours: 'ساعة',
minutes: 'دقيقة',
seconds: 'ثانية'
},
en: {
offerText: 'Limited Time Offer',
buyNow: 'Buy Now',
addToCart: 'Add to Cart',
outOfStock: 'Out of Stock',
ratings: 'ratings',
hours: 'Hours',
minutes: 'Minutes',
seconds: 'Seconds'
}
}
}
};
const config = CONFIG[userCountry];
const t = config.translations[currentLang];
// ============================================
// 📱 عناصر DOM
// ============================================
const desktopBtn = document.getElementById("desktop_add_to_cart");
const mobileBtn = document.getElementById("mobile_add_to_cart");
const addToCartBtn = document.querySelector("#add_to_cart");
const productName = document.querySelector("h1[itemprop='name']");
const mobileProductName = document.getElementById("mobileProductName");
const stickyName = document.getElementById("sticky_product_name");
const stickyCurrent = document.getElementById("sticky_current_price");
const stickyOriginal = document.getElementById("sticky_original_price");
const mobileCurrent = document.getElementById("mobile_current_price");
const mobileOriginal = document.getElementById("mobile_original_price");
const hourEl = document.getElementById("mobile_hours");
const minuteEl = document.getElementById("mobile_minutes");
const secondEl = document.getElementById("mobile_seconds");
// ============================================
// 💵 تنسيق السعر
// ============================================
function formatPrice(value) {
if (!value) return '';
const cleanValue = parseFloat(String(value).replace(/[^0-9.]/g, ''));
if (isNaN(cleanValue)) return '';
const formatted = Math.floor(cleanValue).toLocaleString('en-US');
const symbol = currentLang === 'en' ? config.symbolEn : config.symbolAr;
return `${formatted} ${symbol}`;
}
// ============================================
// 💰 قراءة الأسعار
// ============================================
function getPrices() {
const priceConfig = MANUAL_PRICES[userCountry];
const originalPrice = priceConfig.originalPrice ?
parseFloat(priceConfig.originalPrice.replace(/[^0-9.]/g, '')) : 0;
const currentPrice = priceConfig.currentPrice ?
parseFloat(priceConfig.currentPrice.replace(/[^0-9.]/g, '')) : 0;
console.log('💰 Original Price:', originalPrice, 'Current Price:', currentPrice);
return { originalPrice, currentPrice };
}
// ============================================
// 📝 عرض البيانات
// ============================================
function updatePrices() {
const prices = getPrices();
// لو السعودية ومفيش سعر (Out of Stock)، اخفي الأسعار كلها
if (userCountry === 'SA' && (!prices.currentPrice || prices.currentPrice === 0)) {
stickyCurrent.style.display = "none";
mobileCurrent.style.display = "none";
stickyOriginal.style.display = "none";
mobileOriginal.style.display = "none";
return;
}
if (prices.currentPrice) {
const formatted = formatPrice(prices.currentPrice);
stickyCurrent.textContent = formatted;
mobileCurrent.textContent = formatted;
stickyCurrent.style.display = "";
mobileCurrent.style.display = "";
}
if (prices.originalPrice && prices.originalPrice > prices.currentPrice) {
const formatted = formatPrice(prices.originalPrice);
stickyOriginal.textContent = formatted;
mobileOriginal.textContent = formatted;
stickyOriginal.style.display = "";
mobileOriginal.style.display = "";
} else {
stickyOriginal.style.display = "none";
mobileOriginal.style.display = "none";
}
}
if (productName) {
stickyName.textContent = productName.textContent.trim();
if (mobileProductName) {
mobileProductName.textContent = productName.textContent.trim();
}
}
updatePrices();
// ============================================
// 🌐 الترجمة
// ============================================
function applyTranslations() {
const offerText = document.querySelector(".mobile-countdown .offer-text");
if (offerText) offerText.textContent = t.offerText;
if (desktopBtn) desktopBtn.textContent = t.addToCart;
if (mobileBtn) mobileBtn.textContent = t.buyNow;
const ratingText = document.querySelector(".rating-text");
if (ratingText) {
ratingText.textContent = currentLang === 'en' ? `428 ${t.ratings}` : `428 ${t.ratings}`;
}
updateTimerLabels();
}
function updateTimerLabels() {
const hourLabel = document.querySelector(".label-hour");
const minuteLabel = document.querySelector(".label-minute");
const secondLabel = document.querySelector(".label-second");
if (hourLabel) hourLabel.textContent = t.hours;
if (minuteLabel) minuteLabel.textContent = t.minutes;
if (secondLabel) secondLabel.textContent = t.seconds;
}
applyTranslations();
// ============================================
// 📜 Sticky Header
// ============================================
const header = document.getElementById("desktop_sticky_header");
const mobileHeader = document.getElementById("mobile-embed-header");
window.addEventListener("scroll", () => {
const y = window.scrollY;
header.classList.toggle("scrolled", y > 10);
header.classList.toggle("at-top", y <= 10);
if (mobileHeader) {
mobileHeader.classList.toggle("scrolled", y > 10);
mobileHeader.classList.toggle("at-top", y <= 10);
}
});
// ============================================
// 📦 فحص المخزون - متاح في مصر فقط
// ============================================
function checkStockAvailability() {
const isAvailable = STOCK_RULES[userCountry];
const isOutOfStock = !isAvailable;
console.log('🔍 VR Go availability in', userCountry, ':', isAvailable ? 'Available' : 'Out of Stock');
updateButtonState(isOutOfStock);
}
function updateButtonState(isDisabled) {
[desktopBtn, mobileBtn].forEach((btn, idx) => {
if (btn) {
btn.disabled = isDisabled;
btn.style.opacity = isDisabled ? "0.5" : "";
btn.style.cursor = isDisabled ? "not-allowed" : "";
const msgId = idx === 0 ? "desktop_out_of_stock" : "mobile_out_of_stock";
const msg = document.getElementById(msgId);
if (msg) {
if (isDisabled) {
msg.textContent = t.outOfStock;
msg.classList.add('show');
} else {
msg.classList.remove('show');
}
}
}
});
}
// ============================================
// ⏱️ Timer
// ============================================
function updateTimer() {
const now = Date.now();
const fiveHoursMs = 5 * 60 * 60 * 1000;
const elapsed = now % fiveHoursMs;
const remaining = fiveHoursMs - elapsed;
const totalSeconds = Math.floor(remaining / 1000);
const h = Math.floor(totalSeconds / 3600);
const m = Math.floor((totalSeconds % 3600) / 60);
const s = totalSeconds % 60;
hourEl.textContent = String(h).padStart(2, '0');
minuteEl.textContent = String(m).padStart(2, '0');
secondEl.textContent = String(s).padStart(2, '0');
}
updateTimer();
setInterval(updateTimer, 1000);
checkStockAvailability();
// ============================================
// 🛒 Add to Cart
// ============================================
const handleClick = (e) => {
e.preventDefault();
if (desktopBtn.disabled || mobileBtn.disabled) return;
if (addToCartBtn) addToCartBtn.click();
};
desktopBtn?.addEventListener("click", handleClick);
mobileBtn?.addEventListener("click", handleClick);
console.log('✅ CardoO VR Go Navbar Ready!');
console.log('🎯 Product is AVAILABLE in Egypt only (Out of Stock in Saudi Arabia)');
});