TriX Executor

A Comprehensive Script Executor for Territorial.io with proxy support, a modern UI, and tab management.

当前为 2025-07-03 提交的版本,查看 最新版本

// ==UserScript==
// @name         TriX Executor
// @namespace    https://github.com/YourUsername/TriX-Executor
// @version      1.5.1
// @description  A Comprehensive Script Executor for Territorial.io with proxy support, a modern UI, and tab management.
// @author       Painsel
// @match        *://territorial.io/*
// @match        *://www.territorial.io/*
// @match        *://*.*.*.*/*
// @icon         https://i.postimg.cc/0NkRZxDm/image.png
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_listValues
// @grant        GM_deleteValue
// @grant        GM_addValueChangeListener
// @grant        GM.xmlHttpRequest
// @require      https://gf.qytechs.cn/scripts/541461-trix-core-library/code/TriX%20Core%20Library.js
// @require      https://gf.qytechs.cn/scripts/541462-trix-ui-library/code/TriX%20UI%20Library.js
// @run-at       document-start
// @license      MIT
// ==/UserScript==

/*
    TriX Executor - Main Loader Script
    This script is the entry point for users. It loads the required core and UI libraries
    from Greasy Fork镜像 and initializes the executor when the game page is ready.
    
    Changelog v1.5.0:
    - Refactored project into a main loader and two libraries for easier maintenance and updates.
*/

(function() {
    'use strict';

    // This function runs first to ensure the script only executes on the correct pages.
    function isTerritorialPage() {
        if (window.location.hostname.includes('territorial.io')) return true;
        try {
            const cpoParam = new URLSearchParams(window.location.search).get('__cpo');
            if (cpoParam && atob(cpoParam).includes('territorial.io')) return true;
        } catch (e) { /* ignore */ }
        return false;
    }

    if (!isTerritorialPage()) {
        return; // Halt execution if not the correct page.
    }

    console.log('[TriX Executor Loader] Page verified. Waiting for game UI...');

    // This function waits for a key element to appear in the DOM before executing the callback.
    function waitForElement(selector, callback) {
        if (document.querySelector(selector)) return void callback();
        const observer = new MutationObserver((mutations, obs) => {
            if (document.querySelector(selector)) {
                obs.disconnect();
                callback();
            }
        });
        observer.observe(document.documentElement, { childList: true, subtree: true });
    }

    // This function is the entry point after the page is ready.
    function startExecutor() {
        const GAME_READY_SELECTOR = '#input0';
        const username = document.querySelector(GAME_READY_SELECTOR).value.trim() || `Guest_temp`;
        console.log(`[TriX Executor Loader] Game UI ready. Initializing core for user: ${username}`);
        
        // The TriX_Core and TriX_UI objects are available globally thanks to the @require directives.
        // We start the core logic, which will then decide if it needs to initialize the UI.
        TriX_Core.TabManager.init(username);
    }

    // --- Entry Point ---
    waitForElement("#input0", startExecutor);

})();

QingJ © 2025

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