-
Notifications
You must be signed in to change notification settings - Fork 6
/
clickCaptcha.js
114 lines (94 loc) · 2.25 KB
/
clickCaptcha.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Click CAPTCHA 0.1.1
// Created by Jonathan Decker
URLGenerate = "generateCaptcha.php";
URLSubmit = "compare.php";
divStr = 'Click the circle<input type="image" id="captcha_image" src="data:image/png;base64,';
function createRequestObject() {
var ro;
// almost everyone but MSIE less than 7
try
{
ro = new XMLHttpRequest();
// MSIE branches
}
catch (e)
{
try
{
ro = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ro = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
ro = null;
}
}
}
return ro;
}
var http = createRequestObject();
function initCaptcha()
{
divele = document.getElementById("captcha");
divele.innerHTML = divStr + imgData + '"/>';
imgele = document.getElementById("captcha_image");
imgele.onclick = submitForm;
}
function handleSubmitResponse()
{
if(http.readyState == 4)
{
if( http.responseText == 'TRUE')
{
onCaptchaSuccess();
}
else
{
onCaptchaFailed();
}
}
}
function submitForm(e)
{
imgele = document.getElementById("captcha_image");
img_left = imgele.offsetLeft;
img_top = imgele.offsetTop;
var pos_x = e.offsetX ? (e.offsetX) : e.pageX-img_left;
var pos_y = e.offsetY ? (e.offsetY) : e.pageY-img_top;
http.open('POST', URLSubmit, true);
var paramStr = 'h=' + targetHash;
paramStr += '&x=' + Math.floor(pos_x / dotSize);
paramStr += '&y=' + Math.floor(pos_y / dotSize);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = handleSubmitResponse;
http.send(paramStr);
}
function handleGenerateResponse()
{
if(http.readyState == 4)
{
//var obj jQuery.parseJSON( http.responseText );
var obj = eval("(" + http.responseText + ')');
targetHash = obj.targetHash;
imgData = obj.imgData;
count_misses = 0;
divele = document.getElementById("captcha");
divele.onclick = submitForm;
divele.innerHTML = divStr + imgData + '"/>';
onNewCaptcha();
}
}
function requestNewCaptcha()
{
http.open('POST', URLGenerate, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = handleGenerateResponse;
http.send();
divele = document.getElementById("captcha");
divele.onclick = null;
}