YouTube Shorts Blocker

Hide YouTube Shorts from search results and redirect Shorts URLs

  1. // ==UserScript==
  2. // @name:ko 유튜브 쇼츠 차단
  3. // @name YouTube Shorts Blocker
  4.  
  5. // @description:ko 쇼츠를 차단 및 Shorts URL을 YouTube.com으로 리다이렉트 합니다.
  6. // @description Hide YouTube Shorts from search results and redirect Shorts URLs
  7.  
  8. // @namespace https://ndaesik.tistory.com/
  9. // @version 1.4
  10. // @author ndaesik
  11. // @match https://m.youtube.com/*
  12. // @match https://www.youtube.com/*
  13. // @icon https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Youtube_shorts_icon.svg/193px-Youtube_shorts_icon.svg.png
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. // Function to hide Shorts in search results and mobile results
  20. function hideShortsInSearch() {
  21. // Desktop search results
  22. const items = document.querySelectorAll('ytd-video-renderer');
  23. items.forEach(item => {
  24. const link = item.querySelector('ytd-thumbnail > a');
  25. if (link && link.href.includes('/shorts/')) {
  26. item.style.display = 'none';
  27. }
  28. });
  29.  
  30. // Mobile search results
  31. const mobileItems = document.querySelectorAll('[href*="/shorts/"]');
  32. mobileItems.forEach(item => {
  33. const contextRenderer = item.closest('ytm-video-with-context-renderer');
  34. if (contextRenderer) {
  35. contextRenderer.style.display = 'none';
  36. }
  37. });
  38. }
  39.  
  40. // Hide existing Shorts sections
  41. function hideShortsSection() {
  42. const selectors = [
  43. '[tab-title="Shorts"]', // desktop nav
  44. 'ytd-rich-section-renderer', // desktop main page feed
  45. 'ytd-reel-shelf-renderer', // desktop search results feed
  46. '#items ytd-guide-entry-renderer:nth-child(2)', // desktop channel tab
  47. 'ytm-pivot-bar-item-renderer:nth-child(2)', // mobile nav bar
  48. 'ytm-rich-section-renderer', // mobile main page feed
  49. 'ytm-reel-shelf-renderer', // mobile search results feed
  50. ];
  51. selectors.forEach(selector => {
  52. const elements = document.querySelectorAll(selector);
  53. elements.forEach(el => {
  54. el.style.display = 'none';
  55. });
  56. });
  57. }
  58.  
  59. // Redirect Shorts URLs to main video player
  60. function redirectShorts() {
  61. if (window.location.href.includes('youtube.com/shorts/')) {
  62. window.location.href = window.location.href.replace('/shorts/', '/watch?v=');
  63. }
  64. }
  65.  
  66. // Create and run MutationObserver to handle dynamically loaded content
  67. const observer = new MutationObserver((mutations) => {
  68. mutations.forEach((mutation) => {
  69. if (mutation.addedNodes.length) {
  70. hideShortsInSearch();
  71. hideShortsSection();
  72. }
  73. });
  74. });
  75.  
  76. // Start observing the document with the configured parameters
  77. observer.observe(document.body, {
  78. childList: true,
  79. subtree: true
  80. });
  81.  
  82. // Initial run
  83. hideShortsInSearch();
  84. hideShortsSection();
  85. redirectShorts();
  86. })();