Always expand comment box on reddit
// ==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;
}