1document.addEventListener("DOMContentLoaded", function () { 2 const BASE_URL = document.querySelector('link[rel="canonical"]')?.getAttribute('href') || ''; 3 4 document.querySelectorAll(".ads_click").forEach(function (el) { 5 const adId = el.getAttribute("rel"); 6 const href = el.getAttribute("href"); 7 8 // Registrar views automaticamente 9 fetch(BASE_URL + "/adsView", { 10 method: "POST", 11 headers: {"Content-Type": "application/x-www-form-urlencoded"}, 12 body: "ad_id=" + encodeURIComponent(adId) 13 }); 14 15 // Interceptar click e redirecionar depois do fetch 16 el.addEventListener("click", function (e) { 17 e.preventDefault(); // impede o redirecionamento padrão 18 19 fetch(BASE_URL + "/adsClick", { 20 method: "POST", 21 headers: {"Content-Type": "application/x-www-form-urlencoded"}, 22 body: "ad_id=" + encodeURIComponent(adId) 23 }) 24 .then(response => { 25 // Redireciona mesmo se falhar, para não travar o usuário 26 window.open(href, '_blank'); 27 }) 28 .catch(() => { 29 // window.open(href, '_blank'); 30 }); 31 }); 32 }); 33});
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.