1(function () { 2 const ADS = []; 3 let currentSize = null; 4 let screenSize = null; 5 6 function getAdSize() { 7 const width = window.innerWidth; 8 if (width < 768) return 'small'; 9 if (width < 1024) return 'medium'; 10 11 screenSize = window.screen.width + 'x' + window.screen.height; 12 13 return 'large'; 14 } 15 16 function parseHTML(html, size, blockId) { 17 const temp = document.createElement('div'); 18 temp.innerHTML = html; 19 20 const adDiv = temp.querySelector('[id]'); 21 if (adDiv) { 22 const adId = adDiv.id; 23 24 var myBody = { 25 id: adId, 26 size: size, 27 screensize: screenSize, 28 block: blockId, 29 url: window.location.href 30 } 31 32 console.log(myBody) 33 34 // Register the view after rendering 35 fetch(`/ads/pageview`, { 36 method: 'POST', 37 headers: { 'Content-Type': 'application/json' }, 38 body: JSON.stringify(myBody) 39 }); 40 } 41 } 42 43 function notifyAds(newSize) { 44 ADS.forEach(({ element, blockId }) => { 45 const url = `/ads?size=${newSize}&block=${blockId}`; 46 fetch(url) 47 .then(res => res.text()) 48 .then(html => { 49 parseHTML(html, newSize, blockId); 50 element.innerHTML = html; 51 }) 52 .catch(err => { 53 console.error(`Ad load failed for ${blockId}:`, err); 54 }); 55 }); 56 } 57 58 function checkSizeAndUpdate() { 59 const newSize = getAdSize(); 60 if (newSize !== currentSize) { 61 currentSize = newSize; 62 notifyAds(currentSize); 63 } 64 } 65 66 67 window.registerAdBlock = function (elementId, blockId) { 68 const el = document.getElementById(elementId); 69 if (!el) return; 70 ADS.push({ element: el, blockId }); 71 if (currentSize !== null) { 72 const url = `/ads?size=${currentSize}&block=${blockId}`; 73 fetch(url) 74 .then(res => res.text()) 75 .then(html => { 76 parseHTML(html, currentSize, blockId); 77 el.innerHTML = html; 78 }); 79 } 80 }; 81 82 checkSizeAndUpdate(); 83 84 window.addEventListener('resize', () => { 85 clearTimeout(window.__adResizeTimeout); 86 window.__adResizeTimeout = setTimeout(checkSizeAndUpdate, 150); 87 }); 88 89 document.addEventListener('click', function (event) { 90 const adElement = event.target.closest('.ad-banner'); 91 if (!adElement) return; 92 93 event.preventDefault(); 94 95 const adId = adElement.id; 96 const adSize = adElement.dataset.size; // â Get data-size 97 const adBlock = adElement.dataset.block; 98 const adPlatform = adElement.dataset.platform; 99 const currentUrl = window.location.href; 100 101 if (!adId || !adSize) { 102 console.warn('Ad clicked but missing ID or size.'); 103 return; 104 } 105 106 // Build the redirect URL 107 const redirectUrl = `/ads/click?id=${encodeURIComponent(adId)}&url=${encodeURIComponent(currentUrl)}&size=${encodeURIComponent(adSize)}&screensize=${screenSize}&block=${adBlock}&platform=${adPlatform}`; 108 109 // Open the tracked redirect in a new tab 110 window.open(redirectUrl, '_blank'); 111 }); 112 113 114})();
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.