1let dataAbo; 2 3// adblock laregione - adcheck.php 4$(document).ready(function () { 5 // Se l'URL corrente contiene "login" (case-insensitive), esci subito 6 if ((window.location.href || '').toLowerCase().includes('login')) { 7 return; 8 } 9 larAdBlockDetect().then((adblockActiveHere) => { 10 if (adblockActiveHere) { 11 console.log("Adblocker rilevato!"); 12 13 if (!alertCanBeShown()) { 14 return; 15 } 16 17 // Check subscription status via the new PHP endpoint 18 fetch('/ext/lar/adcheck.php') 19 .then(response => response.json()) 20 .then(data => { 21 // Show different alerts based on subscription status 22 dataAbo = data; 23 if (data.valid && data.dismissable) { 24 // Valid subscription - show dismissable alert 25 Swal.fire({ 26 title: 'AdBlocker rilevato!', 27 text: data.message, 28 icon: 'warning', 29 confirmButtonText: data.primaryButtonText, 30 confirmButtonColor: '#F5F5F5', // Blue color to match site aesthetic 31 32 allowOutsideClick: false, 33 allowEscapeKey: true 34 }) 35 } else { 36 // Invalid or expired subscription - show non-dismissable alert 37 Swal.fire({ 38 title: 'AdBlocker rilevato!', 39 text: data.message, 40 icon: 'warning', 41 confirmButtonText: data.primaryButtonText, 42 confirmButtonColor: '#F5F5F5', 43 showCancelButton: true, 44 cancelButtonText: data.secondaryButtonText, 45 cancelButtonColor: '#F5F5F5', 46 allowOutsideClick: false, 47 allowEscapeKey: false, 48 customClass: { 49 container: 'adblock-swal-class' 50 } 51 }).then((result) => { 52 if (result.isConfirmed) { 53 // Primary button clicked (Abbonati) 54 window.location.href = data.primaryButtonUrl; 55 } else { 56 // Secondary button clicked (Accedi) 57 window.location.href = data.secondaryButtonUrl; 58 } 59 }); 60 } 61 }) 62 .catch(error => { 63 console.error('Error checking subscription status:', error); 64 }); 65 } else { 66 // 67 } 68 }); 69}); 70 71/* ========================= 72 Cookie helpers 73 ========================= */ 74function larAdBlockSetCookie(name, value, expiresDate) { 75 const expires = expiresDate ? "; expires=" + expiresDate.toUTCString() : ""; 76 document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/; SameSite=Lax"; 77} 78 79function larAdBlockGetCookie(name) { 80 const nameEQ = name + "="; 81 const ca = document.cookie.split(';'); 82 for (let i = 0; i < ca.length; i++) {
83 let c = ca[i]; 84 while (c.charAt(0) === ' ') c = c.substring(1, c.length); 85 if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length)); 86 } 87 return null; 88} 89 90function larAdBlockExpiresAtTonight() { 91 const now = new Date(); 92 const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 0, 0, 0, 0); 93 return midnight; 94} 95 96function larAdBlockTodayStr() { 97 const d = new Date(); 98 const mm = String(d.getMonth() + 1).padStart(2, '0'); 99 const dd = String(d.getDate()).padStart(2, '0'); 100 return `${d.getFullYear()}-${mm}-${dd}`; 101} 102 103function alertCanBeShown() { 104 const COOKIE_NAME = 'larAdBlock'; 105 const raw = larAdBlockGetCookie(COOKIE_NAME); 106 const today = larAdBlockTodayStr(); 107 108 // if no cookie exists, create it 109 if (!raw) { 110 setNewCookie(COOKIE_NAME, today); 111 112 return false; 113 } 114 115 const data = JSON.parse(raw); 116 117 if (data.date !== today) { 118 setNewCookie(COOKIE_NAME, today); 119 120 //show popup once when day changes 121 return true; 122 } 123 124 setNewCookie(COOKIE_NAME, today, data.cv + 1); 125 126 return (data.cv >= data.cc); 127} 128 129function setNewCookie(name, today, numberOfVisits = 1) { 130 const data = { 131 date: today, 132 cv: numberOfVisits, 133 cc: Math.floor(Math.random() * 3) + 2 134 }; 135 136 larAdBlockSetCookie(name, JSON.stringify(data), larAdBlockExpiresAtTonight()); 137} 138 139/* ========================= 140 Adblock bait 141 ========================= */ 142// Rileva adblock: TRUE = attivo sul sito, FALSE = non attivo o in pausa per il dominio 143async function larAdBlockDetect() { 144 const [baitBlocked, scriptBlocked, pixelBlocked] = await Promise.all([ 145 larAdBlockProbeBaitElement(), 146 larAdBlockProbeScript('/js/laregione.ch/ads/fakeads.js'), // Assicurati che ESISTA e dia 200 147 larAdBlockProbeImage('/js/laregione.ch/ads/px.gif') // Assicurati che ESISTA e dia 200 148 ]); 149 150 // Log di debug (rimuovi in prod) 151 console.debug('[larAdBlockDetect]', { baitBlocked, scriptBlocked, pixelBlocked }); 152 153 // Adblock attivo se ALMENO uno dei probe indica blocco. 154 // Se lâadblock è in pausa per il dominio, tutti e tre dovrebbero risultare false. 155 return (baitBlocked || scriptBlocked || pixelBlocked); 156} 157 158/* ========================= 159 PROBES 160 ========================= */ 161 162// Probe 1: bait element (può dare falsi positivi con alcune "pause" che lasciano le regole cosmetiche) 163function larAdBlockProbeBaitElement(timeoutMs = 180) { 164 return new Promise((resolve) => { 165 const bait = document.createElement('div'); 166 bait.className = 'ads banner ad-banner ad-container ad-unit ad-box'; 167 bait.style.position = 'absolute'; 168 bait.style.left = '-9999px'; 169 bait.style.width = '1px'; 170 bait.style.height = '1px'; 171 document.body.appendChild(bait); 172 173 setTimeout(() => { 174 const cs = window.getComputedStyle(bait); 175 const blocked = ( 176 cs.display === 'none' || 177 cs.visibility === 'hidden' || 178 bait.offsetParent === null || // spesso gli adblock la staccano dal flow 179 bait.offsetHeight === 0 180 ); 181 bait.remove(); 182 resolve(blocked); 183 }, timeoutMs); 184 }); 185} 186 187// Probe 2: caricare uno script in un path "sospetto" (cache-busting incluso) 188function larAdBlockProbeScript(url, timeoutMs = 2000) { 189 return new Promise((resolve) => { 190 const s = document.createElement('script'); 191 s.src = urlWithCacheBust(url); 192 s.async = true; 193 194 const cleanup = () => s.remove(); 195 196 const timer = setTimeout(() => { 197 // timeout: lo consideriamo bloccato (meglio conservative) 198 cleanup(); 199 resolve(true); 200 }, timeoutMs); 201 202 s.onerror = () => { clearTimeout(timer); cleanup(); resolve(true); }; 203 s.onload = () => { clearTimeout(timer); cleanup(); resolve(false); }; 204 205 document.body.appendChild(s); 206 }); 207} 208 209// Probe 3: caricare un pixel/immagine in un path "sospetto" (cache-busting incluso) 210function larAdBlockProbeImage(url, timeoutMs = 2000) { 211 return new Promise((resolve) => { 212 const img = new Image(); 213 img.decoding = 'async'; 214 img.loading = 'eager'; 215 216 const timer = setTimeout(() => { 217 // timeout â probabile blocco 218 cleanup(); 219 resolve(true); 220 }, timeoutMs); 221 222 function cleanup() { 223 clearTimeout(timer); 224 // non serve aggiungerla al DOM, quindi niente remove 225 } 226 227 img.onerror = () => { cleanup(); resolve(true); }; 228 img.onload = () => { cleanup(); resolve(false); }; 229 230 img.src = urlWithCacheBust(url); 231 }); 232} 233 234/* ========================= 235 Utils 236 ========================= */ 237function urlWithCacheBust(url) { 238 const sep = url.includes('?') ? '&' : '?'; 239 return `${url}${sep}_cb=${Date.now()}${Math.random().toString(16).slice(2)}`; 240}
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.