Hide YouTube Shorts

Hides YouTube Shorts videos from showing across the YouTube website.

  1. // ==UserScript==
  2. // @name Hide YouTube Shorts
  3. // @namespace https://www.taylrr.co.uk/
  4. // @version 0.3
  5. // @description Hides YouTube Shorts videos from showing across the YouTube website.
  6. // @author taylor8294
  7. // @match https://www.youtube.com/
  8. // @match https://www.youtube.com/feed/subscriptions*
  9. // @match https://www.youtube.com/feed/explore*
  10. // @match https://www.youtube.com/feed/trending*
  11. // @match https://www.youtube.com/results*
  12. // @match https://www.youtube.com/watch*
  13. // @match https://www.youtube.com/shorts*
  14. // @icon https://i.ytimg.com/an/r0deIusKuMOsUobj89aPZA/featured_channel.jpg?v=60f4dc70
  15. // @grant none
  16. // @license GPLv3
  17. // @require https://cdn.jsdelivr.net/npm/arrive@2.4.1/minified/arrive.min.js
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. 'use strict';
  22.  
  23. if(window.location.pathname.toLowerCase().startsWith('/shorts/')){
  24. window.location.href = window.location.origin+'/watch?v='+window.location.pathname.replace(/^\/shorts\//g,'')+window.location.search.replace(/^\?/g,'&')
  25. } else {
  26. let removeShorts = function(){
  27. // Explore and Trending
  28. Array.from(document.querySelectorAll('h2.ytd-reel-shelf-renderer')).filter(h2 => h2.textContent.includes('Shorts')).forEach(h2 => {
  29. if(h2.closest('ytd-reel-shelf-renderer')){
  30. h2.closest('ytd-reel-shelf-renderer').remove()
  31. } else h2.closest('ytd-item-section-renderer')?.remove()
  32. })
  33. Array.from(document.querySelectorAll('a.ytd-thumbnail[href^="/shorts"]')).forEach(a => a.closest('ytd-video-renderer')?.remove() )
  34. Array.from(document.querySelectorAll('#video-title.ytd-video-renderer')).forEach(a => /\#shorts?/.test(a.innerText.toLowerCase()) ? a.closest('ytd-video-renderer')?.remove() : null)
  35. Array.from(document.querySelectorAll('#description-text.ytd-video-renderer')).forEach(yfs => /\#shorts?/.test(yfs.innerText.toLowerCase()) ? yfs.closest('ytd-video-renderer')?.remove() : null )
  36.  
  37. // Search
  38. Array.from(document.querySelectorAll('.title-and-badge.ytd-video-renderer')).forEach(h3 => /\#shorts?/.test(h3.innerText.toLowerCase()) ? h3.closest('ytd-video-renderer')?.remove() : null)
  39. Array.from(document.querySelectorAll('.metadata-snippet-container.ytd-video-renderer')).forEach(div => /\#shorts?/.test(div.innerText.toLowerCase()) ? div.closest('ytd-video-renderer')?.remove() : null)
  40.  
  41. // Recommended
  42. Array.from(document.querySelectorAll('#video-title.ytd-compact-video-renderer')).forEach(span => /\#shorts?/.test(span.innerText.toLowerCase()) ? span.closest('ytd-compact-video-renderer')?.remove() : null)
  43.  
  44. // Subscriptions and Home
  45. Array.from(document.querySelectorAll('h2.ytd-rich-shelf-renderer')).filter(h2 => h2.textContent.includes('Shorts')).forEach(h2 => h2.closest('ytd-rich-section-renderer')?.remove())
  46.  
  47. // Side menu
  48. Array.from(document.querySelectorAll('ytd-guide-entry-renderer')).filter(el => el.textContent.includes('Shorts')).forEach(el => el?.remove())
  49. }
  50.  
  51. document.arrive('ytd-reel-shelf-renderer, ytd-item-section-renderer, ytd-video-renderer, ytd-compact-video-renderer, ytd-rich-section-renderer, ytd-guide-entry-renderer', function () {
  52. removeShorts();
  53. console.log("[removeShorts called]");
  54. });
  55.  
  56. removeShorts()
  57. }
  58. })();