Skip to content

Instantly share code, notes, and snippets.

@evilaliv3
Last active August 29, 2015 14:15
Show Gist options
  • Save evilaliv3/5ee41687cd8e1054e54d to your computer and use it in GitHub Desktop.
Save evilaliv3/5ee41687cd8e1054e54d to your computer and use it in GitHub Desktop.
Javascript CheckTor library
<script>
/*
Copyright 2015 - Hermes Center - GlobaLeaks project
Author <giovanni.pellerano@evilaliv3.org>
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