Добавлена Яндекс.Капча

This commit is contained in:
mi
2026-07-23 18:53:32 +03:00
parent 31efbf3b69
commit 8c3c454998
36 changed files with 836 additions and 35 deletions
@@ -127,11 +127,97 @@
updateCountdown();
if (expiresAt > Date.now()) timer = window.setInterval(updateCountdown, 1000);
resend.addEventListener("click", function () {
if (document.getElementById("han-captcha-container")) return;
window.setTimeout(function () { resend.disabled = true; }, 0);
});
}
function initCaptcha() {
var container = document.getElementById("han-captcha-container");
if (!container) return;
var form = document.getElementById(container.getAttribute("data-form-id"));
var tokenInput = document.getElementById("han-captcha-token");
var error = document.getElementById("han-captcha-client-error");
var resendOnly = container.getAttribute("data-resend-only") === "true";
var widgetId = null;
var executing = false;
var pendingSubmitter = null;
function showError() {
executing = false;
if (pendingSubmitter) pendingSubmitter.disabled = false;
pendingSubmitter = null;
if (tokenInput) tokenInput.value = "";
if (error) error.hidden = false;
}
window.hanCaptchaOnload = function () {
if (!window.smartCaptcha || !form || !tokenInput) {
showError();
return;
}
try {
widgetId = window.smartCaptcha.render(container, {
sitekey: container.getAttribute("data-sitekey"),
invisible: true,
hl: "ru",
callback: function (token) {
if (!token || !pendingSubmitter) {
showError();
return;
}
var submitter = pendingSubmitter;
pendingSubmitter = null;
executing = false;
tokenInput.value = token;
if (submitter.name) {
var action = document.createElement("input");
action.type = "hidden";
action.name = submitter.name;
action.value = submitter.value;
form.appendChild(action);
}
HTMLFormElement.prototype.submit.call(form);
}
});
window.smartCaptcha.subscribe(widgetId, "network-error", showError);
window.smartCaptcha.subscribe(widgetId, "javascript-error", showError);
window.smartCaptcha.subscribe(widgetId, "token-expired", function () {
tokenInput.value = "";
if (executing) showError();
});
} catch (_error) {
showError();
}
};
if (!form || !tokenInput) return;
form.addEventListener("submit", function (event) {
var submitter = event.submitter;
var requiresCaptcha = !resendOnly
|| (submitter && submitter.name === "otp_action" && submitter.value === "resend");
if (!requiresCaptcha) return;
event.preventDefault();
if (executing) return;
if (error) error.hidden = true;
if (widgetId === null || !window.smartCaptcha) {
showError();
return;
}
pendingSubmitter = submitter || document.getElementById(container.getAttribute("data-submit-id"));
executing = true;
if (pendingSubmitter) pendingSubmitter.disabled = true;
tokenInput.value = "";
try {
window.smartCaptcha.execute(widgetId);
} catch (_error) {
showError();
}
});
}
initDeviceMetadata();
initPhoneForm();
initOtpForm();
initCaptcha();
})();