Auto Luarmor

Finds the elements on the page such as +12H, next, start, etc.. and clicks them at the appropriate times so you never have to do luarmor yourself again! (Code was written by ChatGPT)

// ==UserScript==
// @name         Auto Luarmor
// @namespace    http://tampermonkey.net/
// @version      2.5
// @description  Finds the elements on the page such as +12H, next, start, etc.. and clicks them at the appropriate times so you never have to do luarmor yourself again! (Code was written by ChatGPT)
// @author       Chatgpt
// @license      MIT
// @match        https://ads.luarmor.net/get_key*
// @grant        none
// ==/UserScript==


(function () {
    'use strict';

    let scriptPaused = false;

    const selectors = {
        nextButton: '#nextbtn',
        addTimeButton: '#addtimebtn_cCtbsGjODTFXrIHLDiAPYCQDsOlttPwz',
        progressText: '#adprogressp',
        newKeyButton: '#newkeybtn',
        captchaCheckText: 'h1',
        keyTimeLeft: '#_timeleft_cCtbsGjODTFXrIHLDiAPYCQDsOlttPwz',
        blacklistTitle: '#swal2-title',
        blacklistTimeText: 'p.text-sm',
        keyValue: 'h6.mb-0.text-sm' // Selector for the key
    };

    function isInPopupWindow() {
        return window.name === 'luarmor_popup';
    }

    function parseTimeToMs(timeStr) {
        const parts = timeStr.split(':').map(Number);
        if (parts.length === 3) {
            const [h, m, s] = parts;
            return ((h * 60 + m) * 60 + s) * 1000;
        } else {
            const match = timeStr.match(/(\d+)\s*hours?\s*(\d+)\s*minutes?/i);
            if (match) {
                const [, h, m] = match.map(Number);
                return ((h * 60 + m) * 60) * 1000;
            }
        }
        return 0;
    }

    function flashTitle(message, duration = 3000) {
        const originalTitle = document.title;
        let visible = true;
        const interval = 500;
        const flashCount = Math.floor(duration / interval);
        let i = 0;
        const flasher = setInterval(() => {
            document.title = visible ? message : originalTitle;
            visible = !visible;
            i++;
            if (i >= flashCount) {
                clearInterval(flasher);
                document.title = originalTitle;
            }
        }, interval);
    }

let lastStatusMessage = ''; // To track the last message logged
let lastCooldownStatus = ''; // To keep track of the last cooldown status
let lastCooldownTime = ''; // To keep track of the last cooldown time

function updateStatus(msg) {
    const statusText = document.getElementById('luarmor-status-text');
    if (statusText) statusText.textContent = msg;

    // Extract the label from the message
    const labelMatch = msg.match(/^[\u{1F600}-\u{1F64F}]+|\D+/gu); // Match emojis and non-numeric characters at the start
    const label = labelMatch ? labelMatch[0] : msg;

    // Check if the label has changed (log when label changes)
    if (label !== lastStatusMessage) {
        console.log(msg);
        lastStatusMessage = label;
    }

    // Check if it's a cooldown message
    if (msg.includes("Cooldown")) {
        const timeMatch = msg.match(/\d{2}:\d{2}:\d{2}/);
        const currentCooldown = timeMatch ? timeMatch[0] : '';

        // Log only when the cooldown status changes (not the time)
        if (currentCooldown !== lastCooldownTime) {
            // Log the first time the cooldown is detected
            if (lastCooldownStatus !== 'Cooldown') {
                console.log(msg); // Log once when the cooldown starts
                lastCooldownStatus = 'Cooldown';
            }
            lastCooldownTime = currentCooldown;
        }
    } else {
        // Reset cooldown status when it's no longer a cooldown message
        if (lastCooldownStatus === 'Cooldown') {
            lastCooldownStatus = ''; // Reset the cooldown log flag when it's no longer "Cooldown"
        }
    }
}

    function updateUITimers() {
        // Update active key time if available
        const timeLeftElem = document.querySelector(selectors.keyTimeLeft);
        if (timeLeftElem) {
            document.getElementById('luarmor-timeleft').textContent = timeLeftElem.textContent.trim();
        }

        // Update key from the page
        const keyElem = document.querySelector(selectors.keyValue);
        if (keyElem) {
            document.getElementById('luarmor-key').textContent = keyElem.textContent.trim();
        }
// Directly read cooldown time from DOM
const nextBtn = document.querySelector(selectors.nextButton);
const cooldownElem = document.getElementById('luarmor-cooldown');

if (nextBtn && cooldownElem) {
    if (nextBtn.style.cursor === 'not-allowed') {
        // Extract the visible time from the button's text
        const match = nextBtn.textContent.match(/\d{2}:\d{2}:\d{2}/);
        cooldownElem.textContent = match ? match[0] : 'Waiting...';
    } else {
        cooldownElem.textContent = 'None';
    }
}

        // Only update blacklist time and cooldown if blacklisted
        const isBlacklisted = document.querySelector(selectors.blacklistTitle)?.textContent.includes("Temporarily Blacklisted");
        if (isBlacklisted) {
            const blacklistTextElem = document.querySelector(selectors.blacklistTimeText);
            if (blacklistTextElem) {
                const blacklistTime = blacklistTextElem.textContent.replace("You can continue in:", '').trim();
                document.getElementById('luarmor-blacklist').textContent = blacklistTime;

                const ms = parseTimeToMs(blacklistTime);
                const h = String(Math.floor(ms / 3600000)).padStart(2, '0');
                const m = String(Math.floor((ms % 3600000) / 60000)).padStart(2, '0');
                const s = String(Math.floor((ms % 60000) / 1000)).padStart(2, '0');
                document.getElementById('luarmor-cooldown').textContent = `${h}:${m}:${s}`;
            }
        } else {
            document.getElementById('luarmor-blacklist').textContent = 'None';
            document.getElementById('luarmor-cooldown').textContent = 'None';
        }
    }

    function checkBlacklist() {
        const title = document.querySelector(selectors.blacklistTitle);
        if (title && title.textContent.includes("Temporarily Blacklisted")) {
            const timeText = document.querySelector(selectors.blacklistTimeText)?.textContent;
            if (timeText) {
                const ms = parseTimeToMs(timeText);
                updateStatus("⛔ Blacklisted. Waiting...");
                const blacklistTime = timeText.replace("You can continue in:", '').trim();
                document.getElementById('luarmor-blacklist').textContent = blacklistTime;

                const h = String(Math.floor(ms / 3600000)).padStart(2, '0');
                const m = String(Math.floor((ms % 3600000) / 60000)).padStart(2, '0');
                const s = String(Math.floor((ms % 60000) / 1000)).padStart(2, '0');
                document.getElementById('luarmor-cooldown').textContent = `${h}:${m}:${s}`;

                setTimeout(() => {
                    location.reload();
                }, ms);
                return true;
            }
        }
        return false;
    }

let cooldownInterval;

function handleCooldownAndClickStart() {
    if (scriptPaused) return;
    updateUITimers();

    const nextBtn = document.querySelector(selectors.nextButton);
    if (!nextBtn) return console.log("❌ Next button not found.");

    if (nextBtn.style.cursor === 'not-allowed') {
        clearInterval(cooldownInterval); // prevent duplicates

        cooldownInterval = setInterval(() => {
            if (scriptPaused) return;
            const btn = document.querySelector(selectors.nextButton);
            if (!btn || btn.style.cursor !== 'not-allowed') {
                clearInterval(cooldownInterval);
                return;
            }
            const match = btn.textContent.match(/\d{2}:\d{2}:\d{2}/);
            if (match) updateStatus(`⏳ Cooldown: ${match[0]}`);
        }, 1000);

        const match = nextBtn.textContent.match(/\d{2}:\d{2}:\d{2}/);
        const ms = match ? parseTimeToMs(match[0]) : 0;

        if (ms > 3000) {
            setTimeout(() => {
                if (scriptPaused) return;
                window.focus();
                flashTitle("⏰ Cooldown Ending!");
            }, ms - 3000);
        }

        setTimeout(() => {
            if (scriptPaused) return;
            const btn = document.querySelector(selectors.nextButton);
            if (btn?.style.cursor !== 'not-allowed') {
                clearInterval(cooldownInterval);
                btn.click();
                updateStatus("🟢 Clicked Start.");
                setTimeout(() => window.close(), 1000);
            }
        }, ms + 1000);
    } else {
        nextBtn.click();
        updateStatus("🟢 Clicked Start.");
        setTimeout(() => window.close(), 1000);
    }
}

    function handleProgressCheck() {
        if (scriptPaused) return;

        const progress = document.querySelector(selectors.progressText);
        if (!progress) return console.log("❌ Progress not found.");

        if (progress.textContent.includes("2/2")) {
            const addBtn = document.querySelector(selectors.addTimeButton);
            if (addBtn && !addBtn.classList.contains('disabled')) {
                addBtn.click();
                updateStatus("🟢 Clicked +12H.");
                return;
            }

            const timeLeft = document.querySelector(selectors.keyTimeLeft);
            const ms = timeLeft ? parseTimeToMs(timeLeft.textContent.trim()) : 0;
            if (ms > 12 * 60 * 60 * 1000) {
                updateStatus("🕒 Max time. Retry in 12h.");
                setTimeout(handleProgressCheck, 12 * 60 * 60 * 1000 + 1000);
                return;
            }

            const newKey = document.querySelector(selectors.newKeyButton);
            if (newKey && !newKey.disabled) {
                newKey.click();
                updateStatus("🟢 Clicked new key.");
            }
        } else {
            handleCooldownAndClickStart();
        }
    }

    function checkCaptchaAndProceed() {
        if (scriptPaused) return;

        const check = document.querySelector(selectors.captchaCheckText);
        if (check?.textContent.includes("Checking Your Browser")) {
            updateStatus("⏳ CAPTCHA detected...");
            setTimeout(checkCaptchaAndProceed, 3000);
        } else {
            updateStatus("🟢 Proceeding.");
            setTimeout(handleProgressCheck, 1000);
        }
    }

    function injectUI() {
        const style = document.createElement('style');
        style.textContent = `
            #luarmor-status-box {
                position: fixed;
                top: 10px;
                left: 10px;
                background: rgba(0,0,0,0.85);
                color: #0f0;
                padding: 12px 16px;
                border-radius: 10px;
                font-family: monospace;
                font-size: 14px;
                z-index: 9999;
                box-shadow: 0 0 12px rgba(0,255,0,0.5);
                transition: opacity 0.5s ease;
                max-width: 320px;
            }
            #luarmor-logo {
                position: fixed;
                bottom: 10px;
                right: 10px;
                width: 50px;
                height: 50px;
                background: url('https://upload.wikimedia.org/wikipedia/commons/thumb/1/1d/Green_check.svg/1024px-Green_check.svg.png') no-repeat center;
                background-size: contain;
                opacity: 0.7;
                z-index: 9998;
            }
            #luarmor-status-box .extra {
                margin-top: 8px;
                font-size: 12px;
                color: #aaa;
            }
            #luarmor-status-box .extra strong {
                color: #0f0;
            }
        `;
        document.head.appendChild(style);

        const box = document.createElement('div');
        box.id = 'luarmor-status-box';
        box.innerHTML = `
            <div id="luarmor-status-text">🚀 Script initialized</div>
            <button id="luarmor-pause-btn" style="margin-top: 8px; background:#222; color:#0f0; border:1px solid #0f0; padding:4px 8px; border-radius:6px; cursor:pointer;">
                ⏸️ Pause Script
            </button>
            <div class="extra">
                🔐 Key: <strong id="luarmor-key">loading...</strong><br>
                ⏱️ Time Left: <strong id="luarmor-timeleft">loading...</strong><br>
                ⛔ Blacklist: <strong id="luarmor-blacklist">None</strong><br>
                🕒 Cooldown: <strong id="luarmor-cooldown">None</strong>
            </div>
        `;

        document.body.appendChild(box);

        const pauseBtn = document.getElementById('luarmor-pause-btn');
        pauseBtn.addEventListener('click', () => {
            scriptPaused = !scriptPaused;
            pauseBtn.textContent = scriptPaused ? '▶️ Resume Script' : '⏸️ Pause Script';
            updateStatus(scriptPaused ? '⏸️ Script paused by user.' : '▶️ Script resumed.');
            if (!scriptPaused) checkCaptchaAndProceed();
        });

        const logo = document.createElement('div');
        logo.id = 'luarmor-logo';
        document.body.appendChild(logo);
    }

    window.addEventListener("load", () => {
        if (isInPopupWindow()) {
            window.name = 'luarmor_popup';
            console.log("✅ Running in popup.");
            flashTitle("🚀 Script Started!");
            injectUI();
            if (!checkBlacklist()) checkCaptchaAndProceed();
            setInterval(updateUITimers, 1000);
        } else {
            if (!window.popupOpenedOnce) {
                const popup = window.open(window.location.href, '_blank', 'width=500,height=600');
                if (popup) {
                    popup.name = 'luarmor_popup';
                    window.popupOpenedOnce = true;
                    setTimeout(() => window.close(), 500);
                } else {
                    console.log("❌ Failed to open popup.");
                }
            }
        }
    });
})();