Dzen Auto-Expand Comments

Автоматическое раскрытие свернутых комментариев на dzen.ru

// ==UserScript==
// @name         Dzen Auto-Expand Comments
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Автоматическое раскрытие свернутых комментариев на dzen.ru
// @author       You
// @match        https://dzen.ru/*
// @grant        none
// @run-at       document-idle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function expandComments() {
        // Selector for the "ещё" span, specifically within the comment text area.
        // We try a slightly different approach, targeting the parent div of the
        // expand span, but using a more general class that seems consistent
        // across different comment structures.
        const expandButtons = document.querySelectorAll('div[aria-label="Кликабельный текст поста"] .content--rich-text__expandWord-2_');

        expandButtons.forEach(button => {
            try {
                button.click();
            } catch (error) {
                console.error("Error clicking expand button:", error);
            }
        });
    }

    // Create a MutationObserver
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.addedNodes && mutation.addedNodes.length > 0) {
                expandComments();
            }
        });
    });


    function init(){
        expandComments();
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        init();
    } else {
        document.addEventListener('DOMContentLoaded', init);
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址