-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
40 lines (37 loc) · 1.51 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<script src='wasm_exec.js'></script>
<script>
if (WebAssembly) {
const go = new Go();
WebAssembly.instantiateStreaming(fetch('wasm/captcha.wasm'), go.importObject).then((result) => {
go.run(result.instance);
const img = document.createElement('img');
img.src = generateCaptcha();
document.body.appendChild(img);
const form = document.createElement('div');
const captchaInput = document.createElement('input');
captchaInput.setAttribute('type', 'text');
captchaInput.setAttribute('placeholder', 'Enter captcha');
captchaInput.onkeydown = function(e) {
if (e.key == "Enter") {
if (!verifyCaptcha(captchaInput.value)) {
alert('Wrong captcha');
captchaInput.value = '';
} else {
alert('Success!');
}
}
};
form.appendChild(captchaInput);
document.body.appendChild(form);
});
} else {
console.log('WebAssembly is not supported in your browser')
}
</script>
</head>
<body></body>
</html>