1// Wait for page to load 2window.addEventListener("load", function () { 3 // Simple ad rotation - direct approach 4 rotateAds("banner"); 5 rotateAds("sidebar"); 6 rotateAds("box"); 7 8 // Track impressions for initially visible ads 9 // document.querySelectorAll(".ad-item").forEach((adEl) => { 10 // if (adEl.offsetParent !== null) { 11 // // Check if visible 12 // const adId = adEl.getAttribute("data-ad-id"); 13 // const screen = adEl.closest(".ad-slot").getAttribute("data-screen"); 14 // const pageId = link ? link.getAttribute("data-page-id") : null; 15 // this.alert(pageId); 16 17 // // Prevent duplicate impression 18 // if (!window.trackedImpressions) window.trackedImpressions = new Set(); 19 // const key = `${adId}-${screen}`; 20 // if (!window.trackedImpressions.has(key)) { 21 // window.trackedImpressions.add(key); 22 23 // // Debug log 24 // console.log("Tracking impression for ad:", adId, "on screen:", screen); 25 26 // // Track the impression 27 // trackAdImpression(adId, screen); 28 // } 29 // } 30 // }); 31 32 document.querySelectorAll(".ad-item").forEach((adEl) => { 33 if (adEl.offsetParent !== null) { 34 // Check if visible 35 const adId = adEl.getAttribute("data-ad-id"); 36 const screen = adEl.closest(".ad-slot").getAttribute("data-screen"); 37 38 // Define link properly 39 const link = adEl.querySelector(".ad-click"); 40 const pageId = link ? link.getAttribute("data-page-id") : null; 41 42 // alert(pageId); 43 44 // Prevent duplicate impression 45 if (!window.trackedImpressions) window.trackedImpressions = new Set(); 46 const key = `${adId}-${screen}`; 47 if (!window.trackedImpressions.has(key)) { 48 window.trackedImpressions.add(key); 49 50 console.log("Tracking impression for ad:", adId, "on screen:", screen, "page:", pageId); 51 52 trackAdImpression(adId, screen, pageId); 53 } 54 } 55 }); 56 57 58 // Add click tracking to all ad links (prevent duplicate listeners) 59 document.querySelectorAll(".ad-click").forEach((link) => { 60 // Check if listener already attached 61 if (link.hasAttribute('data-click-listener')) { 62 return; 63 } 64 65 // Mark as having listener attached 66 link.setAttribute('data-click-listener', 'true'); 67 68 link.addEventListener("click", function (e) { 69 e.preventDefault(); // Prevent default navigation 70 71 const adId = this.getAttribute("data-id"); 72 const screen = this.closest(".ad-slot").getAttribute("data-screen"); 73 const targetUrl = this.getAttribute("href"); 74 const pageId = this.getAttribute("data-page-id"); 75 76 // Prevent duplicate clicks with a more specific key 77 if (!window.trackedClicks) window.trackedClicks = new Set(); 78 const clickKey = `${adId}-${screen}`; 79 80 // Add a small delay to prevent rapid duplicate clicks 81 if (window.trackedClicks.has(clickKey)) { 82 console.log("Duplicate click prevented for ad:", adId); 83 return; 84 } 85 86 window.trackedClicks.add(clickKey); 87 88 // Remove from set after 2 seconds to allow legitimate re-clicks 89 setTimeout(() => { 90 window.trackedClicks.delete(clickKey); 91 }, 2000); 92 93 // Debug log 94 console.log("Tracking click for ad:", adId, "on screen:", screen); 95 96 // Track the click 97 trackAdClick(adId, screen, targetUrl, pageId); 98 }); 99 }); 100}); 101 102function rotateAds(type) { 103 // Get all ads of this type 104 const ads = document.querySelectorAll(`.ad-item.${type}-ad`); 105 if (ads.length <= 1) return; 106 107 let currentIndex = 0; 108 109 // Function to rotate to next ad 110 function showNextAd() { 111 // Hide current ad 112 ads[currentIndex].style.display = "none"; 113 114 // Move to next ad 115 currentIndex = (currentIndex + 1) % ads.length; 116 117 // Show next ad 118 ads[currentIndex].style.display = "block"; 119 120 // Track impression for newly shown ad 121 const adId = ads[currentIndex].getAttribute("data-ad-id"); 122 const screen = ads[currentIndex] 123 .closest(".ad-slot") 124 .getAttribute("data-screen"); 125 126 // Prevent duplicate impression 127 if (!window.trackedImpressions) window.trackedImpressions = new Set();
128 const key = `${adId}-${screen}`; 129 if (!window.trackedImpressions.has(key)) { 130 window.trackedImpressions.add(key); 131 // trackAdImpression(adId, screen); 132 const link = ads[currentIndex].querySelector(".ad-click"); 133 const pageId = link ? link.getAttribute("data-page-id") : null; 134 trackAdImpression(adId, screen, pageId); 135 } 136 137 // Get duration and set timer for next rotation 138 const duration = 139 parseInt(ads[currentIndex].getAttribute("data-duration")) || 5; 140 setTimeout(showNextAd, duration * 1000); 141 } 142 143 // Start rotation after first ad duration 144 const firstDuration = parseInt(ads[0].getAttribute("data-duration")) || 5; 145 setTimeout(showNextAd, firstDuration * 1000); 146} 147 148function closeAd(button) { 149 const adItem = button.closest(".ad-item"); 150 adItem.style.display = "none"; 151 152 // Get the ad container and type 153 const adContainer = adItem.closest(".ad-slot"); 154 const adType = adContainer.getAttribute("data-screen"); 155 156 // Show next ad if available 157 const nextAd = document.querySelector( 158 `.ad-item.${adType}-ad:not([style*="display: none"])` 159 ); 160 if (!nextAd) { 161 // If no visible ad, show the first one that's not this one 162 const firstOtherAd = document.querySelector( 163 `.ad-item.${adType}-ad:not([data-ad-id="${adItem.getAttribute( 164 "data-ad-id" 165 )}"])` 166 ); 167 if (firstOtherAd) { 168 firstOtherAd.style.display = "block"; 169 170 // Track impression for newly shown ad 171 const adId = firstOtherAd.getAttribute("data-ad-id"); 172 const screen = firstOtherAd 173 .closest(".ad-slot") 174 .getAttribute("data-screen"); 175 176 // Prevent duplicate impression 177 if (!window.trackedImpressions) window.trackedImpressions = new Set(); 178 const key = `${adId}-${screen}`; 179 if (!window.trackedImpressions.has(key)) { 180 window.trackedImpressions.add(key); 181 // trackAdImpression(adId, screen); 182 const link = firstOtherAd.querySelector(".ad-click"); 183 const pageId = link ? link.getAttribute("data-page-id") : null; 184 trackAdImpression(adId, screen, pageId); 185 186 } 187 } 188 } 189} 190 191// Track ad impression 192function trackAdImpression(adId, screen, pageId) { 193 // Create form data 194 const deviceId = getDeviceId(); 195 const formData = new FormData(); 196 formData.append("_token", csrfToken); 197 formData.append("type", "impression"); 198 formData.append("ad_id", adId); 199 formData.append("screen", screen); 200 formData.append("page_id", pageId); 201 formData.append("deviceId", deviceId); 202 203 // Send the request 204 fetch(adTrackUrl, { 205 method: "POST", 206 body: formData, 207 }) 208 .then((response) => response.json()) 209 .then((data) => { 210 console.log("Impression tracked:", data); 211 }) 212 .catch((error) => { 213 console.error("Error tracking impression:", error); 214 }); 215} 216 217// Track ad click and then redirect 218function trackAdClick(adId, screen, targetUrl, pageId) { 219 // Create form data 220 const deviceId = getDeviceId(); 221 const formData = new FormData(); 222 formData.append("_token", csrfToken); 223 formData.append("type", "click"); 224 formData.append("ad_id", adId); 225 formData.append("screen", screen); 226 formData.append("page_id", pageId); 227 formData.append("deviceId", deviceId); 228 formData.append("target_url", targetUrl); 229 230 // Send the request 231 fetch(adTrackUrl, { 232 method: "POST", 233 body: formData, 234 }) 235 .then((response) => response.json()) 236 .then((data) => { 237 console.log("Click tracked:", data); 238 }) 239 .catch((error) => { 240 console.error("Error tracking click:", error); 241 }) 242 .finally(() => { 243 // Redirect whether request succeeds or fails 244 window.open(targetUrl, "_blank"); 245 }); 246} 247 248function getDeviceId() { 249 let deviceId = localStorage.getItem("device_id"); 250 if (!deviceId) { 251 deviceId = "dev-" + Math.random().toString(36).substring(2) + Date.now(); 252 localStorage.setItem("device_id", deviceId); 253 } 254 return deviceId; 255}
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.