Skip to content

Instantly share code, notes, and snippets.

@primedime
Last active February 1, 2018 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save primedime/32211053279b5ec523babc36707d1fd8 to your computer and use it in GitHub Desktop.
Save primedime/32211053279b5ec523babc36707d1fd8 to your computer and use it in GitHub Desktop.
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