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.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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