Auto Send Resource for Minting

send ress automatically at WH at random intervals (10-20 minutes) with a countdown, reset button, and customizable settings

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Auto Send Resource for Minting
// @version      2.2
// @description  send ress automatically at WH at random intervals (10-20 minutes) with a countdown, reset button, and customizable settings
// @include      https://*/game.php*screen=storage*
// @namespace https://greasyfork.org/users/1388863
// ==/UserScript==

// Variabel global untuk menyimpan referensi timer
let countdownTimer = null;

// Fungsi untuk menghasilkan waktu tunggu acak dalam milidetik
function getRandomInterval(min, max) {
    return Math.random() * (max - min) + min;
}

// Fungsi untuk mendapatkan nilai dari localStorage atau nilai default jika tidak ada
function getFromStorage(key, defaultValue) {
    return localStorage.getItem(key) || defaultValue;
}

// Fungsi untuk menjalankan langkah-langkah dengan jeda
function executeSteps() {
    console.log('Eksekusi langkah utama dimulai...');

    setTimeout(() => {
        document.querySelector('.input_wood.scriptInput').value = 28000000;
        document.querySelector('.input_stone.scriptInput').value = 30000000;
        document.querySelector('.input_iron.scriptInput').value = 25000000;

        const target = document.getElementById('input_target1');
        const origin = document.getElementById('input_origin1');

        const targetValue = getFromStorage('mintingTarget', ' ');
        const originValue = getFromStorage('mintingOrigin', ' ');

        if (target) {
            target.value = targetValue;
            console.log('Teks telah dimasukkan ke dalam target:', target.value);
        } else {
            console.error('Elemen dengan id "input_target1" tidak ditemukan.');
        }

        if (origin) {
            origin.value = originValue;
            console.log('Teks telah dimasukkan ke dalam origin:', origin.value);
        } else {
            console.error('Elemen dengan id "input_origin1" tidak ditemukan.');
        }

        setTimeout(() => {
            const button = document.querySelector('input.btn.evt-confirm-btn.btn-confirm-yes[type="button"][value="calculate"]');
            if (button) {
                button.click();
                console.log('Tombol calculate telah diklik.');
            } else {
                console.error('Tombol calculate tidak ditemukan.');
            }

            setTimeout(() => {
                function pressEnterContinuously() {
                    console.log('Menekan tombol Enter...');
                    const event = new KeyboardEvent('keydown', {
                        key: 'Enter',
                        code: 'Enter',
                        keyCode: 13,
                        which: 13,
                        bubbles: true,
                    });
                    document.dispatchEvent(event);
                    setTimeout(pressEnterContinuously, 2000);
                }

                pressEnterContinuously();
            }, getRandomInterval(2000, 3000));
        }, getRandomInterval(2000, 3000));
    }, getRandomInterval(2000, 3000));
}

// Fungsi utama untuk memulai script
function main() {
    console.log('Menunggu sebelum memuat script eksternal...');
    setTimeout(() => {
        console.log('Memuat script eksternal...');
        $.getScript("https://dl.dropboxusercontent.com/s/gijrksuvyynuzlp/resSender.js?dl=0")
            .done(() => {
                console.log('Script eksternal berhasil dimuat.');
                setTimeout(() => {
                    console.log('Melanjutkan ke langkah utama...');
                    executeSteps();
                }, getRandomInterval(1000, 2000));
            })
            .fail(() => {
                console.error('Gagal memuat script eksternal.');
            });
    }, getRandomInterval(1000, 2000));
}

// Countdown logic
function startCountdown(minutes) {
    const countdownElement = document.getElementById('countdown-timer');
    const endTime = Date.now() + minutes * 60000;
    localStorage.setItem('countdownEndTime', endTime);

    // Hentikan timer sebelumnya jika ada
    if (countdownTimer) {
        clearTimeout(countdownTimer);
    }

    function updateCountdown() {
        const remainingTime = Math.max(0, endTime - Date.now());
        const mins = Math.floor(remainingTime / 60000);
        const secs = Math.floor((remainingTime % 60000) / 1000);

        countdownElement.textContent = `Next execution in: ${mins}m ${secs}s`;

        if (remainingTime > 0) {
            countdownTimer = setTimeout(updateCountdown, 1000);
        } else {
            countdownElement.textContent = 'Executing...';
            main();
            startCountdown(Math.random() * 10 + 10); // Start new countdown with 20-30 minutes
        }
    }

    updateCountdown();
}

// Inisialisasi UI
function initializeUI() {
    const container = document.createElement('div');
    container.style.position = 'fixed';
    container.style.bottom = '20px';
    container.style.left = '20px';
    container.style.backgroundColor = '#333';
    container.style.color = '#fff';
    container.style.padding = '10px';
    container.style.borderRadius = '5px';
    container.style.zIndex = 10000;

    const countdownElement = document.createElement('div');
    countdownElement.id = 'countdown-timer';
    countdownElement.style.marginBottom = '10px';
    container.appendChild(countdownElement);

    const resetButton = document.createElement('button');
    resetButton.textContent = 'Forced Start';
    resetButton.style.padding = '5px 10px';
    resetButton.style.marginRight = '5px';
    resetButton.style.border = 'none';
    resetButton.style.borderRadius = '3px';
    resetButton.style.cursor = 'pointer';
    resetButton.style.backgroundColor = '#007bff';
    resetButton.style.color = '#fff';

    resetButton.addEventListener('click', () => {
        console.log('Reset button clicked.');
        // main();
        // startCountdown(Math.random() * 10 + 20); // Start new countdown with 20-30 minutes
        startCountdown(0.02); // Start new countdown with 20-30 minutes
        location.reload();
    });

    const settingsButton = document.createElement('button');
    settingsButton.textContent = 'Settings';
    settingsButton.style.padding = '5px 10px';
    settingsButton.style.border = 'none';
    settingsButton.style.borderRadius = '3px';
    settingsButton.style.cursor = 'pointer';
    settingsButton.style.backgroundColor = '#28a745';
    settingsButton.style.color = '#fff';

    settingsButton.addEventListener('click', () => {
        const newTarget = prompt('Masukkan Koordinat Target:', getFromStorage('mintingTarget', ' '));
        if (newTarget !== null) {
            localStorage.setItem('mintingTarget', newTarget);
            console.log('Target baru disimpan:', newTarget);
        }

        const newOrigin = prompt('Masukkan Koordinat Origin:', getFromStorage('mintingOrigin', ' '));
        if (newOrigin !== null) {
            localStorage.setItem('mintingOrigin', newOrigin);
            console.log('Origin baru disimpan:', newOrigin);
        }
    });

    container.appendChild(resetButton);
    container.appendChild(settingsButton);
    document.body.appendChild(container);
}

// Mulai program
(function () {
    initializeUI();

    const savedEndTime = localStorage.getItem('countdownEndTime');
    const remainingTime = savedEndTime ? Math.max(0, savedEndTime - Date.now()) : 0;

    if (remainingTime > 0) {
        console.log('Melanjutkan countdown sebelumnya.');
        startCountdown(remainingTime / 60000);
    } else {
        console.log('Memulai countdown baru.');
        startCountdown(Math.random() * 10 + 10); // Random interval between 20-30 minutes
    }
})();