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.

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.

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

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        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,
  });
};