Greasy Fork

来自缓存

Greasy Fork is available in English.

Die Stämme Auto Label Incoming Attacks

Automatically labels incoming attacks on die-staemme.de

当前为 2024-11-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Die Stämme Auto Label Incoming Attacks
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically labels incoming attacks on die-staemme.de
// @author       ricardofauch
// @match        https://*.die-staemme.de/game.php?screen=overview_villages&mode=incomings*
// @match        https://*.die-staemme.de/game.php?village=*&screen=overview_villages&mode=incomings*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to get random number between min and max (inclusive)
    function getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    // Function to wait for a specific time
    function wait(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    // Logging function with timestamp
    function log(message) {
        const timestamp = new Date().toLocaleTimeString();
        console.log(`[Auto Label ${timestamp}] ${message}`);
    }

    // Function to find and click elements
    async function autoLabel(initialWaitSeconds) {
        try {
            log('Script started');

            // Initial wait of 5-10 minutes
            log(`Waiting ${initialWaitSeconds} seconds before starting actions`);
            await wait(initialWaitSeconds * 1000);

            // Find and click the select all checkbox
            const selectAllCheckbox = document.getElementById('select_all');
            if (!selectAllCheckbox) {
                throw new Error('Select all checkbox not found');
            }
            log('Found select all checkbox');
            selectAllCheckbox.click();
            log('Clicked select all checkbox');

            // Wait 1-3 seconds
            const actionWait = getRandomInt(1000, 3000);
            log(`Waiting ${actionWait}ms before clicking rename`);
            await wait(actionWait);

            // Find and click the rename button
            const renameButton = Array.from(document.querySelectorAll('input[type="submit"]'))
                .find(input => input.value === 'Umbenennen');
            if (!renameButton) {
                throw new Error('Rename button not found');
            }
            log('Found rename button');
            renameButton.click();
            log('Clicked rename button - page will reload automatically');

        } catch (error) {
            log(`ERROR: ${error.message}`);
            console.error('Auto label script error:', error);
        }
    }

    // Add visual indicator that script is running with countdown
    const style = document.createElement('style');
    style.textContent = `
        .auto-label-indicator {
            position: fixed;
            top: 10px;
            right: 10px;
            background: rgba(0, 0, 0, 0.7);
            color: white;
            padding: 5px 10px;
            border-radius: 5px;
            z-index: 9999;
            font-size: 12px;
        }
    `;
    document.head.appendChild(style);

    const indicator = document.createElement('div');
    indicator.className = 'auto-label-indicator';
    document.body.appendChild(indicator);

    // Generate wait time once and use it for both the countdown and the actual wait
    const startTime = Date.now();
    const initialWaitSeconds = getRandomInt(300, 600); // 5-10 minutes in seconds

    // Update countdown every second
    function updateIndicator() {
        const elapsed = Math.floor((Date.now() - startTime) / 1000);
        const remaining = initialWaitSeconds - elapsed;
        if (remaining > 0) {
            indicator.textContent = `🤖 Auto Label: ${remaining}s`;
            requestAnimationFrame(updateIndicator);
        } else {
            indicator.textContent = `🤖 Auto Label: Running...`;
        }
    }
    updateIndicator();

    // Start the automation with the same wait time
    log('Initializing Auto Label script');
    autoLabel(initialWaitSeconds);
})();