Hides YouTube Shorts shelves and videos on Home, Subscriptions, and Channel pages.
当前为
// ==UserScript==
// @name YouTube Unshortened
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Hides YouTube Shorts shelves and videos on Home, Subscriptions, and Channel pages.
// @author OthorWight
// @match *://www.youtube.com/*
// @grant none
// @run-at document-start
// @license MIT
// ==/UserScript==
(function() {
'use strict';
const hideShortsElements = () => {
// Hide the entire "Shorts" shelf.
// YouTube uses a specific attribute `is-shorts` for the shelf renderer.
document.querySelectorAll('ytd-rich-shelf-renderer[is-shorts]')
.forEach(shelf => {
// We hide the entire parent "section" to remove the title and spacing.
const section = shelf.closest('ytd-rich-section-renderer');
if (section && section.style.display !== 'none') {
section.style.display = 'none';
}
});
// Hide individual Short videos that may appear in regular feeds.
// We can identify these by the "/shorts/" in their URL.
// We cover multiple types of video renderers for broad compatibility.
const individualShortSelectors = [
'ytd-grid-video-renderer:has(a[href^="/shorts/"])', // Grid view (e.g., Subscriptions)
'ytd-rich-item-renderer:has(a[href^="/shorts/"])', // Home page rich grid
'ytd-video-renderer:has(a[href^="/shorts/"])', // List view (e.g., Search results)
'ytd-reel-item-renderer' // Renderer specifically for Shorts reels
];
document.querySelectorAll(individualShortSelectors.join(','))
.forEach(video => {
if (video.style.display !== 'none') {
video.style.display = 'none';
}
});
};
// YouTube loads content dynamically. A MutationObserver is the most
// reliable way to act on new elements as they are added to the page.
const observer = new MutationObserver(hideShortsElements);
// Start observing the entire document for changes to the list of elements.
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
// Run the function once when the script is first injected,
// just in case some elements are already on the page.
hideShortsElements();
})();