Dzen Auto Expander (Comments & More) v1.2 (MutationObserver)

Автоматически разворачивает ветки комментариев Dzen, нажимает «читать дальше» в комментариях и нажимает главную кнопку «показать больше комментариев».

这些是代码更新过的版本。 显示所有版本

  • v1.2 2025-04-13

    Removed Interval Logic: CHECK_INTERVAL_MS, MAX_CHECKS_WITHOUT_ACTION, checksWithoutAction, intervalId, and setInterval are removed.
    Added MutationObserver:
    observer: Holds the MutationObserver instance.
    mutationCallback: This function is executed when the observer detects DOM changes.
    observer.observe(document.body, { childList: true, subtree: true });: This line tells the observer to watch the entire document.body for nodes being added or removed, including within nested elements (subtree: true). This is robust for catching dynamically loaded comments.
    Added Debouncing:
    DEBOUNCE_DELAY_MS: A constant defining how long to wait after the last detected mutation before running runExpansionCycle. This prevents the function from running excessively if many elements are added rapidly.
    debounceTimer: Holds the setTimeout ID for the debounced call.
    The mutationCallback clears any existing timeout and sets a new one. Only when the DOM stops changing for DEBOUNCE_DELAY_MS will runExpansionCycle execute.
    Modified Initialization:
    The script still waits for document-idle and an additional INITIAL_DELAY_MS.
    It runs runExpansionCycle once initially to catch elements already present.
    It then creates and starts the MutationObserver.
    Updated stopScript: Now also includes observer.disconnect() to stop listening for DOM changes and clears the debounceTimer.
    Removed Automatic Stop Condition: The script no longer stops automatically after a period of inactivity. It relies on the MutationObserver and will only trigger checks when the DOM changes. It will run until the page is closed or stopDzenExpander() is called.
    Added beforeunload Listener: A good practice to ensure the observer is stopped cleanly when the user navigates away.
    Minor Logging: Added a run counter to runExpansionCycle for easier debugging in the console.

  • v1.1 2025-04-13