Hungary
Norway
Sweden
Asia
Rest of World
tag of the clicked element This will serve as data of what country is selected */ selectedCountry = countryElement.querySelector('p').textContent; // Update selectedIndex when a country is clicked selectedIndex = index; updateButtonContent(selectedCountry); }); }); /* Add a keydown event listener for arrow keys outside the forEach loop */ document.addEventListener('keydown', (event) => { if (event.key === 'ArrowUp') { //Prevent page scrolling event.preventDefault(); /* Calculates the index of the previous country Example: selectedIndex = 0 is already defined then we have countryElements = [Japan, Brazil, Finland, Sweden, Rest of world] therefore countryElements.length = 5 using this formula (selectedIndex - 1 + countryElements.length) % countryElements.length (0 - 1 + 5) % 5 0 - 1 = -1 -1 + 5 = 4 4 % 5 = 4 4 corresponds to 'Rest of world' Same logic applies below */ const prevIndex = (selectedIndex - 1 + countryElements.length) % countryElements.length; countryElements[prevIndex].click(); } else if (event.key === 'ArrowDown') { event.preventDefault(); // Prevent page scrolling const nextIndex = (selectedIndex + 1) % countryElements.length; countryElements[nextIndex].click(); } else if (event.key === 'Enter') { event.preventDefault(); // Prevent form submission, if any // if (selectedCountryElement) { // redirectToCountrySite(selectedCountry); // updateButtonContent(selectedCountry); // } proceedRegionButton.click(); } else if (event.key === 'Escape') { event.preventDefault(); } }); const proceedRegionButton = document.getElementById('proceedRegion'); const MeCheckbox = document.querySelector( '#Me input[type="checkbox"]' ); const notificationActionsContainer = document.querySelector( '.notification-actions' ); const MeContainer = document.querySelector('#Me'); MeCheckbox.addEventListener('click', () => { if (MeCheckbox.checked) { const disclaimerElement = document.createElement('div'); disclaimerElement.textContent = "On your next visit to verajohn.com, it will automatically redirect you to your chosen country. Click 'Continue' to proceed"; disclaimerElement.classList.add('disclaimer'); MeContainer.insertAdjacentElement( 'afterend', disclaimerElement ); } else { const disclaimerElement = document.querySelector( '.notification-actions .disclaimer' ); notificationActionsContainer.removeChild(disclaimerElement); } }); proceedRegionButton.addEventListener('click', () => { if (MeCheckbox.checked) { setCookie('SelectedCountry', selectedCountry, 14); // 7 days = 1 week, Change this to adjust the expiration } dataLayer.push({ event: 'button_continue_to', pop_up_button_country: selectedCountry, }); redirectToCountrySite(selectedCountry); updateButtonContent(selectedCountry); }); updateButtonContent(selectedCountry); } const selectedCountryCookie = getCookie('SelectedCountry'); if (selectedCountryCookie) { const selectedCountry = selectedCountryCookie; redirectToCountrySite(selectedCountry); } // Function to set a cookie with an expiration date function setCookie(cookieName, cookieValue, daysToExpire) { const expirationDate = new Date(); expirationDate.setTime( expirationDate.getTime() + daysToExpire * 24 * 60 * 60 * 1000 ); const expires = 'expires=' + expirationDate.toUTCString(); document.cookie = `${cookieName}=${cookieValue}; ${expires}; path=/`; } // Function to check for the existence of a cookie function getCookie(cookieName) { const name = cookieName + '='; const decodedCookie = decodeURIComponent(document.cookie); const cookieArray = decodedCookie.split(';'); for (let i = 0; i < cookieArray.length; i++) { let cookie = cookieArray[i]; while (cookie.charAt(0) === ' ') { cookie = cookie.substring(1); } if (cookie.indexOf(name) === 0) { return cookie.substring(name.length, cookie.length); } } return ''; } // Function to handle the redirection function redirectToCountrySite(selectedCountry) { switch (selectedCountry) { case 'Finland': window.location.href = 'https://play.verajohncasino.com/'; break; case 'Hungary': window.location.href = 'https://tinyurl.com/vjurl'; break; case 'Norway': window.location.href = 'https://play.verajohncasino.com/'; break; case 'Sweden': window.location.href = 'https://www.verajohn.se/sv'; break; case 'Asia': window.location.pathname = '/ja/'; break; case 'Rest of World': window.location.href = 'https://www.verajohncasino.com'; break; default: break; } } // Function to update the button text function updateButtonContent(country) { const proceedRegionButton = document.getElementById('proceedRegion'); proceedRegionButton.textContent = `Continue to ${country}`; } // const addDialog = document.getElementById('addBtn') // addDialog.addEventListener('click', () => { // createDialog() // }) });