Last active
August 29, 2015 14:15
-
-
Save evilaliv3/5ee41687cd8e1054e54d to your computer and use it in GitHub Desktop.
Javascript CheckTor library
This file contains hidden or 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> | |
/* | |
Copyright 2015 - Hermes Center - GlobaLeaks project | |
Author <[email protected]> | |
Javascript CheckTor library | |
*/ | |
function redirectIfOnTor(url, test_url) { | |
// Test if the user is using Tor and in that case | |
// redirects the user to provided url | |
try { | |
if (typeof(test_url) === 'undefined') { | |
var test_url = 'https://antani.tor2web.org/checktor'; | |
} | |
if (window.XMLHttpRequest) { | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange=function() { | |
if (xmlhttp.readyState==4 && xmlhttp.status==200) { | |
if (xmlhttp.getResponseHeader("x-check-tor")) { | |
window.location.href = url; | |
} | |
} | |
} | |
xmlhttp.open("GET", test_url, true); | |
xmlhttp.send(); | |
} | |
} catch(err) { | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment