(function(){ var doc = document; var CDN_BASE = 'https://toplist.instaffinity.com'; loadContent(); function setupLoadMoreButton(toplistElement) { const loadMoreBtn = toplistElement.querySelector(".toplist-more-btn"); if (!loadMoreBtn) return; loadMoreBtn.addEventListener("click", function () { const hiddenBrands = toplistElement.querySelectorAll( ".toplist-brand.d-none" ); hiddenBrands.forEach((brand) => { brand.classList.remove("d-none"); }); if ( toplistElement.querySelectorAll(".toplist-brand.d-none").length === 0 ) { loadMoreBtn.style.display = "none"; } }); } function classifyTraffic(url, referrer = document.referrer, userAgent = navigator.userAgent) { const parsedUrl = new URL(url, window.location.origin); const params = parsedUrl.searchParams; const utmSource = params.get("utm_source")?.toLowerCase() || ""; const utmMedium = params.get("utm_medium")?.toLowerCase() || ""; const utmCampaign = params.get("utm_campaign")?.toLowerCase() || ""; const gclid = params.get("gclid"); const msclkid = params.get("msclkid"); const fbclid = params.get("fbclid"); if (gclid || msclkid || ["cpc", "ppc", "paidsearch"].includes(utmMedium)) { return "paid"; } if (["display", "banner", "cpm"].includes(utmMedium)) { return "cpm"; } if (["push", "inpagepush"].includes(utmMedium)) { return "push"; } if ( utmMedium === "social" || ["facebook","instagram","twitter","tiktok","linkedin","pinterest"].some(s => utmSource.includes(s)) ) { return "social"; } if (utmMedium === "email" || utmSource.includes("newsletter")) { return "email"; } if (["organic", "seo"].includes(utmMedium)) { return "search"; } if (!utmSource && !utmMedium && !utmCampaign) { } else { return "other"; } if (!referrer) { return "direct"; } const ref = referrer.toLowerCase(); if (/(facebook|instagram|twitter\.com|t\.co|linkedin|pinterest|tiktok)/.test(ref)) { return "Social"; } if (/(google\..*\/search|bing\.com\/search|yahoo\.com\/search|yandex\.com)/.test(ref)) { return "search"; } if (/mail\.|webmail|outlook|gmail/.test(ref)) { return "email"; } return "direct"; } function loadContent() { function tryLoad() { var elements = doc.querySelectorAll('casino-toplist[data-key]'); if (elements.length > 0) { for (var i = 0; i < elements.length; i++) { var el = elements[i]; var key = el.getAttribute('data-key'); if (!key) continue; (function(element, id) { var listData = {"TmWgGd3Z3yWVpn1G":{"a":["country"],"t":"1760971043"}}; var extraQuery = ''; if (listData[id].a.includes('traffic-source')) { extraQuery = '&traffic-source=' + classifyTraffic(window.location.href); } var url = CDN_BASE + '/toplist/' + id + '?time=' + listData[id].t + extraQuery; fetch(url, { referrerPolicy: 'no-referrer-when-downgrade', credentials: 'omit' }) .then(r => r.text()) .then(html => { element.innerHTML = html; setupLoadMoreButton(element); // Add geo parameter to all links element.querySelectorAll('a[href]').forEach((link) => { try { const href = link.getAttribute('href'); const url = new URL(href, window.location.href); link.setAttribute('href', url.toString()); } catch (_) { /* ignore malformed hrefs */ } }); // Modal logic - only run once per page load if (!window.instaModalProcessed) { window.instaModalProcessed = true; const modal = doc.getElementById("instaSubscribeModal"); if (modal) { const waitAttr = modal.getAttribute('data-timer'); const waitTime = Math.max(0, parseInt(waitAttr || '0', 10) || 0); const geoAttr = modal.getAttribute('data-geo'); const geoCountries = geoAttr ? geoAttr.split(',').map(s => s.trim().toUpperCase()) : []; const modalContent = doc.querySelector(".insta-card"); const maybeOpen = () => { if (!geoCountries.length || geoCountries.includes(country)) { modal.style.display = "block"; doc.body.classList.add('modal-open'); } }; if (modalContent) { doc.addEventListener('click', function onDocClick(event){ if (!modalContent.contains(event.target)) { modal.style.display = "none"; doc.body.classList.remove('modal-open'); doc.removeEventListener('click', onDocClick); } }); } if (waitTime > 0) { setTimeout(maybeOpen, waitTime); } else { maybeOpen(); } } } }) .catch(error => { console.error("Instaffinity: fetch HTML failed for key:", id, error); element.innerHTML = '
Unable to load casino list
'; }); })(el, key); } } else { setTimeout(tryLoad, 50); } } tryLoad(); } // Expose subscribe globally for existing templates window.subscribe = function subscribe() { var emailInput = doc.getElementById("instaffinity-email"); if (!emailInput) return; var email = emailInput.value || ''; var tagKey = emailInput.getAttribute("data-tagkey"); var domain = window.location.hostname; function validateEmailLocal(e) { var re = /\S+@\S+\.\S+/; return re.test(e); } if (email === '' || !validateEmailLocal(email)) { alert("Please enter a valid email address."); return; } var payload = { email: email, country: 'GL', toplist: tagKey, domain: domain }; fetch("https://cdn.instaffinity.com/instaffinity/emails/", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), credentials: 'omit' }) .then(function(response){ if (!response.ok) throw new Error('Network error'); var modal = doc.getElementById("instaSubscribeModal"); if (modal) { modal.style.display = "none"; doc.body.classList.remove('modal-open'); } }) .catch(function(){ /* silent */ }); }; })();