Last active
March 15, 2019 09:12
-
-
Save carlwoodhouse/a42dac90d6f9c7429cd792d4eb56ea9a 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
<script> | |
(function () { | |
var ip, newNode, referenceNode; | |
// helper function to execute once we have the IP address | |
function useIP (ip) { | |
if (ip.indexOf("194.176.105.") === 0) { | |
var el = document.getElementsByTagName('body')[0]; | |
el.setAttribute('data-n3', 'true'); | |
} | |
} | |
if (sessionStorage) { | |
ip = sessionStorage.getItem("ipify.ip"); | |
} | |
if (ip) { | |
// use IP address retrieved from session cache | |
useIP(ip); | |
} else { | |
// use ipify.org to get IP address | |
// listen for when the IP address has been loaded by ipfiy | |
window.ipifyCallback = function ipifyCallback (json) { | |
if (sessionStorage) { | |
sessionStorage.setItem("ipify.ip", json.ip); | |
} | |
useIP(json.ip); | |
}; | |
// inject the script from ipify.org | |
newNode = document.createElement("script"); | |
newNode.async = true; | |
newNode.src = "https://api.ipify.org?format=jsonp&callback=ipifyCallback"; | |
referenceNode = document.getElementsByTagName("script")[0]; | |
referenceNode.parentNode.insertBefore(newNode, referenceNode); | |
} | |
}()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment