Youtube auto grid

Youtube Auto Grid: 1-2-3-4-5-6 columns layout

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Youtube auto grid
// @namespace    http://tampermonkey.net/
// @version      2025-05-03
// @description  Youtube Auto Grid: 1-2-3-4-5-6 columns layout
// @author       You
// @match        https://www.youtube.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license      MIT2
// ==/UserScript==

(function() {
    'use strict';
const css = `
    .ytd-rich-grid-renderer {
        --ytd-rich-grid-items-per-row: 1 !important;
    }

    @media (max-width: 600px) {
        .ytd-rich-grid-renderer {
            --ytd-rich-grid-items-per-row: 2 !important;
        }
    }

    @media (min-width: 601px) and (max-width: 1026px) {
        .ytd-rich-grid-renderer {
            --ytd-rich-grid-items-per-row: 3 !important;
        }
    }

    @media (min-width: 1027px) and (max-width: 1665px) {
        .ytd-rich-grid-renderer {
            --ytd-rich-grid-items-per-row: 4 !important;
        }
    }

    @media (min-width: 1666px) and (max-width: 2000px) {
        .ytd-rich-grid-renderer {
            --ytd-rich-grid-items-per-row: 5 !important;
        }
    }

    @media (min-width: 2001px) {
        .ytd-rich-grid-renderer {
            --ytd-rich-grid-items-per-row: 6 !important;
        }
    }
`;
const style = document.createElement('style');
    style.textContent = css;
    document.head.appendChild(style);
})();