mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
window.addEventListener('DOMContentLoaded', (event) => {
|
|
|
|
const captchaFields = document.getElementsByClassName('captchafield');
|
|
|
|
const refreshCaptcha = function(e) {
|
|
if (this.refreshing) {
|
|
return;
|
|
}
|
|
this.refreshing = true;
|
|
document.cookie = 'captchaid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
const captchaImg = this;
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.onload = function() {
|
|
captchaImg.src = xhr.responseURL;
|
|
captchaImg.refreshing = false;
|
|
}
|
|
xhr.open('GET', '/captcha', true);
|
|
xhr.send(null);
|
|
};
|
|
|
|
const loadCaptcha = function(e) {
|
|
const captchaDiv = this.previousSibling;
|
|
const captchaImg = document.createElement('img');
|
|
const field = this;
|
|
captchaImg.src = '/captcha';
|
|
captchaImg.onload = function() {
|
|
field.placeholder = 'double click image to refresh';
|
|
captchaDiv.appendChild(captchaImg);
|
|
captchaDiv.style.display = '';
|
|
captchaImg.addEventListener('dblclick', refreshCaptcha, true);
|
|
}
|
|
};
|
|
|
|
for (let i = 0; i < captchaFields.length; i++) {
|
|
captchaFields[i].placeholder = 'click to load';
|
|
captchaFields[i].addEventListener('click', loadCaptcha, { once: true });
|
|
}
|
|
|
|
});
|
|
|