How manafasif/subreddit-blocker works
Main Components
a. Chrome Extension Core:
• Background Scripts (background.js): Monitors browsing events and runs in the background.
• Content Script (content.js): Injected into web pages to modify or block subreddit content dynamically.
• User Interface Components:
– Popup (popup.html and popup.js): Provides quick user interaction.
– Options Page (options.html): Allows users to configure settings, such as editing the block list.
– Blocked Page (blocked.html): May be used to show a message or alternative content for blocked subreddits.
• Manifest File (manifest.json): Describes the behavior, permissions, and resources that the extension uses.
• Styling (style.css & docs/styles.css; images): For the UI elements of the extension and documentation.
b. Data Management:
• Local Block List:
– A text file (data/blocked_subreddit_names.txt) that provides the initial or allowed list of subreddits to block.
– Usage of Chrome’s local storage to save and manage this list dynamically.
• Additional Data Sources:
– JSON data files (inappropriate.json, and various files under web_scraper/data) holding information on subreddits, NSFW content, and additional metadata that might be used either by the extension or by helper utilities.
c. Utility Components for Data Extraction and Packaging:
• Web Scraper Module (web_scraper/):
– Scripts such as scraper.py, extract_subreddits.py, and evaluate_subreddits.py work to gather and evaluate subreddit data.
– Data files (e.g., all_subreddits.json, nsfw_subreddit_names.txt) used to update or validate the block list.
• Packaging and Additional Utilities:
– A Python script (utils/package_extension.py) likely used to help package the extension (an automated build step, perhaps creating a ZIP for release).
Relationships and Interactions
• Chrome Extension Workflow:
– The manifest file ties together all the UI components, background scripts, and content scripts, specifying their roles and permissions.
– Background.js acts as the orchestrator, invoking Chrome APIs (such as chrome.webNavigation and chrome.storage) to manage and relay changes.
– Content.js and popup.js communicate (or trigger actions) based on user interactions and page events.
– The data from the block list (read from data/blocked_subreddit_names.txt) is loaded into local storage on initialization, allowing dynamic blocking.
• Data Updating and Scraping:
– The web scraper components run separately. They fetch information from various sources (presumably Reddit) and update local JSON or text files.
– These updated data files can either be manually imported or automatically integrated into the extension’s data folder so the block list or additional metadata remains current.
• Packaging and Deployment:
– The utils/package_extension.py and zip file under releases bundle the entire extension for distribution, ensuring that all necessary components are included.
Architectural Patterns and Design Principles
• Modularity: Separation of the extension core from auxiliary data scraping utilities ensures that the primary blocking functionality remains lightweight and user-focused.
• Client-side Processing: By using Chrome’s local storage and content/background scripts, the extension securely processes data directly in the user’s browser.
• Extensibility: The design allows for easy updates to the block list via external files and the scraping routines.
• Clear Separation of Concerns: The division between UI (popup and options pages), logic (background and content scripts), and data management (text/JSON files and web scraper) is well maintained.
Relevant Technologies, Frameworks, and Libraries
• JavaScript for core extension logic.
• Chrome Extension APIs (chrome.storage, chrome.webNavigation, chrome.runtime) to interface with the browser.
• HTML/CSS for the user interface.
• Python scripts (in the web_scraper and utils directories) for data gathering, evaluation, and packaging.