Бот для капчи в чатах
Roman Sergienko
12 hours ago 2717f2c1bb4e325f70f806b323c3cb3d63b3b3d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const tg = window.Telegram && window.Telegram.WebApp;
const status = document.getElementById("status");
const retry = document.getElementById("retry");
 
async function authenticate() {
    if (!tg || !tg.initData) {
        status.textContent = "Откройте панель кнопкой Mini App в Telegram.";
        retry.classList.remove("hidden");
        return;
    }
 
    tg.ready();
    try {
        const params = new URLSearchParams(location.search);
        params.delete("auth");
        const destination = "/miniapp" + (params.size ? "?" + params.toString() : "");
        const response = await fetch("/auth/miniapp", {
            method: "POST",
            credentials: "same-origin",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({ init_data: tg.initData })
        });
        const result = await response.json();
        if (!response.ok || !result.ok) throw new Error(result.msg || "Не удалось войти.");
        location.replace(destination);
    } catch (error) {
        status.textContent = error.message || "Не удалось выполнить вход. Попробуйте ещё раз.";
        retry.classList.remove("hidden");
    }
}
 
retry.addEventListener("click", authenticate);
authenticate();