Chat Calculator

Press Tab To Do Math

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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