// ==UserScript==
// @name TriX Executor
// @namespace https://github.com/YourUsername/TriX-Executor
// @version 3.3.0
// @description A Comprehensive Script Executor with Guest Sign-Up, Tab User Confirmation, and Python support.
// @author You
// @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
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/html2canvas.min.js
// @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
// @require https://gf.qytechs.cn/scripts/542296-trix-addons-library/code/TriX%20Addons%20Library.js
// @run-at document-start
// @license MIT
// ==/UserScript==
/*
TriX Executor - Main Loader v2.3.0
- Added Guest Sign-Up system with permanent random ID generation.
- Added Tab User Confirmation step to ensure user identity matches the game tab.
*/
(function() {
'use strict';
function isTerritorialPage(){if(window.location.hostname.includes('territorial.io'))return!0;try{const e=new URLSearchParams(window.location.search).get('__cpo');if(e&&atob(e).includes('territorial.io'))return!0}catch(e){}return!1}
if(!isTerritorialPage()){return}
function waitForElement(e,t){if(document.querySelector(e))return void t();const o=new MutationObserver((c,r)=>{document.querySelector(e)&&(r.disconnect(),t())});o.observe(document.documentElement,{childList:!0,subtree:!0})}
const VerificationSystem = {
validUsers: { '795354688': 'Dr. Yes', '000000000': 'Painsel' },
currentUserID: null,
showModal(content) {
let modal = document.getElementById('trix-verify-modal');
if (!modal) {
GM_addStyle(`@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&family=Fira+Code&display=swap');#trix-verify-modal{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(26,27,38,.9);z-index:2000000;display:flex;align-items:center;justify-content:center;backdrop-filter:blur(5px);font-family:'Poppins',sans-serif}.trix-verify-container{background:#2a2d3d;padding:30px;border-radius:10px;text-align:center;color:#e0e0e0;box-shadow:0 8px 32px rgba(0,0,0,.4);width:400px;}.trix-verify-container h3{margin-top:0;color:#00bfff;}.trix-captcha-code{background:#1e202b;padding:10px 20px;border-radius:5px;font-family:'Fira Code',monospace;font-size:24px;letter-spacing:10px;margin:20px 0;user-select:none;}.trix-verify-input{padding:10px;font-size:16px;width:90%;text-align:center;border-radius:5px;border:1px solid #353952;background:#1e202b;color:#e0e0e0;margin-bottom:20px;}.trix-verify-btn{padding:10px 20px;border:none;border-radius:5px;cursor:pointer;background:#00bfff;color:#fff;font-weight:700;transition:background-color .2s;}.trix-verify-btn:hover{background-color:#00a0d8}.trix-verify-btn.secondary{background-color:#414868;}.trix-verify-btn.secondary:hover{background-color:#565f89;}.trix-verify-btn:disabled{background:#414868;cursor:not-allowed}.trix-progress-bar{width:100%;background:#1e202b;border-radius:5px;overflow:hidden;height:20px;margin-top:15px;border:1px solid #16161e}.trix-progress-bar-inner{height:100%;width:0;background:linear-gradient(90deg,#00bfff,#28a745);transition:width .3s ease,background-color .3s ease}`);
modal = document.createElement('div');
modal.id = 'trix-verify-modal';
document.body.appendChild(modal);
}
modal.innerHTML = `<div class="trix-verify-container">${content}</div>`;
},
async run() {
const savedGuestId = await GM_getValue('trix_guest_user_id', null);
if (savedGuestId) {
this.currentUserID = savedGuestId;
this.validUsers[savedGuestId] = 'Guest'; // Add to valid users for this session
this.showTabUserConfirm();
} else {
this.showInitialChoice();
}
},
showInitialChoice() {
this.showModal(`
<h3>TriX Executor Access</h3>
<p>Please log in or sign up as a guest.</p>
<input type="text" class="trix-verify-input" id="trix-id-input" placeholder="Enter User ID">
<button class="trix-verify-btn" id="trix-id-submit">Login with ID</button>
<p style="margin: 20px 0 10px;">or</p>
<button class="trix-verify-btn secondary" id="trix-guest-signup">Sign Up as Guest</button>
`);
document.getElementById('trix-id-submit').addEventListener('click', () => this.handleLogin());
document.getElementById('trix-id-input').addEventListener('keydown', e => { if (e.key === 'Enter') this.handleLogin(); });
document.getElementById('trix-guest-signup').addEventListener('click', () => this.handleGuestSignup());
},
handleLogin() {
const input = document.getElementById('trix-id-input');
const enteredId = input.value.trim();
if (this.validUsers[enteredId]) {
this.currentUserID = enteredId;
this.showTabUserConfirm();
} else {
input.style.border = '1px solid #f7768e';
input.value = 'Invalid ID';
setTimeout(() => { input.style.border = '1px solid #353952'; input.value = ''; }, 1500);
}
},
async handleGuestSignup() {
const newGuestId = `GUEST-${Date.now().toString(36).slice(-4).toUpperCase()}${Math.random().toString(36).slice(-2).toUpperCase()}`;
await GM_setValue('trix_guest_user_id', newGuestId);
this.currentUserID = newGuestId;
this.validUsers[newGuestId] = 'Guest';
this.showModal(`
<h3>Guest ID Created!</h3>
<p>Your permanent Guest ID is:</p>
<div class="trix-captcha-code" style="cursor:text;" title="Save this ID!">${newGuestId}</div>
<p>Please save this ID. You will be automatically logged in on this browser.</p>
`);
setTimeout(() => this.showTabUserConfirm(), 4000);
},
showTabUserConfirm() {
const tabUsername = document.querySelector("#input0").value.trim();
const welcomeName = this.validUsers[this.currentUserID] || 'User';
this.showModal(`
<h3>Confirm Tab User</h3>
<p>Welcome, ${welcomeName}.<br>Please confirm your current in-game username to proceed.</p>
<input type="text" class="trix-verify-input" id="trix-user-confirm" placeholder="Current in-game username">
<button class="trix-verify-btn" id="trix-user-submit">Confirm User</button>
`);
const input = document.getElementById('trix-user-confirm');
const submit = document.getElementById('trix-user-submit');
input.focus();
const verifyUser = () => {
if (input.value.trim() === tabUsername) {
this.runCaptcha();
} else {
input.style.border = '1px solid #f7768e';
input.value = "Username does not match tab";
setTimeout(() => { input.style.border = '1px solid #353952'; input.value = ''; }, 2000);
}
};
submit.addEventListener('click', verifyUser);
input.addEventListener('keydown', e => { if (e.key === 'Enter') verifyUser(); });
},
async runCaptcha(){const e=this.validUsers[this.currentUserID],t=Math.random().toString(36).substring(2,8).toUpperCase();this.showModal(`<h3>Identity Confirmed</h3><p>Please complete the final CAPTCHA.</p><div class="trix-captcha-code">${t}</div><input type="text" class="trix-verify-input" id="trix-captcha-input" maxlength="6" autocomplete="off"><button class="trix-verify-btn" id="trix-captcha-submit">Continue</button>`);const i=document.getElementById("trix-captcha-input"),s=document.getElementById("trix-captcha-submit");i.focus();const o=()=>{i.value.toUpperCase()===t?this.runLoader():i.style.border="1px solid #f7768e"};s.addEventListener("click",o),i.addEventListener("keydown",e=>{"Enter"===e.key&&o()})},
runLoader(){this.showModal(`<h3>Preparing TriX Environment</h3><p id="trix-loader-status" style="height:20px; transition: color .3s;">Initializing...</p><div class="trix-progress-bar"><div id="trix-progress-bar-inner"></div></div><button class="trix-verify-btn" id="trix-loader-skip" style="margin-top:20px; background-color:#8c8c8c;">Skip Pre-load</button>`);const e=document.getElementById("trix-loader-status"),t=document.getElementById("trix-progress-bar-inner"),i=document.getElementById("trix-loader-skip");let s=!1;i.onclick=()=>{s||(s=!0,TriX_Core.PyodideManager.isSkipped=!0,this.onVerificationSuccess())};const o=TriX_Core.PyodideManager.init(!0,i=>{e.textContent=i.what,i.total&&(t.style.width=`${i.loaded/i.total*100}%`)});o.then(()=>{s||(e.textContent="Finalizing...",t.style.width="100%",setTimeout(()=>this.onVerificationSuccess(),500))}).catch(t=>{s||(e.textContent="Python failed to load. You can continue without it.",e.style.color="#f7768e",i.textContent="Continue without Python")})},
onVerificationSuccess(){document.getElementById("trix-verify-modal")?.remove();const e=document.querySelector("#input0").value.trim()||"Guest_temp";console.log(`[TriX] Verification successful. Initializing core for user: ${e}`),TriX_Core.TabManager.init(e)}
};
console.log('[TriX Loader] Page verified. Starting verification system...');
waitForElement("#input0", () => VerificationSystem.run());
})();