1/** 2 * Immediate AdSense Container Fix 3 * Prevents "No slot size for availableWidth=0" errors 4 */ 5(function () { 6 'use strict'; 7 8 console.log('ð§ AdSense Immediate Fix - Starting...'); 9 10 /** 11 * Fix AdSense container dimensions 12 */ 13 function fixAdSenseContainers() { 14 const containers = document.querySelectorAll('.adsbygoogle'); 15 let fixedCount = 0; 16 17 containers.forEach((container, index) => { 18 const computedStyle = window.getComputedStyle(container); 19 const currentWidth = parseFloat(computedStyle.width); 20 const currentHeight = parseFloat(computedStyle.height); 21 22 console.log(`Checking AdSense container ${index + 1}:`, { 23 element: container, 24 currentWidth, 25 currentHeight, 26 display: computedStyle.display, 27 visibility: computedStyle.visibility 28 }); 29 30 // Check if container has zero or invalid dimensions 31 if (isNaN(currentWidth) || currentWidth === 0 || isNaN(currentHeight) || currentHeight === 0) { 32 console.log(`ð§ Fixing container ${index + 1} with invalid dimensions`); 33 34 // Determine appropriate size based on data attributes or defaults 35 let targetWidth = 300; 36 let targetHeight = 250; 37 38 // Check if it's a banner ad (look for common banner patterns) 39 const adSlot = container.dataset.adSlot; 40 const parentClass = container.parentElement?.className || ''; 41 42 if (parentClass.includes('675') || parentClass.includes('625') || 43 adSlot === '2529636047' || computedStyle.width.includes('675')) { 44 targetWidth = 675; 45 targetHeight = 50; 46 } 47 48 // Apply explicit dimensions 49 container.style.width = `${targetWidth}px`; 50 container.style.height = `${targetHeight}px`; 51 container.style.minWidth = `${targetWidth}px`; 52 container.style.minHeight = `${targetHeight}px`; 53 container.style.display = 'inline-block'; 54 container.style.visibility = 'visible'; 55 56 // Fix parent container too 57 const parent = container.parentElement; 58 if (parent) { 59 parent.style.minWidth = `${targetWidth}px`; 60 parent.style.minHeight = `${targetHeight}px`; 61 62 // Force layout recalculation 63 parent.offsetHeight; 64 } 65 66 // Force layout recalculation 67 container.offsetHeight; 68 69 fixedCount++; 70 71 console.log(`â Fixed container ${index + 1}:`, { 72 newWidth: `${targetWidth}px`, 73 newHeight: `${targetHeight}px`, 74 computedWidth: window.getComputedStyle(container).width, 75 computedHeight: window.getComputedStyle(container).height 76 }); 77 } else { 78 console.log(`â Container ${index + 1} already has valid dimensions`); 79 } 80 }); 81 82 console.log(`ð¯ AdSense Fix Complete: ${fixedCount} containers fixed out of ${containers.length} total`); 83 return fixedCount; 84 } 85 86 /** 87 * Run fixes immediately and monitor for new containers 88 */ 89 function initializeFixes() { 90 // Fix existing containers immediately 91 fixAdSenseContainers(); 92 93 // Fix again after a short delay (for dynamically loaded content) 94 setTimeout(fixAdSenseContainers, 500); 95 setTimeout(fixAdSenseContainers, 1000); 96 setTimeout(fixAdSenseContainers, 2000); 97 98 // Monitor for new AdSense containers 99 const observer = new MutationObserver(function (mutations) { 100 let hasNewAds = false; 101 mutations.forEach(function (mutation) { 102 mutation.addedNodes.forEach(function (node) { 103 if (node.nodeType === 1) { // Element node 104 if (node.classList?.contains('adsbygoogle') || 105 node.querySelector?.('.adsbygoogle')) { 106 hasNewAds = true; 107 } 108 } 109 }); 110 }); 111 112 if (hasNewAds) { 113 console.log('ð New AdSense containers detected, applying fixes...'); 114 setTimeout(fixAdSenseContainers, 100); 115 } 116 }); 117 118 observer.observe(document.body, { 119 childList: true, 120 subtree: true 121 }); 122 123 console.log('ð AdSense container monitoring enabled'); 124 } 125 126 // Initialize when DOM is ready 127 if (document.readyState === 'loading') { 128 document.addEventListener('DOMContentLoaded', initializeFixes); 129 } else { 130 initializeFixes(); 131 } 132 133 // Also run when all resources are loaded 134 window.addEventListener('load', () => { 135 setTimeout(fixAdSenseContainers, 100); 136 }); 137 138 console.log('â AdSense Immediate Fix - Initialized'); 139})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.