Reload Shorts + Auto Open Comments

Reload Shorts when URL changes and auto-open comment panel for the visible Short.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reload Shorts + Auto Open Comments
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Reload Shorts when URL changes and auto-open comment panel for the visible Short.
// @match        https://www.youtube.com/shorts/*
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function () {
    let lastUrl = location.href;

    // Detect URL change (YouTube navigation)
    setInterval(() => {
        const currentUrl = location.href;
        if (currentUrl !== lastUrl) {
            lastUrl = currentUrl;

            // Only reload when switching to another Short
            if (currentUrl.includes("/shorts/")) {
                location.reload();
            }
        }
    }, 300);

    // Auto-open comments AFTER reload
    document.addEventListener("DOMContentLoaded", () => {
        autoOpenComments();
    });

    function autoOpenComments() {
        // Try multiple times because Shorts load slowly
        const tryClick = () => {
            // Find ALL possible comment buttons
            let commentButtons = [
                ...document.querySelectorAll('ytd-toggle-button-renderer#comments-button button'),
                ...document.querySelectorAll('button[aria-label^="Comments"]'),
                ...document.querySelectorAll('button[aria-label*="comment"]')
            ];

            // Filter to the visible one (like your like-button script)
            commentButtons = commentButtons.filter(btn => {
                const rect = btn.getBoundingClientRect();
                return rect.top > 0 && rect.top < window.innerHeight;
            });

            if (commentButtons.length > 0) {
                commentButtons[0].click();
            } else {
                // Retry until Shorts UI appears
                setTimeout(tryClick, 200);
            }
        };

        // Delay slightly to let the Shorts UI load
        setTimeout(tryClick, 400);
    }
})();