TTRS HACK

Types the answer to the first valid math equation in a highlighted block on play.ttrockstars.com, with 0.1s delay before typing.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         TTRS HACK
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Types the answer to the first valid math equation in a highlighted block on play.ttrockstars.com, with 0.1s delay before typing.
// @author       AJM
// @match        https://play.ttrockstars.com/*
// @grant        none
// @license      GPL-3.0-or-later
// ==/UserScript==

(function() {
    'use strict';

    function pressKey(key) {
        const keyDown = new KeyboardEvent('keydown', {
            key: key,
            code: key === 'Enter' ? 'Enter' : `Digit${key}`,
            keyCode: key === 'Enter' ? 13 : key.charCodeAt(0),
            which: key === 'Enter' ? 13 : key.charCodeAt(0),
            bubbles: true
        });
        const keyUp = new KeyboardEvent('keyup', {
            key: key,
            code: key === 'Enter' ? 'Enter' : `Digit${key}`,
            keyCode: key === 'Enter' ? 13 : key.charCodeAt(0),
            which: key === 'Enter' ? 13 : key.charCodeAt(0),
            bubbles: true
        });
        document.activeElement.dispatchEvent(keyDown);
        document.activeElement.dispatchEvent(keyUp);
    }

    function typeAnswer(answer) {
        const str = answer.toString();
        for (let i = 0; i < str.length; i++) {
            pressKey(str[i]);
        }
        pressKey('Enter');
    }

    document.addEventListener('mouseup', () => {
        const selectedText = window.getSelection().toString().trim();
        const lines = selectedText.split('\n').map(line => line.trim());

        const equationLine = lines.find(line =>
            /^[\d\s×÷\+\-\*\/=]+$/.test(line) && /[\d]+.*[×÷\*\/\+\-]/.test(line)
        );

        if (equationLine) {
            const cleaned = equationLine.replace(/=/g, '').replace(/×/g, '*').replace(/÷/g, '/').trim();
            try {
                const result = eval(cleaned);
                if (!isNaN(result)) {
                    setTimeout(() => typeAnswer(result), 100); // 0.1s delay
                }
            } catch (e) {
                console.warn('Invalid equation:', cleaned);
            }
        }
    });
})();