Remove Youtube Shorts

Remove youtube shorts junk

  1. // ==UserScript==
  2. // @name Remove Youtube Shorts
  3. // @namespace https://www.youtube.com/
  4. // @version 0.2
  5. // @description Remove youtube shorts junk
  6. // @author Scamcast
  7. // @match https://www.youtube.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function RemoveShorts() {
  17. document.querySelectorAll('ytd-grid-video-renderer').forEach(video => {
  18. try {
  19. if (video.__data.data.navigationEndpoint.commandMetadata.webCommandMetadata.webPageType.match(/shorts/i)) video.remove();
  20. } catch (e) {}
  21. });
  22.  
  23. document.querySelectorAll('ytd-guide-entry-renderer.ytd-guide-section-renderer').forEach(guideItem => {
  24. try {
  25. if (guideItem.__data.data.formattedTitle.simpleText.match(/shorts/i)) guideItem.remove();
  26. } catch (e) {}
  27. });
  28.  
  29. document.querySelectorAll('tp-yt-paper-tab').forEach(tab => {
  30. try {
  31. if (tab.textContent.match(/shorts/i)) tab.remove();
  32. } catch (e) {}
  33. });
  34. document.querySelectorAll('ytd-reel-shelf-renderer, ytd-rich-shelf-renderer').forEach(reelshelf => reelshelf.remove());
  35. }
  36.  
  37. RemoveShorts();
  38. let JunkCheckInterval = setInterval(RemoveShorts, 1000);
  39.  
  40. window.addEventListener('focus', (e)=>{
  41. if (document.hasFocus() && document.visibilityState == 'visible'){
  42. clearInterval(JunkCheckInterval);
  43. JunkCheckInterval = setInterval(RemoveShorts, 1000);
  44. } else if (!document.hasFocus() || document.visibilityState == 'hidden') {
  45. clearInterval(JunkCheckInterval);
  46. };
  47. });
  48. window.addEventListener('visibilitychange', (e)=>{
  49. if (!document.hasFocus() || document.visibilityState == 'hidden') {
  50. clearInterval(JunkCheckInterval);
  51. };
  52. })
  53. })();