Auto-expanding text input areas

Makes it so text input areas vertically expand to fit the size of the text you have put inside, making it easier to visualize what you have written in full.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Auto-expanding text input areas
// @match       *://*/*
// @version     1.0
// @license     MIT
// @namespace   https://greasyfork.org/en/users/1436613-gosha305
// @author      gosha305
// @description Makes it so text input areas vertically expand to fit the size of the text you have put inside, making it easier to visualize what you have written in full.
// ==/UserScript==

function autoExpandTextareas() {
  if (document.querySelector("textarea:not(.autoExpandable)")) {
    document.querySelectorAll("textarea:not(.autoExpandable)").forEach((e) => {
      e.classList.add("autoExpandable");
      e.addEventListener("input", function () {
        e.style.height = "auto";
        e.style.height = e.scrollHeight + "px";
      });
    });
  }
}

window.onload = function () {
  autoExpandTextareas();
  new MutationObserver(autoExpandTextareas).observe(document.body, {
    childList: true,
    subtree: true,
  });
};