-
Notifications
You must be signed in to change notification settings - Fork 0
/
v3.html
113 lines (92 loc) · 2.48 KB
/
v3.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ReCaptcha v3 Tester</title>
</head>
<body>
<p>
Site key: <input id="site-key">
</p>
<p>
<button onclick="createRecaptcha()">Create</button>
<button onclick="resetRecaptcha()">Reset</button>
<button onclick="generateToken()">Generate Token</button>
</p>
<p>
<strong>Current site key:</strong>
<span id="curr-site-key" class="mono">(press create)</span>
</p>
<p>
<strong>Result (click to copy):</strong>
</p>
<p
id="result"
class="mono"
onclick="copyResult()"
></p>
<textarea id="clipboard"></textarea>
<script>
const $siteKey = document.querySelector('#site-key');
const $currSiteKey = document.querySelector('#curr-site-key');
const $result = document.querySelector('#result');
const $clipboard = document.querySelector('#clipboard');
let siteKey = '6LdqtwgcAAAAAAvk5IXCQhwJcIkhbZTW-d882i8k';
$siteKey.value = siteKey;
let resultToken;
function createRecaptcha() {
siteKey = $siteKey.value;
$currSiteKey.textContent = siteKey;
resetRecaptcha();
}
function resetRecaptcha() {
const oldScript = document.querySelector('script.recaptcha-api');
if (oldScript) {
document.body.removeChild(oldScript);
}
const script = document.createElement('script');
script.src = 'https://www.google.com/recaptcha/api.js?render=' + siteKey;
script.classList.add = 'recaptcha-api';
document.body.append(script);
$result.textContent = '(press Generate Token)';
}
// https://developers.google.com/recaptcha/docs/v3
async function generateToken() {
await new Promise(ok => grecaptcha.ready(ok));
resultToken = await grecaptcha.execute(siteKey, { action: 'submit' });
$result.textContent = resultToken;
}
function copyResult() {
$clipboard.value = resultToken;
$clipboard.focus();
$clipboard.select();
document.execCommand('copy');
}
</script>
<style>
html {
font-family: sans-serif;
box-sizing: border-box;
}
*, *::before, *::after {
box-sizing: inherit;
}
input {
width: 400px;
}
.mono {
font-family: monospace;
}
textarea {
position: fixed;
top: -1000px;
left: -1000px;
}
#result {
max-width: 600px;
line-break: anywhere;
}
</style>
</body>
</html>