forked from GeorgeChan/captchapng
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.sample.html
82 lines (76 loc) · 2.01 KB
/
index.sample.html
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
<!DOCTYPE html>
<html>
<body onload="getCaptcha();">
<div class="d-flex flex-col align-items-center w-100">
<div class="d-flex flex-row align-items-center">
<img
src="test.jpg"
alt="captcha"
id="mainCaptcha"
width="120"
height="30"
/>
<input
type="button"
id="refresh"
value="Refresh"
onclick="getCaptcha();"
/>
</div>
<input type="text" id="txtInput" />
<input
id="Button1"
type="button"
value="Check"
onclick="alert(ValidCaptcha());"
/>
</div>
<style type="text/css">
.d-flex {
display: flex;
}
.align-items-center {
align-items: center;
}
.flex-col {
flex-direction: column;
}
.flex-row {
flex-direction: row;
}
.w-100 {
width: 100%;
}
</style>
</body>
<script type="text/javascript">
function getCaptcha() {
let token = "";
const url = "http://127.0.0.1:9000/";
fetch(url)
.then((response) => {
token = response.headers.get("token");
return response.blob();
})
.then((images) => {
outside = URL.createObjectURL(images);
const captchaElement = document.getElementById("mainCaptcha");
captchaElement.src = outside;
captchaElement.setAttribute("data-token", token);
});
}
function isValidCaptcha() {
const captchaElement = document.getElementById("mainCaptcha");
const captchaInput = document.getElementById("captchaInput").value;
const token = captchaElement.getAttribute("data-token");
const url = `http://127.0.0.1:9000/verify?token=${token}&captcha=${captchaInput}`;
console.log({ url });
return fetch(url).then((response) => {
return response.status === 200;
});
}
function removeSpaces(string) {
return string.split(" ").join("");
}
</script>
</html>