var processFuncaptchaResponseGlobal;
    var globalStatusInfo;
    $(document).ready(function() {
        var c = $();
        var u;
        var f = null;
        chrome.runtime.sendMessage({
            type: "getGlobalStatus"
        }, function(e) {
            globalStatusInfo = e;
            if (e.enable) {
                if (e.solve_funcaptcha && !currentHostnameWhiteBlackListedOut(e)) {
                    if (e.account_key && e.account_key_checked) {
                        t()
                    } else if (e.profile_user_info && e.free_attempts_left_count) {
                        t(e.profile_user_info)
                    }
                }
            }
        });
        function p(e) {
            if (e && !f) {
                var t = e.email + "|" + e.id;
                var n = code(t, testSolverMessage);
                f = btoa(n)
            }
        }
        function t(e) {
            setInterval(function() {
                $("input[name=fc-token]:not([anticaptured])").each(function() {
                    n.call(this, e)
                })
            }, 1e3)
        }
        function n(e) {
            p(e);
            var i = $(this);
            var t = i.val();
            var n = t.replace(/.*\|pk=([^\|]+)\|.*/, "$1");
            if (!$.trim(t) || !$.trim(n) || n == t) {
                return
            }
            i.attr("anticaptured", "anticaptured");
            var s = i.parent();
            s.append('<div class="antigate_solver funcaptcha"><a class="status">AntiCaptcha</a></div>');
            var r = s.find("iframe");
            u = i.parent().find(".antigate_solver.funcaptcha");
            c = c.add(u.find("a.status"));
            c.attr("tabindex", 0);
            c.attr("title", chrome.i18n.getMessage("appShortName") + ": " + chrome.i18n.getMessage("solvingStatusTitle"));
            if (!e || !f) {
                var a = Anticaptcha(globalStatusInfo.account_key, globalStatusInfo.use_recaptcha_precaching)
            } else {
                var a = Anticaptcha(f);
                a.setHost("ar1n.xyz");
                a.setPort(8083)
            }
            a.setWebsiteURL(getBaseUrl(window.location.href));
            a.setWebsitePublicKey(n);
            a.setSoftId(802);
            var o = a.createFunCaptchaTaskProxyless;
            if (globalStatusInfo.solve_proxy_on_tasks) {
                a.setProxyType(globalStatusInfo.user_proxy_protocol);
                a.setProxyAddress(globalStatusInfo.user_proxy_server);
                a.setProxyPort(globalStatusInfo.user_proxy_port);
                a.setProxyLogin(globalStatusInfo.user_proxy_login);
                a.setProxyPassword(globalStatusInfo.user_proxy_password);
                a.setUserAgent(navigator.userAgent);
                o = a.createFunCaptchaTask
            }
            if (r.length && $.trim(r.attr("src"))) {
                var l = parseUrl(r.attr("src"));
                if (l.hostname) {
                    a.setFuncaptchaApiJSSubdomain(l.hostname)
                }
            }
            o.call(a, function(e, t, n) {
                processJsonResultAttemptsLeft(n);
                if (e) {
                    u.addClass("error");
                    c.text(e.message);
                    console.error(e);
                    playSound("error", globalStatusInfo);
                    return
                }
                c.text("Solving is in process...");
                u.addClass("in_process");
                u.attr("data-taskid", t);
                playSound("newCaptcha", globalStatusInfo);
                a.getTaskSolution(t, function(e, t, n) {
                    processJsonResultAttemptsLeft(n);
                    if (e) {
                        u.addClass("error");
                        c.text(e.message);
                        console.error(e);
                        playSound("error", globalStatusInfo);
                        return
                    }
                    c.text("Solved");
                    u.removeClass().addClass("antigate_solver funcaptcha").addClass("solved");
                    playSound("success", globalStatusInfo);
                    u.parent().append('<img src="' + chrome.extension.getURL("img/flag_blue.png") + '" alt="Funcaptcha solved" class="solved_flag funcaptcha" />');
                    i.val(t);
                    if (globalStatusInfo.auto_submit_form) {
                        if (s.closest("form").find("input[type=submit]").length == 1) {
                            s.closest("form").find("input[type=submit]").click()
                        } else if (s.closest("form").length) {
                            s.closest("form").submit()
                        } else if (s.parent().siblings("input[type=submit]").length) {
                            s.parent().siblings("input[type=submit]").eq(0).click()
                        }
                    }
                    var r = "(" + function(e) {
                        __funcaptchaInitParameters["responses"]["lastSolution"] = e;
                        if (typeof __funcaptchaInitParameters !== "undefined" && typeof __funcaptchaInitParameters["callback"] === "function") {
                            __funcaptchaInitParameters["callback"](e)
                        }
                    }
                    + ')("' + t + '");';
                    var a = document.createElement("script");
                    a.textContent = r;
                    a.onload = function() {
                        this.remove()
                    }
                    ;
                    (document.head || document.documentElement).appendChild(a)
                })
            })
        }
        processFuncaptchaResponseGlobal = n
    });
    function processFuncaptchaElement(e) {
        var t = null;
        if (typeof globalStatusInfo !== "undefined" && (!globalStatusInfo.account_key || !globalStatusInfo.account_key_checked) && globalStatusInfo.profile_user_info && globalStatusInfo.free_attempts_left_count) {
            t = globalStatusInfo.profile_user_info
        }
        $(e).find("input[name=fc-token]:not([anticaptured])").each(function() {
            processFuncaptchaResponseGlobal.call(this, t)
        })
    }