Territorial.io Auto-Join (F6 Trigger + Proxy Redirect)

On F6 key press, clicks Multiplayer & Ready. Automatically redirects to a random web proxy on first visit for a new IP.

目前為 2025-06-30 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Territorial.io Auto-Join (F6 Trigger + Proxy Redirect)
// @namespace    Violentmonkey Scripts
// @version      2.0
// @description  On F6 key press, clicks Multiplayer & Ready. Automatically redirects to a random web proxy on first visit for a new IP.
// @author       Assistant
// @match        *://*/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // --- PROXY REDIRECTION CONFIGURATION ---
    // WARNING: Public web proxies are not secure or private. Use at your own risk.
    // To disable redirection, just make this list empty: const proxyTemplates = [];
    const proxyTemplates = [
        'https://www.croxyproxy.com/_enproxy.php?u={URL}',
        'https://www.blockaway.net/index.php?cdURL={URL}',
        'https://www.4everproxy.com/proxy.php?u={URL}',
        'https://www.proxysite.com/en/proxy?q={URL}'
    ];

    /**
     * This section handles the automatic redirection to a random proxy.
     * It only runs if the hostname is exactly "territorial.io".
     */
    if (window.location.hostname === 'territorial.io' && proxyTemplates.length > 0) {
        console.log('[Auto-Join] On territorial.io, redirecting to a random proxy...');
        const targetUrl = encodeURIComponent(window.location.href);
        const randomProxy = proxyTemplates[Math.floor(Math.random() * proxyTemplates.length)];
        const newUrl = randomProxy.replace('{URL}', targetUrl);
        window.location.replace(newUrl); // Use replace to avoid polluting browser history
        return; // Stop script execution after redirecting
    }

    /**
     * This function runs on every page to check if it's a valid territorial.io page
     * (either directly or through a known proxy format).
     * This prevents the script from running on unrelated websites.
     */
    function isTerritorialPage() {
        const href = window.location.href;
        // Check for direct site, common proxy URLs, or base64 encoded URLs
        if (href.includes('territorial.io') || href.includes('?__cpo=')) {
            if (href.includes('?__cpo=')) {
                try {
                    return atob(new URLSearchParams(window.location.search).get('__cpo')).includes('territorial.io');
                } catch (e) { return false; }
            }
            return true;
        }
        return false;
    }

    // --- AUTOMATION SCRIPT (F6 TRIGGER) ---
    // This part of the script will only run on a valid territorial.io page.
    // We wait until the DOM is loaded to attach listeners.
    window.addEventListener('DOMContentLoaded', () => {
        if (!isTerritorialPage()) {
            return; // Exit if we're not on a territorial page
        }

        console.log('[Auto-Join] Script ready. Press F6 to start the automation sequence.');
        let isAutomationRunning = false;

        document.addEventListener('keydown', (event) => {
            if (event.key === 'F6') {
                event.preventDefault(); // Prevent default browser action for F6
                if (isAutomationRunning) {
                    console.warn('[Auto-Join] Automation is already in progress.');
                    return;
                }
                isAutomationRunning = true;
                startAutomation();
            }
        });

        function startAutomation() {
            console.log('[Auto-Join] F6 pressed. Starting automation...');
            waitForElementAndClick(findMultiplayerButton, () => {
                waitForElementAndClick(findReadyButton, () => {
                    console.log("[Auto-Join] Sequence complete.");
                    isAutomationRunning = false;
                }, "'Ready' button", () => { isAutomationRunning = false; });
            }, "'Multiplayer' button", () => { isAutomationRunning = false; });
        }
    });

    // --- HELPER FUNCTIONS FOR CLICKING ---
    const TIMEOUT_SECONDS = 15;
    const CHECK_INTERVAL_MS = 200;

    function waitForElementAndClick(findFunction, successCallback, description, timeoutCallback) {
        let attempts = 0;
        const maxAttempts = (TIMEOUT_SECONDS * 1000) / CHECK_INTERVAL_MS;
        console.log(`[Auto-Join] Searching for: ${description}`);
        const interval = setInterval(() => {
            if (attempts >= maxAttempts) {
                clearInterval(interval);
                console.error(`[Auto-Join] Timed out waiting for: ${description}`);
                if (timeoutCallback) timeoutCallback();
                return;
            }
            const element = findFunction();
            if (element) {
                clearInterval(interval);
                console.log(`[Auto-Join] Found and clicking: ${description}`);
                element.click();
                if (successCallback) successCallback();
            }
            attempts++;
        }, CHECK_INTERVAL_MS);
    }

    const findMultiplayerButton = () => Array.from(document.querySelectorAll('button')).find(btn => btn.innerText.includes('Multiplayer'));
    const findReadyButton = () => Array.from(document.querySelectorAll('button')).find(btn => btn.innerText.trim().startsWith('Ready'));

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址