// by @kushalcodes (https://github.com/kushalcodes)
// https://www.neupanekushal.com.np
let __Captcha = null; !function () { function t(t) { this.id = t.id, this.value = t.value } __Captcha = { name: "__captcha", type: "NUMBER", idCounter: 0, captchas: [], currentCaptchaParent: null, submitIcon: null, css: !0, getRandCaptchaValue: function () { const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", e = this.getGenRand(t.length - 1, 0), n = this.getGenRand(t.length - 1, 0), a = this.getGenRand(t.length - 1, 0); return this.getGenRand(9, 0) + t[e] + this.getGenRand(9, 0) + t[n] + this.getGenRand(9, 0) + t[a] }, genRandNum: function () { const e = this.getRandCaptchaValue(); this.captchas[this.idCounter] = new t({ id: this.idCounter, value: e }), this.idCounter++ }, getGenRand: function (t, e) { const n = this.essentials.rand(t, e); return "number" != typeof n ? "A" : n }, setupCaptcha: function () { this.genRandNum() }, essentials: { rand: function (t, e) { return Math.floor(Math.random() * (t - e + 1)) + e }, insertAfter: function (t, e) { e.parentNode.insertBefore(t, e.nextSibling) } }, generate: function () { this.setupCaptcha() }, captchaCSS: "https://cdn.jsdelivr.net/gh/kushalcodes/captcha-gen-js@master/captcha.css", initCss: function () { const t = document.createElement("link"); t.href = this.captchaCSS, t.rel = "stylesheet", document.getElementsByTagName("head")[0].appendChild(t) }, handleEnterOnInput: function (t) { if ("enter" === t.code.toLowerCase()) { const t = this.id.replace("__captcha_input_", ""); document.getElementById("__captcha_submit_" + t).click() } }, initEnterKeyInput: function () { const t = document.getElementsByClassName("__captcha_input"); for (let e = 0; e < t.length; e++)t[e].onkeyup = this.handleEnterOnInput }, initCaptchaElements: function () { this.generate(); const t = this.captchas[this.captchas.length - 1], e = this.currentCaptchaParent; e.innerHTML = "", e.className += " __captcha_main", e.innerHTML += "<div class='__captcha_value __border_color_default' id='__captcha_value_" + t.id + "'>" + t.value + "</div>", e.innerHTML += "<input type='button' tabindex='-1' title='Reload' class='__captcha_btn __captcha_reload __border_color_default' id='__captcha_refresh_" + t.id + "' value = '&#10227;' onclick='__Captcha.refresh(" + t.id + ") '/>", e.innerHTML += "<input type='text' class='__captcha_input __border_color_default" + (this.submitIcon ? " custom" : "") + "' tabindex='0' id='__captcha_input_" + t.id + "' placeholder = 'Enter captcha' maxlength = '6' />", e.innerHTML += "<input type='button' title='Check' tabindex='-1' class='__captcha_btn __border_color_default" + (this.submitIcon ? " custom" : "") + "' id='__captcha_submit_" + t.id + "' style='" + (this.submitIcon ? "background-image:url(" + this.submitIcon.url + ");" + (this.submitIcon.size ? "background-size:" + this.submitIcon.size + ";" : "") : "") + "' value = '" + (this.submitIcon ? "" : ">") + "' onclick='__Captcha.match(" + t.id + ") '/>" }, match: function (t) { const e = this.verify(t); this.onVerify[t]({ verified: e, captcha: { userInput: document.getElementById("__captcha_input_" + t).value, value: this.captchas[t].value, id: this.captchas[t].id, els: { parent: document.getElementById("__captcha_input_" + t).parentElement, input: document.getElementById("__captcha_input_" + t), value: document.getElementById("__captcha_value_" + t), reload: document.getElementById("__captcha_refresh_" + t), submit: document.getElementById("__captcha_submit_" + t) } } }) }, verify: function (t) { return this.captchas[t].value === document.getElementById("__captcha_input_" + t).value }, refresh: function (t) { const e = this.getRandCaptchaValue(); document.getElementById("__captcha_value_" + t).innerText = e, this.captchas[t].value = e }, onVerify: [], default: { verify: function (t) { t.verified ? alert("Success: Captcha matched") : alert("Error: Captcha mismatch") } }, handleParams: function (t) { }, init: function (t, e, n) { this.css && this.initCss(), this.handleParams(n), this.initInner(t, e), this.initEnterKeyInput() }, warned: !1, initInner: function (t, e) { if ("string" == typeof t) { if ("function" != typeof e && (this.warned || console.warn("captcha-gen-js : No function passed for verification callback, default verification callback used", this.default.verify), e = this.default.verify, this.warned = !0), "#" !== t[0] && "." !== t[0] && (t = "#" + t), "#" === t[0]) { const n = document.getElementById(t.replace("#", "")); return n ? (this.currentCaptchaParent = n, this.initCaptchaElements(), void this.onVerify.push(e)) : void console.error("captcha-gen-js : No element exist on DOM with id of ", t) } if ("." !== t[0]); else { const n = document.getElementsByClassName(t.replace(".", "")); if (0 === n.length) return void console.error("captcha-gen-js : No elements found on DOM with class name of ", t); for (let t = 0; t < n.length; t++) { const a = n[t]; this.currentCaptchaParent = a, this.initCaptchaElements(), this.onVerify.push(e) } } } else console.error("captcha-gen-js : Invalid element passed for initliazing captcha.", t) }, setSubmitIcon: function (t) { "object" == typeof t ? this.submitIcon = t : console.error("captcha-gen-js: Submit icon parameter expects object passed " + typeof t + " > " + t) } } }();