YouTube Shorts Blocker

Hide YouTube Shorts from search results and redirect Shorts URLs

Från och med 2024-12-16. Se den senaste versionen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name:ko           유튜브 쇼츠 차단
// @name              YouTube Shorts Blocker

// @description:ko    쇼츠를 차단 및 Shorts URL을 YouTube.com으로 리다이렉트 합니다.
// @description       Hide YouTube Shorts from search results and redirect Shorts URLs

// @namespace         https://ndaesik.tistory.com/
// @version           1.0
// @author            ndaesik
// @match             https://www.youtube.com/*
// @icon              https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// ==/UserScript==

(function() {
    'use strict';

    // Function to hide Shorts in search results
    function hideShortsInSearch() {
        const items = document.querySelectorAll('ytd-video-renderer');
        items.forEach(item => {
            const link = item.querySelector('ytd-thumbnail > a');
            if (link && link.href.includes('/shorts/')) {
                item.style.display = 'none';
            }
        });
    }

    // Hide existing Shorts sections
    function hideShortsSection() {
        const selectors = [
            'ytd-rich-section-renderer',
            'ytd-reel-shelf-renderer',
            '#items ytd-guide-entry-renderer:nth-child(2)'
        ];

        selectors.forEach(selector => {
            const elements = document.querySelectorAll(selector);
            elements.forEach(el => {
                el.style.display = 'none';
            });
        });
    }

    // Redirect Shorts URLs to main video player
    function redirectShorts() {
        if (window.location.href.includes('youtube.com/shorts/')) {
            const videoId = window.location.pathname.split('/shorts/')[1];
            window.location.href = 'https://www.youtube.com/watch?v=' + videoId;
        }
    }

    // Create and run MutationObserver to handle dynamically loaded content
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.addedNodes.length) {
                hideShortsInSearch();
                hideShortsSection();
            }
        });
    });

    // Start observing the document with the configured parameters
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // Initial run
    hideShortsInSearch();
    hideShortsSection();
    redirectShorts();
})();