Skip to content

Commit

Permalink
Add checktor.js script to misc scripts useful for Tor2web integration
Browse files Browse the repository at this point in the history
  • Loading branch information
evilaliv3 committed Feb 23, 2015
1 parent 88e3eca commit 62e4fd9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions misc/checktor.js
@@ -0,0 +1,33 @@
/*
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) {

}
}

0 comments on commit 62e4fd9

Please sign in to comment.