Reddit - Auto Expand Hidden Comments by AI

This userscript was created by an AI. It will most likely never be updated, so consider it 'as is.'

当前为 2025-01-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Reddit - Auto Expand Hidden Comments by AI
// @version      0.01.01
// @description  This userscript was created by an AI. It will most likely never be updated, so consider it 'as is.'
// @description  There is a slight delay of the action bar (upvote, downvote, reply, share) on previously hidden comments during the initial page load.
// @namespace    makewebsitesbetter
// @icon         https://i.postimg.cc/3NMLffrh/greenbox.png
// @include      *://www.reddit.com/*
// @run-at       document-start
// @grant        none
// @license      MIT
// ==/UserScript==



(function() {
    'use strict';

    function expandComments() {
        const comments = document.querySelectorAll('shreddit-comment[collapsed]');
        comments.forEach(comment => {
            // Set action row height to 32px during loading
            const actionRow = comment.querySelector('shreddit-comment-action-row');
            if (actionRow) {
                actionRow.style.maxHeight = '32px';
                actionRow.style.height = '32px';
            }
            // Remove collapsed attribute to expand the comment
            comment.removeAttribute('collapsed');
        });
    }

    // Observe DOM changes to capture new comments dynamically
    const observer = new MutationObserver(() => {
        expandComments();
    });

    // Start observing the document body
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial run to expand comments on page load
    window.addEventListener('load', () => {
        expandComments();
        setTimeout(expandComments, 1000); // Run again after 1 second to catch any late load
    });

})();