<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="https://i.ibb.co/Dtpz8rJ/897e5bd4663cc432c8e776a2cc3ceb9e.png">
    <link rel="stylesheet" href="css/sweetalert.min.css">
    <script src="js/sweetalert.min.js"></script>
    <title>sharknet.fun</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/all.min.css" crossorigin="anonymous">

    <style>
        .log-container {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #3b3d4e93;
            border-radius: 5px;
            max-height: 200px;
            overflow-y: auto;
            width: 100%;
            max-width: 600px;
            min-height: 300px;
            box-sizing: border-box;
            margin: 20px auto;
            text-align: left;
        }
        .log-entry {
            margin: 5px 0;
            font-size: 12px;
            color: #ffffff;
        }
        .custom-input, .custom-button {
            background-color: #333333;
            color: #ffffff;
            border: 1px solid #555555;
        }
        .custom-button {
            cursor: pointer; /* Make it clear the button is clickable */
        }
        .custom-button:hover {
            background-color: #444444;
        }
        .custom-button:disabled {
            background-color: #555555;
            color: #aaaaaa;
            cursor: not-allowed; /* Show not allowed cursor when disabled */
            opacity: 0.5;
        }
        .nav_links a {
            color: #ffffff;
        }
        .nav_links a:hover {
            color: #b3b3b3;
        }
        .header_logo img {
            mix-blend-mode: lighten;
        }
        .sweet-alert {
            background-color: #2c2c2c;
            color: #ffffff;
        }
        .sweet-alert h2, .sweet-alert p {
            color: #ffffff;
        }
        .sweet-alert .sa-button-container .confirm {
            background-color: #333333 !important;
            color: #ffffff !important;
            border: none;
            box-shadow: none;
        }
        .sweet-alert .sa-button-container .confirm:hover {
            background-color: #444444 !important;
        }
        .sweet-alert .sa-button-container .cancel {
            background-color: #555555 !important;
            color: #ffffff !important;
            border: none;
            box-shadow: none;
        }
        .sweet-alert .sa-button-container .cancel:hover {
            background-color: #666666 !important;
        }
        /* Scrollbar styles */
        ::-webkit-scrollbar {
            width: 12px;
        }
        ::-webkit-scrollbar-track {
            background: #2c2c2c;
        }
        ::-webkit-scrollbar-thumb {
            background-color: #5a5a5a;
            border-radius: 6px;
            border: 3px solid #2c2c2c;
        }
        ::-webkit-scrollbar-thumb:hover {
            background-color: #777;
        }
        html {
            scrollbar-width: thin;
            scrollbar-color: #5a5a5a #2c2c2c;
        }
        @keyframes typewriter {
            from {
                width: 0;
            }
            to {
                width: 31.0em;
            }
        }
        span {
        color: #ff6347; /* Зміна кольору тексту на червоний */
        font-size: 24px; /* Зміна розміру шрифту */
        font-weight: bold; /* Товстий шрифт */
        text-transform: uppercase; /* Перетворення тексту на великі літери */
        letter-spacing: 2px; /* Відстань між літерами */
        background-color: #333333; /* Темний фон для span */
        padding: 5px; /* Внутрішні відступи */
        border-radius: 5px; /* Кути з округленням */
        position: relative; /* Встановлюємо позицію як відносну */
        top: -20px; /* Піднімаємо елемент на 10px вгору */
        }
        html, body {
        height: 100%;
        margin: 0;
        padding: 0;
        }

    </style>
</head>
<body>
<header>
    <nav>
        <div class="header_logo">
            <a href="http://sharknet.fun">
                <img src="https://i.ibb.co/Dtpz8rJ/897e5bd4663cc432c8e776a2cc3ceb9e.png" alt=""/>
            </a>            
        </div>
    </nav>
</header>
<section class="main">
    <span>Manifest & Lua Generator</span>
    <p>If you have any question, write on glib.workspace@gmail.com</p>
    <div style="margin-top: 20px; display: flex">
        <input type="text" placeholder="Enter your APP ID / URL here." class="custom-input"
               style="padding: 10px; border: 1px solid transparent; border-radius: 5px; font-size: 16px; width: 65%; box-sizing: border-box; margin-right: 10px;" />
        <button id="submit-button" class="custom-button"
                style="padding: 10px 20px; border: none; color: white; border-radius: 5px; width: 30%;"
                onclick="handleInput()">Submit</button>
    </div>
    <div id="log-container" class="log-container"></div>
</section>
<script>
document.addEventListener("DOMContentLoaded", function() {
    swal({
        title: "Warning",
        text: "This website is intended to provide information only. We are not responsible for any consequences that may arise from the use of the information provided.",
        icon: "warning",
        button: "Okey",
        background: "#2c2c2c",
        color: "#fff"
    });
    
    window.setCookie = function(name, value, days) {
        const d = new Date();
        d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
        const expires = "expires=" + d.toUTCString();
        document.cookie = name + "=" + value + ";" + expires + ";path=/";
    }

    window.getCookie = function(name) {
        const cname = name + "=";
        const decodedCookie = decodeURIComponent(document.cookie);
        const ca = decodedCookie.split(';');
        for (let i = 0; i < ca.length; i++) {
            let c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(cname) == 0) {
                return c.substring(cname.length, c.length);
            }
        }
        return "";
    }

    const logContainer = document.getElementById("log-container");
    const logHistory = getCookie("logHistory");

    if (logHistory) {
        const entries = logHistory.split('|');
        entries.forEach(entry => {
            if (entry.trim().length > 0) {
                const logEntry = document.createElement("div");
                logEntry.className = "log-entry";
                logEntry.textContent = entry;
                logContainer.appendChild(logEntry);
            }
        });
        logContainer.scrollTop = logContainer.scrollHeight;
    }

    window.handleInput = function() {
    const input = document.querySelector(".custom-input").value.trim();
    const logContainer = document.getElementById("log-container");
    const submitButton = document.getElementById("submit-button");

    function extractAppId(input) {
        if (/^\d+$/.test(input)) {
            return input;
        }
        const urlPattern = /(?:app\/|agecheck\/app\/)(\d+)/;
        const match = input.match(urlPattern);
        return match ? match[1] : null;
    }

    function getCurrentTimestamp() {
        const now = new Date();
        return now.toLocaleString();
    }

    submitButton.disabled = true; // Disable the button

    const appId = extractAppId(input);

    if (!appId) {
        const errorEntry = document.createElement("div");
        errorEntry.className = "log-entry";
        errorEntry.textContent = `${getCurrentTimestamp()} [ Error ] Invalid URL or APP ID.`;
        logContainer.appendChild(errorEntry);
        scrollLogToBottom();
        updateLogCookie();
        submitButton.disabled = false; // Re-enable the button
        return;
    }

    const logEntry = document.createElement("div");
    logEntry.className = "log-entry";
    logEntry.textContent = `${getCurrentTimestamp()} [ Information ] Finding APP ID: ${appId}`;
    logContainer.appendChild(logEntry);
    scrollLogToBottom();
    updateLogCookie();

    // Log "Starting download..."
    const downloadingEntry = document.createElement("div");
    downloadingEntry.className = "log-entry";
    downloadingEntry.textContent = `${getCurrentTimestamp()} [ Information ] Starting download...`;
    logContainer.appendChild(downloadingEntry);
    scrollLogToBottom();
    updateLogCookie();

    // Open the download URL in a new tab, but keep it in the background
    const downloadUrl = `http://sharknet.fun/db/${appId}.zip`;
    const newTab = window.open(downloadUrl, '_blank');

    if (newTab) {
        newTab.blur(); // Send the new tab to the background
    }
    
    window.focus(); // Focus back on the current tab

    submitButton.disabled = false; // Re-enable the button
}


    function updateLogCookie() {
        const logContainer = document.getElementById("log-container");
        const logEntries = logContainer.querySelectorAll(".log-entry");
        const entries = [];
        logEntries.forEach(entry => entries.push(entry.textContent));
        setCookie("logHistory", entries.join('|'), 7);
    }

    function scrollLogToBottom() {
        logContainer.scrollTop = logContainer.scrollHeight;
    }
});
</script>
</body>
</html>
