The Details
The script works by injecting a JavaScript file (contentscript.js) directly into YouTube pages. It searches the DOM (Document Object Model) for specific elements that contain YouTube Shorts, such as containers with the classes .ytd-item-section-renderer, .ytd-rich-section-renderer, and .ytd-rich-shelf-renderer.
Furthermore, the script hides the shortcut to “Shorts” located in the sidebar by identifying the attribute [title=“Shorts”]. Its execution is tied not only to the initial page load (window.onload), but also listens for YouTube’s native yt-navigate-finish event. This way, the extension continues to function perfectly even when navigating within the web platform without physically reloading the tab (Single Page Application).
The Features
- Complete Shorts Removal: Removes the Shorts sections from the homepage and search results.
- Clean Navigation: Hides the annoying “Shorts” button from the main navigation menu at the top left.
- Dynamic Execution (SPA Support): Runs invisibly even during dynamic navigation on YouTube, without the need to refresh the page.
- Ultra-Lightweight: Relies on just a few lines of pure JavaScript (Vanilla JS), minimally impacting browser performance.
The Future
Some ideas for future versions of the project:
- Integrate a MutationObserver: To detect asynchronous loading (such as infinite scrolling on the Home screen) more responsively than just navigation events.
- Settings Popup (UI): Create a small interface (via a full browser extension) to allow the user to temporarily enable or disable the script with a single click.
- Advanced Customization: Give the user the choice of hiding only videos from the page or also links in the sidebar.
- Official Release: Package the script for publication on the Chrome Web Store and Mozilla Add-ons.