YouTube Row Fix

5 videos/row

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

Advertisement:

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

Advertisement:

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         YouTube Row Fix
// @namespace    https://youtube.com/
// @version      1.4
// @description  5 videos/row
// @match        https://www.youtube.com/*
// @match        https://youtube.com/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(() => {
    "use strict";

    const prfx = "row fix ignore";
    const VideoPerRow = 5;
    const ShortPerRow = 8;

    function addStyle() {
        const old = document.getElementById(prfx);

        if (old) {
            old.remove();
        }

        const style = document.createElement("style");
        style.id = prfx;
        style.textContent = `
            html,
            ytd-rich-grid-renderer {
                --ytd-rich-grid-items-per-row: ${VideoPerRow} !important;
                --ytd-rich-grid-posts-per-row: ${VideoPerRow} !important;
                --ytd-rich-grid-slim-items-per-row: ${VideoPerRow} !important;
            }

            ytd-rich-grid-renderer {
                margin-left: 8px !important;
                margin-right: 8px !important;
            }

            ytd-rich-grid-row,
            #contents.ytd-rich-grid-row,
            ytd-rich-grid-row > #contents {
                display: contents !important;
            }

            ytd-rich-item-renderer {
                max-width: none !important;
            }

            ytd-rich-shelf-renderer[is-shorts],
            ytd-rich-section-renderer {
                --ytd-rich-grid-items-per-row: ${ShortPerRow} !important;
                --ytd-rich-grid-posts-per-row: ${ShortPerRow} !important;
            }

            @media (max-width: 1200px) {
                html,
                ytd-rich-grid-renderer {
                    --ytd-rich-grid-items-per-row: 4 !important;
                    --ytd-rich-grid-posts-per-row: 4 !important;
                    --ytd-rich-grid-slim-items-per-row: 4 !important;
                }
            }

            @media (max-width: 900px) {
                html,
                ytd-rich-grid-renderer {
                    --ytd-rich-grid-items-per-row: 3 !important;
                    --ytd-rich-grid-posts-per-row: 3 !important;
                    --ytd-rich-grid-slim-items-per-row: 3 !important;
                }
            }
        `;

        document.documentElement.appendChild(style);
    }

    function patchGrid() {
        document.querySelectorAll("ytd-rich-grid-renderer").forEach((grid) => {
            grid.style.setProperty("--ytd-rich-grid-items-per-row", String(VideoPerRow), "important");
            grid.style.setProperty("--ytd-rich-grid-posts-per-row", String(VideoPerRow), "important");
            grid.style.setProperty("--ytd-rich-grid-slim-items-per-row", String(VideoPerRow), "important");
        });
    }

    function run() {
        addStyle();
        patchGrid();
    }

    run();

    window.addEventListener("yt-navigate-finish", run);
    window.addEventListener("resize", patchGrid);

    new MutationObserver(patchGrid).observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();