-
Notifications
You must be signed in to change notification settings - Fork 5
/
hcaptcha.js
39 lines (36 loc) · 1.47 KB
/
hcaptcha.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
function submitCaptchaForm() {
const resp = document.getElementsByName('h-captcha-response')[0].value;
document.getElementById('resp').value = resp;
window.scrollTo(0, document.body.scrollHeight);
}
function copyToClipboard() {
navigator.clipboard.writeText(document.getElementById('resp').value);
document.getElementById('cpmessage').innerHTML = '<p>Copied to clipboard!</p>';
setTimeout(function() {
document.getElementById('cpmessage').innerHTML = '';
}, 2500);
}
window.addEventListener('load', function () {
if (!navigator.clipboard) {
document.getElementById('copybt').style.display = 'none';
}
document.querySelector('#hcaptcha-form').onsubmit = function(e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
submitCaptchaForm();
};
document.getElementById('resp').value = '';
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const siteKey = urlParams.get('sitekey');
if (siteKey && /^([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$/.test(siteKey)) {
const hdiv = document.getElementById("h-captcha-div");
hdiv.dataset.sitekey=siteKey;
this.document.querySelector('#sitekey').value = siteKey;
hcaptcha.render('h-captcha-div', {
sitekey: siteKey,
callback: submitCaptchaForm,
});
} else {
this.document.querySelector('#error2').innerHTML = 'No valid sitekey provided.';
}
});