Let me describe how this extension is supposed to work.
The user watches a YouTube video and when he/she watches till the end, they come face to face with 3 more recommended videos from YouTube. I want to prevent those recommendations from showing up
- The extension must detect if the user is watching a youtube video and should start listening
- The extension must fire an event when a the body of the document is loaded
- The extension must remove the class or the elements housing the three suggested videos
- The user should be able to turn the extension on or off
- Add text and button to popup menu
- Implement super basic content and test
- Add support to toggle the switch on or off
- Modify styling and add reversion capablities
- Figure out a way to listen to youtube tab and listen to change in DOM
-
The background script runs all the time, content script runs only on the pages whose urls are specified. The background script and the popup script exist inside of extension context, so you get access to all the browser.* api calls.
-
Setting browser storage is asynchronous, these have to awaited before accessing the values. Using arrow functions without the body is an implicit return. The get elements by classname gives me all the elements with said class name.
-
The content script and background script have a limited number of apis that can be used. To observe console statements of the the popup and the background script, inspect the API. Content script console logs show up on the specified page.
-
The background script does not have access to the DOM but the content script has access to the DOM of the page.
-
Mutation Observers can be used to detect changes in DOM on YouTube page. The DOM event listener was not listening properly so opted to use only the mutation observer. Initially I tried to observe specific classes but switched to just observing the entire body instead. This likely poses issues with the variable being undefined since it does take time for YouTube to load it all but the extension is working regardless.
Recommendation Remover is a browser extension that hides YouTube's "end screen" recommendation panel (the grid of suggested videos that appears after a video ends).
The extension includes a popup toggle so you can enable or disable this behavior at any time.
- Firefox (manifest version 2)
- Open Firefox and go to
about:debugging. - Click
Load Temporary Add-on.... - Select the
manifest.jsonfile from this project. - Open YouTube and test the toggle from the extension popup.
- Navigate to any YouTube video page.
- Click the extension icon.
- Use the button in the popup:
Turn ON: hide end-of-video recommendations.Turn OFF: show recommendations again.
Your preference is saved using browser sync storage (rec_switch).
background.js- Initializes storage on install and sets
rec_switchtofalse.
- Initializes storage on install and sets
popup/popup.js- Toggles
rec_switch.
- Toggles
content-script/recommendation-remover.js- Observes DOM mutations on YouTube pages.
- Finds the recommendation container (
ytp-fullscreen-grid-stills-container). - Applies
display: nonewhen enabled, and restoresdisplay: gridwhen disabled.
tabs: interact with browser tabs.activeTab: operate on the currently active tab.storage: persist toggle state.
background.js
manifest.json
content-script/
recommendation-remover.js
popup/
popup.html
popup.css
popup.js
icons/
- Add safeguards for missing recommendation nodes before changing style.
This project is licensed under the terms described in LICENSE.