🚫 ShortsOff! - YouTube Shorts Remover

Disables elements that lead to YouTube Shorts.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        🚫 ShortsOff! - YouTube Shorts Remover
// @icon        https://solabs.neocities.org/assets/no_shorts!.png
// @license     GNU GPL v3.0; http://www.gnu.org/licenses/gpl-3.0.txt
// @match       https://www.youtube.com/*
// @version     1.1
// @author      Boon!
// @description Disables elements that lead to YouTube Shorts.
// @namespace https://greasyfork.org/users/1398226
// ==/UserScript==

console.log("[ShortsOff!] Boop!")

// Remove shorts category when searching.
function removeShortsSearchCategory() {
  const elements = document.querySelectorAll('yt-formatted-string[title="Shorts"]');
  elements.forEach(element => {
    if (element) {
      element.parentElement.remove();
    }
  });
}

// Removes the shorts endpoint link at the sidebar.
function removeShortsEndpointLinks() {
  const elements = document.querySelectorAll('a[title="Shorts"]');
  elements.forEach(element => {
    if (element) {
      element.remove();
    }
  });
}

// Removes the recommended shorts at the homepage.
function removeIsShorts() {
  const elements = document.querySelectorAll('[is-shorts]');
  elements.forEach(element => {
    if (element) {
      element.remove();
    }
  });
}

// Removes the recommended shorts at the side while watching a video.
function removeYtdReels() {
  const elements = document.querySelectorAll('ytd-reel-shelf-renderer');
  elements.forEach(element => {
    if (element) {
      element.remove();
    }  });
}

// Main function
function main() {
  removeShortsEndpointLinks();
  removeIsShorts();
  removeYtdReels();
  removeShortsSearchCategory()
}

// Initialize an observer that runs the main function when an element is modified.
const observer = new MutationObserver(main);
observer.observe(document.body, { childList: true, subtree: true });