Microsoft To Do 自動調整欄位高度

修復 Microsoft To Do 欄位高度讓 textarea 高度自動符合內容

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Microsoft To Do 自動調整欄位高度
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  修復 Microsoft To Do 欄位高度讓 textarea 高度自動符合內容
// @author       shanlan(grok-code-fast-1)
// @match        https://to-do.office.com/tasks/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';
  const sel = 'textarea.ms-TextField-field';
  const resize = t => {
    t.rows = 1;
    t.style.height = 'auto';
    t.style.height = t.scrollHeight + 'px';
  };
  let isResizing = false;
  document.addEventListener('mousedown', () => (isResizing = true));
  document.addEventListener('mouseup', () => {
    isResizing = false;
    document.querySelectorAll(sel).forEach(resize);
  });
  document.addEventListener('input', e => {
    if (e.target.matches(sel)) resize(e.target);
  }, true);
  const ro = new ResizeObserver(entries => {
    if (isResizing) return;
    entries.forEach(entry => {
      if (entry.target.matches(sel)) resize(entry.target);
    });
  });
  const scan = node => {
    if (node.matches(sel)) { resize(node); ro.observe(node); }
    node.querySelectorAll(sel).forEach(n => { resize(n); ro.observe(n); });
  };
  const mo = new MutationObserver(muts => muts.forEach(m => m.addedNodes.forEach(scan)));
  mo.observe(document.body, { childList: true, subtree: true });
})();