How divij-agarwal-42/youtube-detoxifier works
Project Type and Purpose
• This is a Chrome browser extension (“Youtube Detoxifier”) designed to modify the YouTube user interface in real time.
• It provides three main features:
• Hiding video recommendations and comments
• A timeout/auto‑pause feature to limit watch time
• A “break” mode to temporarily suspend the blocking rules
File Structure Analysis
• manifest.json
• The extension’s metadata, permissions (tabs, storage), and registration of content/background scripts and UI pages.
• background.js
• Persistent event handler; coordinates timer logic, break mode, and message routing.
• content.js
• Injected into YouTube pages; manipulates the DOM to hide comments, recommendations, shorts.
• popup.html, popup.js, popup.css
• The browser‑action (toolbar) UI; allows users to toggle features, set timeout and break durations.
• landing_page.html, landing_page.js, landing_page.css
• The options or welcome page (opened via popup link or context menu) for extended configuration.
• timer.html, timerscript.js, timerstyles.css
• A standalone timer page (could be opened in a new tab) showing the countdown UI.
• reading-time_images/
Key Architectural Patterns
• Event‑driven architecture utilizing Chrome’s extension message passing.
• Separation of concerns:
• UI layer (popup/landing_page/timer pages)
• Background controller (background.js)
• Content manipulation (content.js)
• Browser storage (chrome.storage) for persisting user settings.
Main Components
a. Browser Host
• Chrome runtime environment provides APIs (storage, messaging, tabs)
b. Manifest Module
• Registers content and background scripts, UI pages, and permissions
c. Background Service (background.js)
• Listens for user actions from the popup or timer
• Starts/stops timers and break periods
• Routes messages between UI and content scripts
d. Content Script (content.js)
• Injected into every youtube.com tab
• Hides or shows page elements based on current settings
e. Popup UI (popup.html/js/css)
• Toolbar interface for toggling features and setting durations
f. Landing/Options Page (landing_page.html/js/css)
• Extended configuration and informational display
g. Timer View (timer.html/js/css)
• Dedicated countdown display when a timeout is active
h. Chrome Storage
• Persists user preferences (enabled features, timeout length, break status)
i. YouTube Page (External Service)
• Destination website where DOM manipulations occur
Interactions and Data Flows
→ Popup sends message to Background Service
→ Background writes to Storage and relays command to active Content Scripts
→ Content Scripts update the YouTube page DOM
• For timer: Background Service starts countdown → Updates Timer View if open → On timeout expiry → Sends “disable” message to Content Scripts
• Break mode: User triggers break via Popup → Background flips a flag in Storage → Content Scripts read new flag on next message or page reload
Final Advice
• Be exhaustive: include manifest.json as the binding point for all scripts/pages.
• Runtime lifecycle: content scripts load on page load, background persists across tabs, UIs load on user demand.
• Keep the layout simple: arrange Browser Host at the top, Storage in the center, and other components radiating around.