mirror of https://github.com/coddrago/Heroku
273 lines
12 KiB
JavaScript
273 lines
12 KiB
JavaScript
function auth(e) {
|
|
$(".main").fadeOut(250), setTimeout((() => {
|
|
$(".auth").hide().fadeIn(250, (() => {
|
|
$("#tg_icon").html(""), bodymovin.loadAnimation({
|
|
container: document.getElementById("tg_icon"),
|
|
renderer: "canvas",
|
|
loop: !0,
|
|
autoplay: !0,
|
|
path: "https://assets9.lottiefiles.com/packages/lf20_bgqoyj8l.json",
|
|
rendererSettings: {
|
|
clearCanvas: !0
|
|
}
|
|
})
|
|
})), fetch("/web_auth", {
|
|
method: "POST",
|
|
credentials: "include",
|
|
timeout: 25e4
|
|
}).then((e => e.text())).then((t => "TIMEOUT" == t ? (error_message("Code waiting timeout exceeded. Reload page and try again."), void $(".auth").fadeOut(250)) : t.startsWith("hikka_") ? ($.cookie("session", t), auth_required = !1, $(".authorized").hide().fadeIn(100), $(".auth").fadeOut(250, (() => {
|
|
$(".installation").fadeIn(250)
|
|
})), void e()) : void 0))
|
|
}), 250)
|
|
}
|
|
var qr_interval = null,
|
|
qr_login = !1,
|
|
old_qr_sizes = [document.querySelector(".qr_inner").style.width, document.querySelector(".qr_inner").style.height];
|
|
|
|
function login_qr() {
|
|
$("#continue_btn").fadeOut(100), $("#denyqr").hide().fadeIn(250), $(".title, .description").fadeOut(250), fetch("/init_qr_login", {
|
|
method: "POST",
|
|
credentials: "include"
|
|
}).then((e => e.text())).then((e => {
|
|
const t = new QRCodeStyling({
|
|
width: window.innerHeight / 3,
|
|
height: window.innerHeight / 3,
|
|
type: "svg",
|
|
data: e,
|
|
dotsOptions: {
|
|
type: "rounded"
|
|
},
|
|
cornersSquareOptions: {
|
|
type: "extra-rounded"
|
|
},
|
|
backgroundOptions: {
|
|
color: "transparent"
|
|
},
|
|
imageOptions: {
|
|
imageSize: .4,
|
|
margin: 8
|
|
},
|
|
qrOptions: {
|
|
errorCorrectionLevel: "M"
|
|
}
|
|
});
|
|
document.querySelector(".qr_inner").innerHTML = "", document.querySelector(".qr_inner").style.width = old_qr_sizes[0], document.querySelector(".qr_inner").style.height = old_qr_sizes[1], t.append(document.querySelector(".qr_inner")), qr_interval = setInterval((() => {
|
|
fetch("/get_qr_url", {
|
|
method: "POST",
|
|
credentials: "include"
|
|
}).then((e => e.text())).then((e => "SUCCESS" == e || "2FA" == e ? ($("#block_qr_login").fadeOut(250), $("#denyqr").fadeOut(250), $("#continue_btn, .title, .description").hide().fadeIn(250), "SUCCESS" == e && switch_block("custom_bot"), "2FA" == e && (show_2fa(), qr_login = !0), void clearInterval(qr_interval)) : void t.update({
|
|
data: e
|
|
})))
|
|
}), 1250)
|
|
}))
|
|
}
|
|
|
|
function isInt(e) {
|
|
var t = parseFloat(e);
|
|
return !isNaN(e) && (0 | t) === t
|
|
}
|
|
|
|
function isValidPhone(e) {
|
|
return /^[+]?\d{11,13}$/.test(e)
|
|
}
|
|
|
|
function finish_login() {
|
|
fetch("/finish_login", {
|
|
method: "POST",
|
|
credentials: "include"
|
|
}).then((() => {
|
|
$(".installation").fadeOut(2e3), setTimeout((() => {
|
|
$("#installation_icon").html(""), bodymovin.loadAnimation({
|
|
container: document.getElementById("installation_icon"),
|
|
renderer: "canvas",
|
|
loop: !0,
|
|
autoplay: !0,
|
|
path: "https://assets1.lottiefiles.com/packages/lf20_n3jgitst.json",
|
|
rendererSettings: {
|
|
clearCanvas: !0
|
|
}
|
|
}), $(".finish_block").fadeIn(250)
|
|
}), 2e3)
|
|
})).catch((e => {
|
|
error_state(), error_message("Login confirmation error: " + e.toString())
|
|
}))
|
|
}
|
|
|
|
function show_2fa() {
|
|
$(".auth-code-form").hide().fadeIn(250, (() => {
|
|
$("#monkey-close").html(""), (anim = bodymovin.loadAnimation({
|
|
container: document.getElementById("monkey-close"),
|
|
renderer: "canvas",
|
|
loop: !0,
|
|
autoplay: !0,
|
|
path: "https://assets1.lottiefiles.com/packages/lf20_eg88dyk9.json",
|
|
rendererSettings: {
|
|
clearCanvas: !0
|
|
}
|
|
})).addEventListener("complete", (() => {
|
|
setTimeout((() => {
|
|
anim.goToAndPlay(0)
|
|
}), 2e3)
|
|
}))
|
|
})), $(".code-input").removeAttr("disabled"), $(".code-input").attr("inputmode", "text"), $(".code-input").attr("autocomplete", "off"), $(".code-input").attr("autocorrect", "off"), $(".code-input").attr("autocapitalize", "off"), $(".code-input").attr("spellcheck", "false"), $(".code-input").attr("type", "password"), $(".enter").hasClass("tgcode") && $(".enter").removeClass("tgcode"), $(".code-caption").html("Enter your Telegram 2FA password, then press <span style='color: #dc137b;'>Enter</span>"), cnt_btn.setAttribute("current-step", "2fa"), $("#monkey").hide(), $("#monkey-close").hide().fadeIn(100), _current_block = "2fa"
|
|
}
|
|
|
|
function show_eula() {
|
|
$(".main").fadeOut(250), $(".eula-form").hide().fadeIn(250, (() => {
|
|
$("#law").html(""), anim = bodymovin.loadAnimation({
|
|
container: document.getElementById("law"),
|
|
renderer: "canvas",
|
|
loop: !0,
|
|
autoplay: !0,
|
|
path: "https://static.dan.tatar/forbidden.json",
|
|
rendererSettings: {
|
|
clearCanvas: !0
|
|
}
|
|
})
|
|
}))
|
|
}
|
|
|
|
function tg_code(e = !1) {
|
|
return e && qr_login ? void fetch("/qr_2fa", {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: _2fa_pass
|
|
}).then((e => {
|
|
e.ok ? ($(".auth-code-form").fadeOut(), $("#block_phone").fadeOut(), switch_block("custom_bot")) : ($(".code-input").removeAttr("disabled"), e.text().then((e => {
|
|
error_state(), Swal.fire("Error", e, "error")
|
|
})))
|
|
})) : void fetch("/tg_code", {
|
|
method: "POST",
|
|
body: _tg_pass + `\n${_phone}\n` + _2fa_pass
|
|
}).then((e => {
|
|
e.ok ? ($(".auth-code-form").fadeOut(), $("#block_phone").fadeOut(), switch_block("custom_bot")) : 401 == e.status ? show_2fa() : ($(".code-input").removeAttr("disabled"), e.text().then((e => {
|
|
error_state(), Swal.fire("Error", e, "error")
|
|
})))
|
|
})).catch((e => {
|
|
Swal.showValidationMessage("Auth failed: " + e.toString())
|
|
}))
|
|
}
|
|
|
|
function switch_block(e) {
|
|
cnt_btn.setAttribute("current-step", e);
|
|
try {
|
|
$("#block_" + _current_block).fadeOut((() => {
|
|
$("#block_" + e).hide().fadeIn()
|
|
}))
|
|
} catch {
|
|
$("#block_" + e).hide().fadeIn()
|
|
}
|
|
"qr_login" == (_current_block = e) && login_qr()
|
|
}
|
|
|
|
function error_message(e) {
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: e
|
|
})
|
|
}
|
|
|
|
function error_state() {
|
|
$("body").addClass("red_state"), cnt_btn.disabled = !0, setTimeout((() => {
|
|
cnt_btn.disabled = !1, $("body").removeClass("red_state")
|
|
}), 1e3)
|
|
}
|
|
document.querySelector(".qr_inner").style.width = "100px", document.querySelector(".qr_inner").style.height = "100px", $("#get_started").click((() => {
|
|
fetch("/can_add", {
|
|
method: "POST",
|
|
credentials: "include"
|
|
}).then((e => e.ok ? auth_required ? auth((() => {
|
|
$("#get_started").click()
|
|
})) : ($("#continue_btn").hide().fadeIn(250), $("#denyqr").hide(), $("#enter_api").fadeOut(250), void $("#get_started").fadeOut(250, (() => {
|
|
switch_block(_current_block)
|
|
}))) : void show_eula()))
|
|
})), $("#enter_api").click((() => auth_required ? auth((() => {
|
|
$("#enter_api").click()
|
|
})) : ($("#get_started").fadeOut(250), void $("#enter_api").fadeOut(250, (() => {
|
|
$("#continue_btn").hide().fadeIn(250), switch_block("api_id")
|
|
})))));
|
|
var _api_id = "",
|
|
_api_hash = "",
|
|
_phone = "",
|
|
_2fa_pass = "",
|
|
_tg_pass = "",
|
|
_current_block = skip_creds ? "qr_login" : "api_id";
|
|
|
|
function is_phone() {
|
|
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i.test(navigator.userAgent)
|
|
}
|
|
is_phone() && "qr_login" == _current_block && (_current_block = "phone");
|
|
const cnt_btn = document.querySelector("#continue_btn");
|
|
|
|
function process_next() {
|
|
var e = cnt_btn.getAttribute("current-step");
|
|
if ("api_id" == e) return (t = document.querySelector("#api_id").value).length < 4 || !isInt(t) ? void error_state() : (_api_id = parseInt(t, 10), void switch_block("api_hash"));
|
|
if ("api_hash" == e) return 32 == (t = document.querySelector("#api_hash").value).length ? void fetch("/set_api", {
|
|
method: "PUT",
|
|
body: (_api_hash = t) + _api_id,
|
|
credentials: "include"
|
|
}).then((e => e.text())).then((e => {
|
|
"ok" == e ? switch_block(is_phone() ? "phone" : "qr_login") : (error_state(), error_message(e))
|
|
})).catch((e => {
|
|
error_state(), error_message("Error occured while saving credentials: " + e.toString())
|
|
})) : void error_state();
|
|
if ("phone" == e) {
|
|
var t = document.querySelector("#phone").value;
|
|
if (!isValidPhone(t)) return void error_state();
|
|
_phone = t, fetch("/send_tg_code", {
|
|
method: "POST",
|
|
body: _phone,
|
|
credentials: "include"
|
|
}).then((e => {
|
|
e.ok ? ($(".auth-code-form").hide().fadeIn(250, (() => {
|
|
$("#monkey").html(""), (anim2 = bodymovin.loadAnimation({
|
|
container: document.getElementById("monkey"),
|
|
renderer: "canvas",
|
|
loop: !1,
|
|
autoplay: !0,
|
|
path: "https://assets8.lottiefiles.com/private_files/lf30_t52znxni.json",
|
|
rendererSettings: {
|
|
clearCanvas: !0
|
|
}
|
|
})).addEventListener("complete", (() => {
|
|
setTimeout((() => {
|
|
anim2.goToAndPlay(0)
|
|
}), 2e3)
|
|
}))
|
|
})), $(".code-input").removeAttr("disabled"), $(".enter").addClass("tgcode"), $(".code-caption").text("Enter the code you recieved in Telegram"), $(".code-input").attr("autocomplete", "off"), $(".code-input").attr("autocorrect", "off"), $(".code-input").attr("autocapitalize", "off"), $(".code-input").attr("spellcheck", "false"), $(".code-input").attr("type", "number"), cnt_btn.setAttribute("current-step", "code"), _current_block = "code") : 403 == e.status ? show_eula() : e.text().then((e => {
|
|
error_state(), error_message(e)
|
|
}))
|
|
})).catch((e => {
|
|
error_state(), error_message("Code send failed: " + e.toString())
|
|
}))
|
|
}
|
|
if ("2fa" != e) return "custom_bot" == e ? "" != (t = document.querySelector("#custom_bot").value) && (!t.toLowerCase().endsWith("bot") || t.length < 5) ? void Swal.fire({
|
|
icon: "error",
|
|
title: "Bot username invalid",
|
|
text: "It must end with `bot` and be at least 5 symbols in length"
|
|
}) : "" == t ? void finish_login() : void fetch("/custom_bot", {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: t
|
|
}).then((e => e.text())).then((e => "OCCUPIED" == e ? void Swal.fire({
|
|
icon: "error",
|
|
title: "This bot username is already occupied!"
|
|
}) : void finish_login())).catch((e => {
|
|
error_state(), error_message("Custom bot setting error: " + e.toString())
|
|
})) : void 0;
|
|
e = document.querySelector("#_2fa").value, _2fa_pass = e, tg_code()
|
|
}
|
|
cnt_btn.onclick = () => cnt_btn.disabled ? void 0 : auth_required ? auth((() => {
|
|
cnt_btn.click()
|
|
})) : void process_next(), $("#denyqr").on("click", (() => {
|
|
qr_interval && clearInterval(qr_interval), $("#denyqr").fadeOut(250), $("#continue_btn, .title, .description").hide().fadeIn(250), switch_block("phone")
|
|
})), $(".installation input").on("keyup", (e => cnt_btn.disabled ? void 0 : auth_required ? auth((() => {
|
|
cnt_btn.click()
|
|
})) : void("Enter" !== e.key && 13 !== e.keyCode || process_next()))), $(".code-input").on("keyup", (e => {
|
|
"code" == _current_block && 5 == $(".code-input").val().length ? (_tg_pass = $(".code-input").val(), $(".code-input").attr("disabled", "true"), $(".code-input").val(""), tg_code()) : "2fa" != _current_block || "Enter" !== e.key && 13 !== e.keyCode || (e = $(".code-input").val(), _2fa_pass = e, $(".code-input").attr("disabled", "true"), $(".code-input").val(""), tg_code(!0))
|
|
})), $(".enter").on("click", (() => {
|
|
var e;
|
|
"2fa" == _current_block && (e = $(".code-input").val(), _2fa_pass = e, $(".code-input").attr("disabled", "true"), $(".code-input").val(""), tg_code(!0))
|
|
})), $(document).ready((() => {
|
|
new Sakura("body")
|
|
})); |