function notarobot(d) { if (typeof d === 'string' || d instanceof String) d = document.getElementById(d) d.classList.add('notarobot-cb') const style = document.createElement('style'); style.textContent = `.notarobot-cb { border: 1px solid #333; border-radius: 5px; background: white; -webkit-user-select: none; -ms-user-select: none; user-select: none; width: 218px; } .notarobot-cb input { transform: scale(2); margin: 16px; } .notarobot-cb.error { background-color: #ffb4b4; color: white; } .notarobot-cb input.done { cursor: default; pointer-events: none; }`; document.head.appendChild(style); const c = document.createElement('input'); c.type = 'checkbox'; c.name = 'notarobot_434350'; c.id = 'notarobot_checkbox'; c.value = 'false'; c.className = 'simple'; const s = document.createElement('span'); s.textContent = 'I\'m not a robot'; d.appendChild(c); d.appendChild(s); } notarobot('validation'); ( function() { let _k = { b: 0, e: 0, l: 0 } let _m = { b: 0, e: 0, l: 0 } let _ = false; const i = document.getElementById('notarobot_checkbox') i.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); if (_) { return false; } i.disabled = true i.checked = false let d = { k: _k, m: _m, t: getTime() } fetch('/inc/confirm/notarobot.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: $.param(d) }) .then(function(response) { return response.json(); }) .then(function(jsonResponse) { i.checked = true i.value = jsonResponse.v i.disabled = false _ = true i.classList.add('done') let err = document.getElementsByClassName('notarobot error'); if (err.length) { err[0].remove() } }) .catch(function() { i.checked = false i.disabled = true i.parentElement.classList.add('error') setTimeout(function(){ i.checked = false i.disabled = false i.parentElement.classList.remove('error') }, 400) }); return false; }) i.addEventListener('keydown', function (e) { _k.b = getTime() }) i.addEventListener('keyup', function (e) { _k.l = getTime() - _k.b }) i.addEventListener('mousedown', function (e) { _m.b = getTime() }) i.addEventListener('mouseup', function (e) { _m.l = getTime() - _m.b }) function getTime() { return window.performance.now(); // Date.now(); } })();