Chat Calculator

Press Tab To Do Math

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Chat Calculator
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Press Tab To Do Math
// @author       AlphB
// @match        https://www.milkywayidle.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=milkywayidle.com
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/bundle.min.js
// @license      CC0
// ==/UserScript==

(function () {
    document.addEventListener('keydown', function (event) {
        if (event.key === 'Tab' && document.activeElement.classList.contains('Chat_chatInput__16dhX')) {
            event.preventDefault();
            const inputNode = document.activeElement;
            const parser = new exprEval.Parser();
            const originalValue = inputNode.value.trim();
            let result;
            if (originalValue.endsWith("=")) {
                try {
                    result = originalValue + String(parser.evaluate(originalValue.substring(0, originalValue.length - 1)));
                } catch (e) {
                    return;
                }
            } else {
                try {
                    result = parser.evaluate(originalValue);
                } catch (e) {
                    return;
                }
            }
            const tracker = inputNode._valueTracker;
            const previousValue = tracker ? tracker.getValue() : originalValue;
            inputNode.value = result;
            if (tracker) {
                tracker.setValue(previousValue);
                inputNode.dispatchEvent(new Event("input", {bubbles: true}));
            }
        }
    });
})();