Read More

Automatically expand truncated comments and replies without clicking "read more"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Read More
// @namespace   https://github.com/DaBlower
// @match       https://www.reddit.com/*
// @match       https://www.youtube.com/*
// @grant       none
// @version     1.2
// @author      DaBlower
// @license     GPL-3.0-only
// @description Automatically expand truncated comments and replies without clicking "read more"
// ==/UserScript==

// for reddit and youtube (for now)

    function expandAll() {
        // expand replies in reddit
        document.querySelectorAll('button').forEach(function(btn) {
            const text = btn.innerText.trim().toLowerCase(); // gets the text in each button
            if (
                btn.offsetParent !== null && // is the button visible?
                (text.includes('more reply') || text.includes('more replies')) // does it contain more reply or more replies? (the text inside the expand button)
            ) {
                btn.click(); // click the button
            }

        });

        // expand truncated comments in youtube
        document.querySelectorAll('tp-yt-paper-button#more').forEach(function(btn){
            const text = btn.innerText.trim().toLowerCase();
            if (
                btn.offsetParent !== null &&
                text.includes('read more')
            ){
                btn.click();
            }
        });
    }
    setTimeout(expandAll, 2000);

    const observer = new MutationObserver(expandAll);

    observer.observe(document.body, {
        childList: true, // observe changes to children as well as document.body
        subtree: true // include non-immediate children
    });