1var popup = document.getElementById("popup-form"); 2var close = document.getElementsByClassName("close")[0]; 3var allowedCountries = ['US', 'CA', 'GB', 'AU', 'NZ', 'SG', 'DE', 'FR', 'FI', 'NL', 'BE', 'AE', 'MY']; 4 5function showPopup() { 6 popup.style.display = "block"; 7} 8 9function hidePopup() { 10 popup.style.display = "none"; 11} 12 13function setCookie(name, value, minutes) { 14 var expires = ""; 15 if (minutes) { 16 var date = new Date(); 17 date.setTime(date.getTime() + (minutes * 60 * 1000)); 18 expires = "; expires=" + date.toUTCString(); 19 } 20 document.cookie = name + "=" + (value || "") + expires + "; path=/"; 21} 22 23function getCookie(name) { 24 var nameEQ = name + "="; 25 var ca = document.cookie.split(';'); 26 for (var i = 0; i < ca.length; i++) { 27 var c = ca[i]; 28 while (c.charAt(0) == ' ') c = c.substring(1, c.length); 29 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); 30 } 31 return null; 32} 33 34// Check if the user has already subscribed or shown popup using a cookie 35if (getCookie("clickedLearnSmash") || getCookie("popupLearnSmashShown")) { 36 // If the user has already subscribed or shown popup, don't show the pop-up form 37 hidePopup(); 38} else { 39 // If the user hasn't subscribed, show the pop-up form based on their country 40 var ip = ''; 41 // Get the user's IP address using a third-party service 42 fetch('https://api.ipify.org?format=json') 43 .then(response => response.json()) 44 .then(data => { 45 ip = data.ip; 46 // Use iplocation.net to get the user's location information based on their IP address 47 return fetch('https://api.iplocation.net/?ip=' + ip) 48 }) 49 .then(response => response.json()) 50 .then(data => { 51 // Check if the user is from one of the allowed countries 52 if (allowedCountries.includes(data.country_code2)) { 53 setTimeout( function () { 54 showPopup(); 55 setCookie("popupLearnSmashShown", "true", 5); // Set cookie to indicate pop-up has been shown 56 gtag('event', 'popupLearnSmash', { popup_name: 'Learn To Smash'}); 57 } , 15000); // Wait for 15 seconds before showing the pop-up 58 } 59 }) 60 .catch(error => { 61 // If there was an error getting the location data, just show the pop-up 62 setTimeout( function () { 63 showPopup(); 64 setCookie("popupLearnSmashShown", "true", 5); // Set cookie to indicate pop-up has been shown 65 gtag('event', 'popupLearnSmash', { popup_name: 'Learn To Smash'}); 66 } , 15000); // Wait for 15 seconds before showing the pop-up 67 }); 68} 69 70close.onclick = hidePopup; 71 72window.onclick = function(event) { 73 if (event.target == popup) { 74 hidePopup(); 75 } 76} 77 78// Add an event listener to the subscribe button 79document.getElementById("popupLearnSmashLink").addEventListener("click", function() { 80 // Set the subscribed cookie to true and hide the pop-up form 81 setCookie("clickedLearnSmash", true, 1440); 82 gtag('event', 'clickedLearnSmash', { popup_name: 'Learn To Smash'}); 83 hidePopup(); 84});
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.