update v1.1.2
This commit is contained in:
@@ -446,16 +446,40 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// Find the parent glass-card to get the product name and price
|
||||
const productCard = e.target.closest('.glass-card');
|
||||
if (productCard) {
|
||||
const productNameElement = productCard.querySelector('h3');
|
||||
// Try to find product name in h1 or h3
|
||||
const productNameElement = productCard.querySelector('h1') || productCard.querySelector('h3');
|
||||
if (productNameElement) {
|
||||
const productName = productNameElement.textContent.trim();
|
||||
const product = productsData[productName];
|
||||
|
||||
// Try to get price from productsData first
|
||||
if (product && product.price) {
|
||||
showCryptoModal(product.price);
|
||||
} else {
|
||||
console.error('Product price not found for:', productName);
|
||||
// Optionally show the modal without price calculation or show an error message
|
||||
showCryptoModal(0); // Pass 0 or handle error in showCryptoModal
|
||||
// If not in productsData, try to extract price from DOM
|
||||
const priceElement = productCard.querySelector('.inline-flex.items-center.px-3.py-1.rounded-full');
|
||||
if (priceElement) {
|
||||
const priceText = priceElement.textContent.trim();
|
||||
// Handle "от " prefix and extract numeric value before €
|
||||
const priceMatch = priceText.match(/(?:от\s*)?([\d,.]+)\s*€/);
|
||||
if (priceMatch) {
|
||||
// Replace comma with dot for decimal numbers if needed
|
||||
const priceValue = priceMatch[1].replace(',', '.');
|
||||
const price = parseFloat(priceValue);
|
||||
if (!isNaN(price)) {
|
||||
showCryptoModal(price);
|
||||
} else {
|
||||
console.error('Invalid price value:', priceValue);
|
||||
showCryptoModal(0);
|
||||
}
|
||||
} else {
|
||||
console.error('Could not parse price from:', priceText);
|
||||
showCryptoModal(0);
|
||||
}
|
||||
} else {
|
||||
console.error('Price element not found in card');
|
||||
showCryptoModal(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error('Product name element not found in card');
|
||||
|
||||
Reference in New Issue
Block a user