Last active
February 1, 2018 03:58
-
-
Save primedime/32211053279b5ec523babc36707d1fd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadIP() { | |
const xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'https://freegeoip.net/json/', true); | |
xhr.onload = function() { | |
const data = JSON.parse(this.response); | |
const country = data.country_code; | |
console.log(country); | |
const europe = ['GB', 'AL', 'AD', 'AT', 'BY', 'BE', 'BA', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FO', 'FI', 'FR', 'DE', 'GI', 'GR', 'HU', 'IS', 'IE', 'IT', 'LV', 'LI', 'LT', 'LU', 'MK', 'MT', 'MD', 'MC', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SM', 'RS', 'SK', 'SI', 'ES', 'SE', 'CH', 'UA', 'VA', 'RS', 'IM', 'RS', 'ME', 'DE']; | |
const inEU = europe.indexOf(country) !== -1; | |
if (country === 'US' || country === 'CA' || country === undefined) | |
document.getElementById('usa').style.display = "block"; | |
else if (inEU) | |
document.getElementById('eur').style.display = "block"; | |
else | |
document.getElementById('usa').style.display = "block"; | |
} | |
xhr.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment