123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- function auth(callback) {
- $(".main").fadeOut(500);
- setTimeout(() => {
- $(".auth").hide().fadeIn(500, () => {
- $("#tg_icon").html("");
- bodymovin.loadAnimation({
- container: document.getElementById("tg_icon"),
- renderer: "canvas",
- loop: true,
- autoplay: true,
- path: "https://raw.githubusercontent.com/hikariatama/Hikka/master/assets/noface.json",
- rendererSettings: {
- clearCanvas: true,
- }
- });
- });
- fetch("/web_auth", {
- method: "POST",
- credentials: "include",
- timeout: 300000
- })
- .then(response => response.text())
- .then((response) => {
- if (response == "TIMEOUT") {
- error_message("Code waiting timeout exceeded. Reload page and try again.");
- $(".auth").fadeOut(500);
- return
- }
- if (response.startsWith("hikka_")) {
- $.cookie("session", response)
- auth_required = false;
- $(".authorized").hide().fadeIn(100);
- $(".auth").fadeOut(500, () => {
- $(".installation").fadeIn(500);
- });
- callback();
- return;
- }
- })
- }, 500);
- }
- $("#get_started")
- .click(() => {
- if (auth_required) return auth(() => {
- $("#get_started").click();
- });
- $("#enter_api").fadeOut(500);
- $("#get_started").fadeOut(500, () => {
- $("#continue_btn").hide().fadeIn(500);
- switch_block(_current_block);
- });
- });
- $("#enter_api")
- .click(() => {
- if (auth_required) return auth(() => {
- $("#enter_api").click();
- });
- $("#get_started").fadeOut(500);
- $("#enter_api")
- .fadeOut(500, () => {
- $("#continue_btn")
- .hide()
- .fadeIn(500);
- switch_block("api_id");
- });
- });
- function isInt(value) {
- var x = parseFloat(value);
- return !isNaN(value) && (x | 0) === x;
- }
- function isValidPhone(p) {
- var phoneRe = /^[+]?\d{11,13}$/;
- return phoneRe.test(p);
- }
- function finish_login() {
- fetch("/finishLogin", {
- method: "POST",
- credentials: "include"
- })
- .then(() => {
- $(".installation").fadeOut(2000);
- setTimeout(() => {
- $("#installation_icon").html("");
- bodymovin.loadAnimation({
- container: document.getElementById("installation_icon"),
- renderer: "canvas",
- loop: true,
- autoplay: true,
- path: "https://assets1.lottiefiles.com/animated_stickers/lf_tgs_j7miwfxd.json",
- rendererSettings: {
- clearCanvas: true,
- }
- });
- $(".finish_block").fadeIn(300);
- }, 2000);
- })
- .catch((err) => {
- error_state();
- error_message("Login confirmation error: " + err.toString());
- });
- }
- function tg_code() {
- fetch("/tgCode", {
- method: "POST",
- body: `${_tg_pass}\n${_phone}\n${_2fa_pass}`
- })
- .then((response) => {
- if (!response.ok) {
- if (response.status == 401) {
- $(".auth-code-form").hide().fadeIn(300, () => {
- $("#monkey-close").html("");
- anim = bodymovin.loadAnimation({
- container: document.getElementById("monkey-close"),
- renderer: "canvas",
- loop: false,
- autoplay: true,
- path: "https://static.hikari.gay/monkey-close.json",
- rendererSettings: {
- clearCanvas: true,
- }
- });
- anim.addEventListener("complete", () => {
- setTimeout(() => {
- anim.goToAndPlay(0);
- }, 2000);
- })
- });
- $(".code-input").removeAttr("disabled");
- $(".code-input").attr("inputmode", "text");
- if($(".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";
- } else {
- $(".code-input").removeAttr("disabled");
- response.text().then((text) => {
- error_state();
- Swal.fire(
- "Error",
- text,
- "error"
- );
- });
- }
- } else {
- $(".auth-code-form").fadeOut();
- switch_block("custom_bot");
- }
- })
- .catch(error => {
- Swal.showValidationMessage(
- `Auth failed: ${error.toString()}`
- )
- })
- }
- function switch_block(block) {
- cnt_btn.setAttribute("current-step", block);
- try {
- $(`#block_${_current_block}`)
- .fadeOut(() => {
- $(`#block_${block}`)
- .hide()
- .fadeIn();
- });
- } catch {
- $(`#block_${block}`)
- .hide()
- .fadeIn();
- }
- _current_block = block;
- }
- function error_message(message) {
- Swal.fire({
- "icon": "error",
- "title": message
- });
- }
- function error_state() {
- $("body").addClass("red_state");
- cnt_btn.disabled = true;
- setTimeout(() => {
- cnt_btn.disabled = false;
- $("body").removeClass("red_state");
- }, 1000);
- }
- var _api_id = "",
- _api_hash = "",
- _phone = "",
- _2fa_pass = "",
- _tg_pass = "",
- _current_block = skip_creds ? "phone" : "api_id";
- const cnt_btn = document.querySelector("#continue_btn");
- function process_next() {
- let step = cnt_btn.getAttribute("current-step");
- if (step == "api_id") {
- let api_id = document.querySelector("#api_id").value;
- if (api_id.length < 4 || !isInt(api_id)) {
- error_state();
- return;
- }
- _api_id = parseInt(api_id, 10);
- switch_block("api_hash");
- return;
- }
- if (step == "api_hash") {
- let api_hash = document.querySelector("#api_hash").value;
- if (api_hash.length != 32) {
- error_state();
- return;
- }
- _api_hash = api_hash;
- fetch("/setApi", {
- method: "PUT",
- body: _api_hash + _api_id,
- credentials: "include"
- })
- .then(response => response.text())
- .then((response) => {
- if (response != "ok") {
- error_state();
- error_message(response)
- } else {
- switch_block("phone");
- }
- })
- .catch((err) => {
- error_state();
- error_message("Error occured while saving credentials: " + err.toString());
- });
- return;
- }
- if (step == "phone") {
- let phone = document.querySelector("#phone").value;
- if (!isValidPhone(phone)) {
- error_state();
- return;
- }
- _phone = phone;
- fetch("/sendTgCode", {
- method: "POST",
- body: _phone,
- credentials: "include"
- })
- .then((response) => {
- if (!response.ok) {
- response.text().then((text) => {
- error_state();
- error_message(text);
- });
- } else {
- $(".auth-code-form").hide().fadeIn(300, () => {
- $("#monkey").html("");
- anim2 = bodymovin.loadAnimation({
- container: document.getElementById("monkey"),
- renderer: "canvas",
- loop: false,
- autoplay: true,
- path: "https://static.hikari.gay/monkey.json",
- rendererSettings: {
- clearCanvas: true,
- }
- });
- anim2.addEventListener("complete", () => {
- setTimeout(() => {
- anim2.goToAndPlay(0);
- }, 2000);
- })
- });
- $(".code-input").removeAttr("disabled");
- $(".enter").addClass("tgcode");
- $(".code-caption").text("Enter the code you recieved in Telegram");
- cnt_btn.setAttribute("current-step", "code");
- _current_block = "code";
- }
- })
- .catch((err) => {
- error_state();
- error_message("Code send failed: " + err.toString());
- });
- }
- if (step == "2fa") {
- let _2fa = document.querySelector("#_2fa").value;
- _2fa_pass = _2fa;
- tg_code();
- return
- }
- if (step == "custom_bot") {
- let custom_bot = document.querySelector("#custom_bot").value;
- if (custom_bot != "" && (!custom_bot.toLowerCase().endsWith("bot") || custom_bot.length < 5)) {
- Swal.fire({
- "icon": "error",
- "title": "Bot username invalid",
- "text": "It must end with `bot` and be at least 5 symbols in length"
- })
- return
- }
- if (custom_bot == "") {
- finish_login();
- return
- }
- fetch("/custom_bot", {
- method: "POST",
- credentials: "include",
- body: custom_bot
- })
- .then(response => response.text())
- .then((response) => {
- if (response == "OCCUPIED") {
- Swal.fire({
- "icon": "error",
- "title": "This bot username is already occupied!"
- })
- return;
- }
- finish_login();
- })
- .catch((err) => {
- error_state();
- error_message("Custom bot setting error: " + err.toString());
- });
- return
- }
- }
- cnt_btn.onclick = () => {
- if (cnt_btn.disabled) return;
- if (auth_required) return auth(() => {
- cnt_btn.click();
- });
- process_next();
- }
- $(".installation input").on("keyup", (e) => {
- if (cnt_btn.disabled) return;
- if (auth_required) return auth(() => {
- cnt_btn.click();
- });
- if (e.key === "Enter" || e.keyCode === 13) {
- process_next();
- }
- });
- $(".code-input").on("keyup", (e) => {
- if (_current_block == "code" && $(".code-input").val().length == 5) {
- _tg_pass = $(".code-input").val();
- $(".code-input").attr("disabled", "true");
- $(".code-input").val("");
- tg_code();
- } else if (_current_block == "2fa" && (e.key === "Enter" || e.keyCode === 13)) {
- let _2fa = $(".code-input").val();
- _2fa_pass = _2fa;
- $(".code-input").attr("disabled", "true");
- $(".code-input").val("");
- tg_code();
- }
- });
- $(".enter").on("click", () => {
- if (_current_block == "2fa") {
- let _2fa = $(".code-input").val();
- _2fa_pass = _2fa;
- $(".code-input").attr("disabled", "true");
- $(".code-input").val("");
- tg_code();
- }
- });
|