Youtube Comments Section First (Latest)

Title description and comments section first, suggestions on the right

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Youtube Comments Section First (Latest)
// @name:zh-CN   Youtube 详情评论在左边 (还能用)
// @namespace    http://tampermonkey.net/
// @version      20240531
// @description  Title description and comments section first, suggestions on the right
// @description:zh-CN   标题、描述和评论会在左侧占据更多空间,视频建议则在右侧显示。
// @author       leovoon
// @match        *.youtube.com/watch*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license      GNU GPLv3

// ==/UserScript==

(function() {
    'use strict';

     // Function to be called when the target element exists
    function waitForElement(selector, callback) {
        const targetNode = document.querySelector(selector);
        if (targetNode) {
            callback(targetNode);
            return;
        }

        const observer = new MutationObserver(mutationsList => {
            for (const mutation of mutationsList) {
                if (mutation.type === 'childList') {
                    const targetNode = document.querySelector(selector);
                    if (targetNode) {
                        callback(targetNode);
                        observer.disconnect();
                        break;
                    }
                }
            }
        });

        // Start observing the target node for changes in children
        observer.observe(document.body, { childList: true, subtree: true });
    }

    waitForElement('#columns', function(targetNode) {
        if(!targetNode) return

        targetNode.children[0].style.flexGrow = 1 // how much suggestion spans
         targetNode.children[0].style.flexBasis = 0
        targetNode.children[0].style.minWidth = 'auto'
         targetNode.children[0].style.order = 2

        targetNode.children[1].style.flexGrow = 5
        targetNode.children[1].style.flexBasis = 0
        targetNode.children[1].style.order = 1

        if (window.matchMedia("(min-width: 1025px)").matches) {
            targetNode.style.width = 'var(--ytd-watch-flexy-max-player-height)';
        }


    });




})();