Telegram Central Script Executor

Menu flutuante para executar scripts internos diretamente no Telegram Web sem precisar recriar arquivos no Tampermonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey, Greasemonkey или Violentmonkey.

Вам потребуется установить расширение, например Tampermonkey или Violentmonkey, чтобы установить этот скрипт.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Userscripts.

Чтобы установить этот скрипт, сначала вы должны установить расширение браузера, например Tampermonkey.

Чтобы установить этот скрипт, вы должны установить расширение — менеджер скриптов.

(у меня уже есть менеджер скриптов, дайте мне установить скрипт!)

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

(у меня уже есть менеджер стилей, дайте мне установить скрипт!)

// ==UserScript==
// @name         Telegram Central Script Executor
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Menu flutuante para executar scripts internos diretamente no Telegram Web sem precisar recriar arquivos no Tampermonkey.
// @author       Gemini
// @match        https://web.telegram.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 1. Cria a estrutura da Interface (GUI)
    const painel = document.createElement('div');
    painel.id = 'central_executor_gui';
    painel.style = `
        position: fixed; top: 100px; right: 30px; z-index: 999999;
        background: #182533; border: 2px solid #2b5278; border-radius: 10px;
        padding: 12px; width: 320px; box-shadow: 0 6px 25px rgba(0,0,0,0.6);
        font-family: sans-serif; color: #fff; display: none;
    `;

    painel.innerHTML = `
        <div id="executor_header" style="padding: 8px; margin-bottom: 10px; background: #2b5278; border-radius: 5px; text-align: center; font-weight: bold; cursor: move; user-select: none; font-size: 13px;">
            💻 EXECUTOR CENTRAL DE SCRIPTS
        </div>
        <textarea id="executor_code_input" placeholder="Cole o código do seu script aqui dentro..." style="width: 94%; height: 180px; background: #0f1922; color: #a6d6ff; border: 1px solid #2b5278; border-radius: 5px; padding: 8px; font-family: monospace; resize: vertical; font-size: 11px; outline: none;"></textarea>
        
        <div style="display: flex; gap: 5px; margin-top: 8px;">
            <button id="btn_execute_now" style="flex: 1; background: #2481cc; color: white; border: none; padding: 10px; font-weight: bold; border-radius: 5px; cursor: pointer; font-size: 12px;">EXECUTAR SCRIPT</button>
            <button id="btn_clear_input" style="background: #34495e; color: white; border: none; padding: 10px; border-radius: 5px; cursor: pointer; font-size: 12px;">LIMPAR</button>
        </div>
        <div style="text-align: center; margin-top: 8px;">
            <button id="btn_close_executor" style="background: none; border: none; color: #ff5252; cursor: pointer; font-size: 11px; font-weight: bold;">[ FECHAR PAINEL ]</button>
        </div>
    `;

    // 2. Cria o Botão Flutuante para Abrir/Fechar o Menu
    const acionador = document.createElement('div');
    acionador.id = 'btn_trigger_executor';
    acionador.innerText = '⚙️';
    acionador.style = `
        position: fixed; top: 15px; right: 15px; z-index: 999998;
        background: #2481cc; color: white; width: 40px; height: 40px;
        border-radius: 50%; display: flex; align-items: center; justify-content: center;
        font-size: 18px; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.4);
        user-select: none;
    `;

    document.body.appendChild(painel);
    document.body.appendChild(acionador);

    // --- SISTEMA DE ARRASTAR (DRAG & DROP) ---
    const header = document.getElementById('executor_header');
    let isDragging = false, initialX, initialY;

    header.onmousedown = (e) => {
        isDragging = true;
        initialX = e.clientX - painel.offsetLeft;
        initialY = e.clientY - painel.offsetTop;
    };
    document.onmousemove = (e) => {
        if (!isDragging) return;
        painel.style.left = (e.clientX - initialX) + 'px';
        painel.style.top = (e.clientY - initialY) + 'px';
        painel.style.right = 'auto';
    };
    document.onmouseup = () => isDragging = false;

    // --- LÓGICA DE INTERAÇÃO ---
    
    // Alternar visibilidade (Abrir / Fechar)
    acionador.onclick = () => {
        painel.style.display = painel.style.display === 'none' ? 'block' : 'none';
    };
    document.getElementById('btn_close_executor').onclick = () => {
        painel.style.display = 'none';
    };

    // Limpar caixa de texto
    document.getElementById('btn_clear_input').onclick = () => {
        document.getElementById('executor_code_input').value = '';
    };

    // INJETAR E EXECUTAR O SCRIPT COLADO
    document.getElementById('btn_execute_now').onclick = () => {
        const codigoParaRodar = document.getElementById('executor_code_input').value;
        
        if (!codigoParaRodar.trim()) {
            alert("A caixa de texto está vazia! Cole um script primeiro.");
            return;
        }

        try {
            // Cria uma função dinâmica contendo o código e a executa imediatamente
            const scriptInjetado = new Function(codigoParaRodar);
            scriptInjetado();
            console.log("Script injetado e executado com sucesso através do painel central.");
        } catch (erro) {
            alert("Erro de sintaxe no script colado:\n\n" + erro.message);
        }
    };

})();