(function() { // 1. Interceptar fetch para recetas_con_foto.json y redirigirlo a la biblioteca de medios var originalFetch = window.fetch; window.fetch = function(url, options) { if (typeof url === 'string' && url.indexOf('recetas_con_foto.json') !== -1) { console.log('[Interceptor] Redirigiendo fetch de recetas_con_foto.json a la biblioteca de medios.'); url = 'https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/recetas_con_foto.txt'; } return originalFetch(url, options); }; // Mapeo completo de imágenes estáticas del tema a la biblioteca de medios var imageMappings = { "arepa_pad_thai.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_pad_thai.jpg", "arepa_birria.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_birria.jpg", "arepa_cachopo.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_cachopo.jpg", "arepa_spain_oviedo.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_spain_oviedo.jpg", "arepa_thailand_bangkok.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_thailand_bangkok.jpg", "arepa_mexico_guadalajara.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_mexico_guadalajara.jpg", "chef_andel.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/chef_andel.png", "chef_martita.jpg": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/chef_martita.jpg", "botchef_avatar.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/botchef_avatar.png", "mesa-chefs-hero.jpg": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/mesa-chefs-hero.jpg", "arepa_poutine.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_poutine.jpg", "arepa_bac_kan.png": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_bac_kan.jpg", "arepa_labs_hero_v3.jpg": "https://www.diamundialdelaarepa.com/wp-content/uploads/2026/06/arepa_labs_hero_v3.jpg" }; // 2. Corregir imágenes estáticas rotas en el DOM (chefs, mini-cards, hero) function fixImages() { var imgs = document.querySelectorAll('img'); imgs.forEach(function(img) { var src = img.getAttribute('src') || ''; var basename = src.substring(src.lastIndexOf('/') + 1); if (imageMappings[basename] && img.src !== imageMappings[basename]) { img.src = imageMappings[basename]; console.log('[Interceptor] Corregido src de img:', basename); } }); // Corregir imágenes de fondo inline var els = document.querySelectorAll('*[style*="background"]'); els.forEach(function(el) { var style = el.getAttribute('style') || ''; for (var filename in imageMappings) { if (style.indexOf(filename) !== -1) { var newStyle = style.replace(new RegExp('[^\\(\\)\\\'\\"]*' + filename + '[^\\(\\)\\\'\\"]*', 'g'), imageMappings[filename]); if (el.getAttribute('style') !== newStyle) { el.setAttribute('style', newStyle); console.log('[Interceptor] Corregido background inline:', filename); } } } }); } // 3. Corregir enlaces de las categorías en la Home para ir a la página de países con filtro function fixCategoryLinks() { var catCards = document.querySelectorAll('.cat-card'); catCards.forEach(function(card) { var category = card.getAttribute('data-category'); if (category) { var btn = card.querySelector('.btn-explore-cat'); if (btn) { var targetUrl = '/recetas/?categoria=' + category; if (btn.getAttribute('href') !== targetUrl) { btn.href = targetUrl; console.log('[Interceptor] Corregido enlace de categoría:', category); } } } }); } // 4. Corregir enlaces a recetas estrella en el hero para ir a la ruta absoluta correcta function fixHeroLinks() { var links = document.querySelectorAll('a[href*="arepa-cachopo-oviedo-espana"], a[href*="arepa-pad-thai-bangkok-tailandia"], a[href*="arepa-birria-guadalajara-mexico"]'); links.forEach(function(link) { var href = link.getAttribute('href') || ''; if (href.indexOf('arepa-cachopo-oviedo-espana') !== -1 && link.getAttribute('href') !== '/arepa-cachopo-oviedo-espana/') { link.href = '/arepa-cachopo-oviedo-espana/'; } else if (href.indexOf('arepa-pad-thai-bangkok-tailandia') !== -1 && link.getAttribute('href') !== '/arepa-pad-thai-bangkok-tailandia/') { link.href = '/arepa-pad-thai-bangkok-tailandia/'; } else if (href.indexOf('arepa-birria-guadalajara-mexico') !== -1 && link.getAttribute('href') !== '/arepa-birria-guadalajara-mexico/') { link.href = '/arepa-birria-guadalajara-mexico/'; } }); // Corregir enlace del botón del mapa mundi si está incorrecto var mapLinks = document.querySelectorAll('a[href*="#categorias"], a[href*="mapa-mundi.html"]'); mapLinks.forEach(function(link) { if (link.textContent.indexOf('MAPA CULINARIO') !== -1 && link.getAttribute('href') !== '/mapa-mundi/') { link.href = '/mapa-mundi/'; console.log('[Interceptor] Corregido enlace del mapa mundi a /mapa-mundi/'); } }); } // 5. Inicializar la lógica del Menú Responsivo (Hamburguesa) function initResponsiveMenu() { var toggle = document.querySelector('.mobile-toggle'); var nav = document.getElementById('main-nav'); if (toggle && nav && !toggle.hasAttribute('data-responsive-init')) { toggle.setAttribute('data-responsive-init', 'true'); console.log('[Interceptor] Inicializando menú responsivo.'); // Eliminar listeners previos clonando el nodo si hiciera falta var newToggle = toggle.cloneNode(true); toggle.parentNode.replaceChild(newToggle, toggle); newToggle.addEventListener('click', function(e) { e.preventDefault(); nav.classList.toggle('active'); newToggle.classList.toggle('active'); document.body.classList.toggle('nav-open'); }); var navLinks = nav.querySelectorAll('a'); navLinks.forEach(function(link) { link.addEventListener('click', function() { nav.classList.remove('active'); newToggle.classList.remove('active'); document.body.classList.remove('nav-open'); }); }); } } // Ejecución segura continua con setInterval para interceptar elementos cargados dinámicamente function runCorrections() { fixImages(); fixCategoryLinks(); fixHeroLinks(); initResponsiveMenu(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', runCorrections); } else { runCorrections(); } // Intervalo continuo de seguridad para renderizado asíncrono setInterval(runCorrections, 400); })();