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

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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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 });
})();