Show YouTube comments while watching 2025

Moves comments to the right side and adds a button to toggle between comments and recommended videos

目前為 2025-03-04 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            Show YouTube comments while watching 2025
// @description     Moves comments to the right side and adds a button to toggle between comments and recommended videos
// @version         3.2
// @author          barn852 & Eloren1
// @license         MIT
// @match           *://*.youtube.com/*
// @include         *://*.youtube.com/watch*
// @grant           none
// @require         https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @run-at          document-end
// @noframes
// @namespace https://greasyfork.org/users/572660
// ==/UserScript==

(function() {
    'use strict';

    let showComments = true; // Show comments by default

    const moveComments = () => {
        let comments = document.getElementById('comments');
        let sidebar = document.querySelector('#secondary-inner');

        if (comments && sidebar && !sidebar.contains(comments)) {
            sidebar.appendChild(comments);
            console.log('Moved comments to the right side');
        }
    };

    const updateView = () => {
        let comments = document.getElementById('comments');
        let related = document.getElementById('related');

        if (comments && related) {
            comments.style.display = 'block';
            related.style.display = 'none';
        }
    };

    const toggleView = () => {
        let comments = document.getElementById('comments');
        let related = document.getElementById('related');

        if (comments && related) {
            showComments = !showComments;
            comments.style.display = showComments ? 'block' : 'none';
            related.style.display = showComments ? 'none' : 'block';
        }
    };

    const observer = new MutationObserver(() => {
        moveComments();
        updateView();
    });

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

    let button = document.createElement('button');
    button.innerHTML = '<svg width="24" height="24" viewBox="0 0 22 22"><g fill="currentColor"><path d="M4 14h4v-4H4v4zm0 5h4v-4H4v4zM4 9h4V5H4v4zm5 5h12v-4H9v4zm0 5h12v-4H9v4zM9 5v4h12V5H9z"/></g></svg>';
    button.style = 'background: transparent; border: 0; color: rgb(96,96,96); outline: 0; cursor: pointer; padding: 5px 10px;';

    button.onclick = toggleView;

    let waitButton = setInterval(() => {
        let menu = document.getElementById('end');
        if (menu) {
            clearInterval(waitButton);
            menu.insertBefore(button, menu.lastElementChild);
            updateView();
        }
    }, 500);

    console.log('Script loaded');

})();