Readable Textarea Expander

Expands small textareas to improve readability and editing comfort on common websites.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/570704/1780717/Readable%20Textarea%20Expander.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Readable Textarea Expander
// @namespace    https://example.com/userscripts
// @version      1.0.0
// @description  Expands small textareas to improve readability and editing comfort on common websites.
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Minimum height for textareas that are too small
    const MIN_HEIGHT = 220;

    // Apply better sizing to a textarea
    function improveTextarea(textarea) {
        if (!(textarea instanceof HTMLTextAreaElement)) {
            return;
        }

        // Avoid processing the same textarea multiple times
        if (textarea.dataset.expanderApplied === 'true') {
            return;
        }
        textarea.dataset.expanderApplied = 'true';

        const computedStyle = window.getComputedStyle(textarea);
        const currentHeight = parseFloat(computedStyle.height) || textarea.offsetHeight;

        if (currentHeight < MIN_HEIGHT) {
            textarea.style.minHeight = `${MIN_HEIGHT}px`;
        }

        textarea.style.resize = 'vertical';
        textarea.style.lineHeight = '1.5';
        textarea.style.padding = '10px';
        textarea.style.boxSizing = 'border-box';
    }

    // Process all existing textareas
    function processPage() {
        const textareas = document.querySelectorAll('textarea');
        textareas.forEach(improveTextarea);
    }

    // Watch for dynamically added textareas
    const observer = new MutationObserver(() => {
        processPage();
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });

    // Run once on load
    processPage();
})();