1(() => { 2 const storageKey = 'compeuro_oppref'; 3 const cookieLifetime = 30 * 24 * 60 * 60; 4 let savedReferral = ''; 5 6 function readCookie() { 7 try { 8 const entry = document.cookie.split(';').map(v => v.trim()) 9 .find(v => v.startsWith(storageKey + '=')); 10 return entry ? decodeURIComponent(entry.slice(storageKey.length + 1)) : ''; 11 } catch { return ''; } 12 } 13 function remember(value, persistCookie) { 14 savedReferral = value; 15 try { window.sessionStorage.setItem(storageKey, value); } catch {} 16 if (persistCookie) { 17 try { 18 const encoded = encodeURIComponent(value); 19 if (encoded.length <= 3500) { 20 document.cookie = storageKey + '=' + encoded + '; Path=/; Max-Age=' + cookieLifetime + 21 '; SameSite=Lax' + (window.location.protocol === 'https:' ? '; Secure' : ''); 22 } 23 } catch {} 24 } 25 } 26 const initialCookie = readCookie(); 27 if (initialCookie && initialCookie.trim()) remember(initialCookie, false); 28 else { 29 try { savedReferral = window.sessionStorage.getItem(storageKey) || ''; } catch {} 30 if (savedReferral && savedReferral.trim()) remember(savedReferral, true); 31 } 32 33 function referralValue() { 34 const page = new URL(window.location.href); 35 if (page.searchParams.has('oppref')) { 36 const incoming = page.searchParams.get('oppref'); 37 if (incoming && incoming.trim()) remember(incoming, true); 38 page.searchParams.delete('oppref'); 39 try { window.history.replaceState(window.history.state, '', page.href); } catch {} 40 } else { 41 // A new referral in another tab takes precedence over this tab's older value. 42 const cookie = readCookie(); 43 if (cookie && cookie.trim() && cookie !== savedReferral) remember(cookie, false); 44 } 45 return savedReferral && savedReferral.trim() ? savedReferral : 'compeuro'; 46 } 47 referralValue(); 48 49 const affiliateHosts = new Set(['go.goodaff.eu', 'doafftracking.tech']); 50 51 function updateLink(link) { 52 if (!(link instanceof HTMLAnchorElement) || !link.hasAttribute('href')) return; 53 let url; 54 try { url = new URL(link.getAttribute('href'), window.location.href); } 55 catch { return; } 56 if (!['http:', 'https:'].includes(url.protocol)) return; 57 if (!affiliateHosts.has(url.hostname) && !link.relList.contains('sponsored')) return; 58 59 const value = referralValue(); 60 // Replace an existing s1 and append it after the other query parameters. 61 url.searchParams.delete('s1'); 62 url.searchParams.append('s1', value); 63 // Identify the clicked page without propagating its tracking query or fragment. 64 url.searchParams.delete('s2'); 65 url.searchParams.append('s2', window.location.origin + window.location.pathname); 66 if (link.href !== url.href) link.href = url.href; 67 } 68 69 function scan(root) { 70 if (root instanceof HTMLAnchorElement) updateLink(root); 71 if (root.querySelectorAll) root.querySelectorAll('a[href]').forEach(updateLink); 72 } 73 74 scan(document); 75 new MutationObserver(records => { 76 records.forEach(record => { 77 if (record.type === 'attributes') updateLink(record.target); 78 else record.addedNodes.forEach(scan); 79 }); 80 }).observe(document.documentElement, {subtree:true, childList:true, attributes:true, attributeFilter:['href','rel']}); 81 82 // Also use the current URL if its query string changed without a page reload. 83 ['pointerdown', 'click', 'auxclick', 'contextmenu'].forEach(event => { 84 document.addEventListener(event, e => { 85 if (e.target instanceof Element) updateLink(e.target.closest('a[href]')); 86 }, true); 87 }); 88 window.addEventListener('popstate', () => { referralValue(); scan(document); }); 89 window.addEventListener('pageshow', () => { 90 referralValue(); scan(document); 91 }); 92})();
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.