fix(adsense): ocultar anchor ads cuando AdSense no llena el slot
- Agregar watchUnfilledAds() con MutationObserver - Detectar data-ad-status="unfilled" de AdSense - Timeout de 5s como respaldo si no hay contenido - Evitar mostrar espacio en blanco cuando no hay anuncio 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -86,6 +86,54 @@
|
|||||||
// ANCHOR ADS
|
// ANCHOR ADS
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observa los slots de AdSense y oculta el contenedor si no se llena
|
||||||
|
* AdSense agrega data-ad-status="unfilled" cuando no hay anuncio
|
||||||
|
*/
|
||||||
|
function watchUnfilledAds(containers) {
|
||||||
|
containers.forEach(function(container) {
|
||||||
|
var ins = container.querySelector('ins.adsbygoogle');
|
||||||
|
if (!ins) return;
|
||||||
|
|
||||||
|
// Verificar si ya tiene estado (por si ya cargo)
|
||||||
|
var status = ins.getAttribute('data-ad-status');
|
||||||
|
if (status === 'unfilled') {
|
||||||
|
container.classList.add('hidden');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usar MutationObserver para detectar cambios
|
||||||
|
var observer = new MutationObserver(function(mutations) {
|
||||||
|
mutations.forEach(function(mutation) {
|
||||||
|
if (mutation.type === 'attributes' && mutation.attributeName === 'data-ad-status') {
|
||||||
|
var newStatus = ins.getAttribute('data-ad-status');
|
||||||
|
if (newStatus === 'unfilled') {
|
||||||
|
container.classList.add('hidden');
|
||||||
|
observer.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(ins, {
|
||||||
|
attributes: true,
|
||||||
|
attributeFilter: ['data-ad-status']
|
||||||
|
});
|
||||||
|
|
||||||
|
// Timeout de seguridad: si despues de 5s no hay contenido, ocultar
|
||||||
|
setTimeout(function() {
|
||||||
|
var adStatus = ins.getAttribute('data-ad-status');
|
||||||
|
// Si no tiene status o esta unfilled, y no tiene contenido real
|
||||||
|
if (!adStatus || adStatus === 'unfilled') {
|
||||||
|
if (ins.innerHTML.length < 100) {
|
||||||
|
container.classList.add('hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
observer.disconnect();
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function initAnchorAds() {
|
function initAnchorAds() {
|
||||||
var config = getConfig('roi-anchor-config');
|
var config = getConfig('roi-anchor-config');
|
||||||
if (!config) return;
|
if (!config) return;
|
||||||
@@ -109,6 +157,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Ocultar anchors cuando AdSense no llena el slot
|
||||||
|
watchUnfilledAds(anchors);
|
||||||
|
|
||||||
// Event delegation para botones
|
// Event delegation para botones
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function(e) {
|
||||||
var btn = e.target.closest('[data-action]');
|
var btn = e.target.closest('[data-action]');
|
||||||
|
|||||||
Reference in New Issue
Block a user