Block + Redirect YouTube Shorts

Hide YouTube Shorts everywhere and redirect shorts URLs to normal watch pages.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Block + Redirect YouTube Shorts
// @namespace    http://github.com/chunjee
// @version      0.1.0
// @description  Hide YouTube Shorts everywhere and redirect shorts URLs to normal watch pages.
// @author       Chunjee
// @match        https://www.youtube.com/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
	'use strict';

	// 🚫 Redirect if on a Shorts URL
	if (location.pathname.startsWith('/shorts/')) {
		location.replace('https://www.youtube.com/');
		return;
	}

	// 🧹 Hide Shorts previews everywhere else
	const observer = new MutationObserver(() => {
		document.querySelectorAll('a[href*="/shorts/"]').forEach(link => {
			let container = link.closest(
				'ytd-grid-video-renderer, ytd-rich-item-renderer, ytd-video-renderer, ytd-compact-video-renderer, ytd-reel-shelf-renderer, ytd-rich-grid-media'
			);
			if (!container) container = link;
			container.style.display = 'none';
		});
	});

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