Chat Calculator

Press Tab To Do Math

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

(I already have a user style manager, let me install it!)

// ==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}));
            }
        }
    });
})();