YouTube 一行顯示 5 條影片 & 隱藏Shorts

自動調整 YouTube 影片縮圖大小,讓每列可顯示 5 條影片,並隱藏 Shorts

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube 一行顯示 5 條影片 & 隱藏Shorts
// @namespace    https://114514.1919.com/
// @version      1.1
// @description  自動調整 YouTube 影片縮圖大小,讓每列可顯示 5 條影片,並隱藏 Shorts
// @author       
// @license      MIT
// @match        https://www.youtube.com/*
// @grant        GM_addStyle
// @run-at       document-idle
// ==/UserScript==

(function () {
  'use strict';

  // 定義要插入的自訂 CSS
  function addCustomStyles() {
    GM_addStyle(`
      /* 隱藏 Shorts 的常見容器 */
      ytd-reel-shelf-renderer,
      ytd-rich-shelf-renderer[is-shorts] {
        display: none !important;
      }

      /* 每列顯示 5 個影片縮圖,並調整左右間距 */
      ytd-rich-grid-media {
        max-width: 100% !important;
        margin-left: 1% !important;
        margin-right: 1% !important;
      }

      /* 讓整個列表一次排 5 列 */
      ytd-rich-grid-renderer {
        --ytd-rich-grid-items-per-row: 5 !important;
      }
    `);
  }

  // 先加一次樣式
  addCustomStyles();

  // 為避免 YouTube 延遲載入或動態更新,監聽 DOM 變化並重複套用
  const observer = new MutationObserver(() => {
    addCustomStyles();
  });

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