Torn Transform Text to Numeric Input

Transforms various text inputs to number inputs (Only useful on mobile)

Stan na 17-01-2025. Zobacz najnowsza wersja.

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

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

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         Torn Transform Text to Numeric Input
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Transforms various text inputs to number inputs (Only useful on mobile)
// @author       TheProgrammer
// @match        https://www.torn.com/page.php?sid=stocks*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function transformToNumericInput(element) {
        element.type = 'number';
        // Optional: Set additional attributes if needed
        // element.pattern = '[0-9]*';
        // element.step = '0.01';
    }

    function processNewInputs(mutationsList, observer) {
        for(const mutation of mutationsList) {
            if (mutation.type === 'childList') {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        if (node.matches('input.input-money:not([type="hidden"])')) {
                            transformToNumericInput(node);
                        } else if (node.hasChildNodes()) {
                            node.querySelectorAll('input.input-money:not([type="hidden"])').forEach(transformToNumericInput);
                        }
                    }
                });
            }
        }
    }

    function observeMutations() {
        const observer = new MutationObserver(processNewInputs);
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    // Run the script on page load and observe for mutations
    observeMutations();

})();