Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/static/captcha.js

26 lines
764 B
JavaScript
Raw Permalink Normal View History

2015-08-04 19:03:44 +05:00
//
// sorry I can't think of any better way to do captcha ;~;
//
window.addEventListener('load', function() {
// get new captcha
var ajax = new XMLHttpRequest();
// get form elements for captcha
var elem_input = document.getElementById("captcha_input");
var elem_img = document.getElementById("captcha_img");
// prepare ajax
ajax.onreadystatechange = function(ev) {
if ( ajax.readyState == XMLHttpRequest.DONE && ajax.status == 200 ) {
// we succeeded
var captcha_id = ajax.responseText;
// set captcha id
elem_input.value = captcha_id;
// set captcha image
elem_img.src = "captcha/" + captcha_id + ".png";
}
};
// open and send the ajax request
ajax.open("GET", "captcha/new");
ajax.send();
});