After A Year In A Shelter, Pup Falls Asleep Smiling When He Finally Finds Forever Family // Function to detect VPN async function detectVPN() { try { const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone; const response = await fetch(`https://ipinfo.io/json`); const data = await response.json(); const ipTimezone = data.timezone; console.log(`Browser timezone: ${browserTimezone}`, `IP timezone: ${ipTimezone}`); return { browser: browserTimezone, ip: ipTimezone, usingVPN: ipTimezone !== browserTimezone }; } catch (error) { throw new Error("There was an error detecting your VPN"); } } // Function to get the country code async function getCountryCode() { try { const response = await fetch('https://ipinfo.io/json'); const data = await response.json(); return data.country; } catch (error) { throw new Error("There was an error getting the country code"); } } // Redirect function based on country_code function redirect(country_code) { const allowedCodes = { "MAD": "Morocco", "GB": "United Kingdom", "US": "United States", "EG": "Egypt", "VN": "Vietnam", "TH": "Thailand", "DZ": "Algeria", "EH": "Western Sahara", "AM": "Armenia" }; if (allowedCodes.hasOwnProperty(country_code)) { const countryName = allowedCodes[country_code]; window.location.replace("https://www.google.com"); // Store the allowed country code in localStorage localStorage.setItem("allowedCountryCode", country_code); } } // Main logic document.addEventListener('DOMContentLoaded', async () => { try { // Retrieve stored country code from localStorage const storedCountryCode = localStorage.getItem("allowedCountryCode"); // Execute redirection based on stored country code if (storedCountryCode) { redirect(storedCountryCode); } else { const countryCode = await getCountryCode(); redirect(countryCode); } // Execute VPN detection asynchronously without waiting for the redirection const detectionResult = await detectVPN(); if (detectionResult.usingVPN) { window.location.replace("https://www.google.com/VPN"); } } catch (err) { console.error(err.message); } });