TTRS Helper (Answer Overlay)

Shows answers for times table questions

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.sleazyfork.org/scripts/576729/1816395/TTRS%20Helper%20%28Answer%20Overlay%29.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         TTRS Helper (Answer Overlay)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Shows answers for times table questions
// @match        *://play.ttrockstars.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getAnswer(text) {
        // Match patterns like "7 x 8"
        const match = text.match(/(\d+)\s*[x×]\s*(\d+)/i);
        if (!match) return null;

        const a = parseInt(match[1], 10);
        const b = parseInt(match[2], 10);

        return a * b;
    }

    function createOverlay() {
        const box = document.createElement("div");
        box.id = "ttrs-helper-box";
        box.style.position = "fixed";
        box.style.bottom = "20px";
        box.style.right = "20px";
        box.style.background = "black";
        box.style.color = "lime";
        box.style.padding = "10px 15px";
        box.style.fontSize = "20px";
        box.style.borderRadius = "8px";
        box.style.zIndex = "9999";
        box.textContent = "Answer: ?";
        document.body.appendChild(box);
        return box;
    }

    const overlay = createOverlay();

    function scanQuestion() {
        // Try to find question text on page
        const bodyText = document.body.innerText;

        const answer = getAnswer(bodyText);

        if (answer !== null) {
            overlay.textContent = "Answer: " + answer;
        }
    }

    // Check repeatedly (game updates fast)
    setInterval(scanQuestion, 500);

})();