Reddit | Always expand comment box

Always expand comment box on reddit

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

Advertisement:

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

Advertisement:

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name            Reddit | Always expand comment box
// @namespace       https://greasyfork.org/users/821661
// @match           https://www.reddit.com/*
// @match           https://sh.reddit.com/*
// @grant           none
// @noframes
// @version         1.0.0
// @author          hdyzen
// @description     Always expand comment box on reddit
// @license         GPL-3.0
// ==/UserScript==

const focusedElements = new WeakSet();
const init = () => {
    focusCommentBox();
    new MutationObserver(focusCommentBox).observe(document.body, {
        childList: true,
    });
};

window.addEventListener("load", init, { once: true });

function focusCommentBox() {
    const commentTextarea = document.querySelector("comment-body-header [noun='add_comment_button'] faceplate-textarea-input");
    if (!commentTextarea || focusedElements.has(commentTextarea)) return;
    focusedElements.add(commentTextarea);

    commentTextarea.dispatchEvent(
        new FocusEvent("focus", {
            bubbles: true,
            cancelable: true,
        }),
    );
    setTimeout(() => getDeepActiveElement()?.blur());
}

function getDeepActiveElement() {
    let activeElement = document.activeElement;
    while (activeElement?.shadowRoot) {
        activeElement = activeElement.shadowRoot.activeElement;
    }
    return activeElement;
}