Greasy Fork

Auto scav

Auto Send Scav

当前为 2024-12-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         Auto scav
// @version      1.1
// @description  Auto Send Scav
// @include      https://*/game.php?*screen=place&mode=scavenge_mass*
// @namespace https://greasyfork.org/users/1388863
// ==/UserScript==

(function () {
    'use strict';

    const botToken = "8151644407:AAEzt2C10IC8xGIc_Iaoeno02aPHg-cQFVU"; // Ganti dengan bot token Anda

    // Function to load external script
    function loadScript(url) {
        const script = document.createElement('script');
        script.src = url;
        script.type = 'text/javascript';
        document.body.appendChild(script);
        console.log(`Loaded script: ${url}`);
    }

    // Function to handle random delay
    function randomDelay(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    // Function to send message to Telegram
    function sendToTelegram(message) {
        const chatId = localStorage.getItem('telegramChatId') || '1817608753'; // Default chatId or from localStorage
        const url = `https://api.telegram.org/bot${botToken}/sendMessage?chat_id=${chatId}&text=${encodeURIComponent(message)}`;
        fetch(url)
            .then(response => {
                if (!response.ok) {
                    console.error("Failed to send message to Telegram:", response.statusText);
                } else {
                    console.log("Message sent to Telegram:", message);
                }
            })
            .catch(error => console.error("Telegram API error:", error));
    }

    // Function to start mass scavenge process
    function startMassScavenge() {
        // Wait 2-5 seconds before loading the external script
        setTimeout(() => {
            // Load external mass scavenge script
            loadScript('https://shinko-to-kuma.com/scripts/massScavenge.js');

            // Wait another 1-5 seconds, then click sendMass for the first time
            setTimeout(() => {
                const sendMassButton = document.getElementById('sendMass');
                if (sendMassButton) {
                    sendMassButton.click();
                    console.log("Clicked sendMass for the first time");
                } else {
                    console.log("sendMass button not found");
                }

                // Wait 2-4 seconds, then click sendMass for the second time (clicking the correct input element)
                setTimeout(() => {
                    const sendMassButton2 = document.querySelector('input#sendMass.btn.btnSophie');
                    if (sendMassButton2) {
                        sendMassButton2.click(); // Clicking the specific button with the correct ID and class
                        console.log("Clicked sendMass for the second time");

                        // Send message to Telegram after second click
                        sendToTelegram("Scav Sudah dikirim");

                    } else {
                        console.log("sendMass button not found for second click");
                    }

                    // Start countdown timer after the second click
                    startCountdown();
                }, randomDelay(2000, 4000));
            }, randomDelay(1000, 5000));
        }, randomDelay(2000, 5000));  // Wait before starting the process
    }

    // Function to start countdown
    function startCountdown() {
        const countdownTime = randomDelay(30, 180); // Random countdown between 1 to 3 minutes
        let timeLeft = countdownTime;
        const countdownPopup = document.createElement("div");
        countdownPopup.style.position = "fixed";
        countdownPopup.style.bottom = "20px";
        countdownPopup.style.right = "20px";
        countdownPopup.style.padding = "10px 20px";
        countdownPopup.style.fontSize = "16px";
        countdownPopup.style.backgroundColor = "#333";
        countdownPopup.style.color = "white";
        countdownPopup.style.borderRadius = "5px";
        countdownPopup.style.zIndex = "1000";
        document.body.appendChild(countdownPopup);

        const countdownInterval = setInterval(() => {
            if (timeLeft <= 0) {
                clearInterval(countdownInterval);
                countdownPopup.innerText = `Countdown finished!`;
                // Navigate to the new page after countdown
                window.location.href = "/game.php?screen=place&mode=scavenge";
            } else {
                countdownPopup.innerText = `Time left: ${Math.floor(timeLeft / 60)}m ${timeLeft % 60}s`;
                timeLeft--;
            }
        }, 1000); // Update countdown every second
    }

    // Start the mass scavenge process
    startMassScavenge();
})();