Reddit | Always expand comment box

Always expand comment box on reddit

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!)

Advertisement:

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!)

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