clarity-for-facebook

🌟 Clarity for Facebook

Clean up your Facebook feed by removing unwanted content like Reels, Stories, sponsored posts, and suggestions.

A powerful, cross-platform browser extension that gives you control over what you see on Facebook. Built with TypeScript, React, and Tailwind CSS using a modular, feature-based architecture.

License: MIT TypeScript React

✨ Features

Feature Description
βœ… Clean Mode Master toggle to enable/disable all filtering features at once
πŸ“– Remove Stories Hide the stories tray from your feed
🎬 Remove Reels Hide all Reels from your feed
πŸ’° Remove Sponsored Posts Block all sponsored and promoted content
πŸ‘₯ Remove Suggested Posts Hide β€œSuggested for you” posts
πŸͺ Remove Marketplace Ads Filter out Marketplace advertisements
πŸ” Remove Search Ads Clean sponsored results in search
πŸ‘€ Remove People You May Know Filter friend suggestions
🎯 Remove Group Suggestions Hide group suggestions

πŸš€ Installation

For Users

Chrome/Edge

  1. Download the latest release from Releases
  2. Unzip the downloaded file
  3. Open Chrome/Edge and go to chrome://extensions/ or edge://extensions/
  4. Enable β€œDeveloper mode” in the top right
  5. Click β€œLoad unpacked” and select the unzipped folder
  6. The extension icon should appear in your toolbar

Firefox

  1. Download the .xpi file from Releases
  2. Open Firefox and go to about:addons
  3. Click the gear icon and select β€œInstall Add-on From File”
  4. Select the downloaded .xpi file
  5. Click β€œAdd” when prompted

For Developers

See Development Guide below.

πŸ“– Usage

  1. Click the extension icon in your browser toolbar
  2. Toggle β€œClean Mode” to activate the extension (master switch)
  3. Customize which content types you want to filter
  4. Your settings are automatically saved and synced across devices
  5. Visit Facebook and enjoy a cleaner feed!

Export/Import Settings

πŸ› οΈ Development

Prerequisites

Setup

# Clone the repository
git clone https://github.com/user/clarity-for-facebook.git
cd clarity-for-facebook

# Install dependencies
npm install

# Start development mode (with hot reload)
npm run dev

Project Structure

clarity-for-facebook/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ background/                 # Background service worker
β”‚   β”‚   └── background.ts
β”‚   β”œβ”€β”€ content/                    # Content scripts (DOM manipulation)
β”‚   β”‚   β”œβ”€β”€ contentScript.ts        # Main orchestrator
β”‚   β”‚   β”œβ”€β”€ content.css             # Injected styles
β”‚   β”‚   β”œβ”€β”€ features/               # Feature modules (modular architecture)
β”‚   β”‚   β”‚   β”œβ”€β”€ base.feature.ts     # Base class for all features
β”‚   β”‚   β”‚   β”œβ”€β”€ reels.feature.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ stories.feature.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ suggested.feature.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ people-you-may-know.feature.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ group-suggestions.feature.ts
β”‚   β”‚   β”‚   └── index.ts
β”‚   β”‚   └── services/               # Shared services
β”‚   β”‚       β”œβ”€β”€ observer.service.ts      # DOM MutationObserver
β”‚   β”‚       β”œβ”€β”€ post-parser.service.ts   # Facebook post parsing
β”‚   β”‚       β”œβ”€β”€ settings.service.ts      # Settings management
β”‚   β”‚       └── style-injector.service.ts
β”‚   β”œβ”€β”€ popup/                      # React popup UI
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Popup.tsx           # Main popup component
β”‚   β”‚   β”‚   β”œβ”€β”€ Header.tsx          # Header with actions
β”‚   β”‚   β”‚   β”œβ”€β”€ Footer.tsx          # Footer with links
β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureToggle.tsx   # Toggle component
β”‚   β”‚   β”‚   └── icons/              # Custom SVG icon components
β”‚   β”‚   β”‚       β”œβ”€β”€ CleanModeIcon.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ RemoveStoriesIcon.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ RemoveReelsIcon.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ RemoveSponsoredIcon.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ RemoveSuggestedIcon.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ RemoveMarketplaceIcon.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ RemoveSearchAdsIcon.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ RemovePeopleYouMayKnowIcon.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ RemoveGroupSuggestionsIcon.tsx
β”‚   β”‚   β”‚       └── index.ts
β”‚   β”‚   β”œβ”€β”€ index.tsx
β”‚   β”‚   β”œβ”€β”€ popup.html
β”‚   β”‚   └── styles.css
β”‚   β”œβ”€β”€ types/                      # TypeScript type definitions
β”‚   β”‚   └── index.ts
β”‚   β”œβ”€β”€ constants/                  # Constants and configuration
β”‚   β”‚   β”œβ”€β”€ index.ts
β”‚   β”‚   β”œβ”€β”€ extension.constant.ts   # Extension settings & features
β”‚   β”‚   β”œβ”€β”€ observer.constant.ts    # Observer configuration
β”‚   β”‚   └── facebook-selectors.constant.ts  # Multi-language selectors
β”‚   β”œβ”€β”€ utils/                      # Utility functions
β”‚   β”‚   β”œβ”€β”€ storage.ts
β”‚   β”‚   └── helpers.ts
β”‚   └── icons/                      # Extension icons
β”‚       β”œβ”€β”€ icon.svg
β”‚       β”œβ”€β”€ icon-16.png
β”‚       β”œβ”€β”€ icon-32.png
β”‚       β”œβ”€β”€ icon-48.png
β”‚       └── icon-128.png
β”œβ”€β”€ manifests/                      # Browser-specific manifests
β”‚   β”œβ”€β”€ manifest.chrome.json
β”‚   β”œβ”€β”€ manifest.firefox.json
β”‚   └── manifest.edge.json
β”œβ”€β”€ dist/                           # Build output (generated)
β”‚   β”œβ”€β”€ chrome/
β”‚   β”œβ”€β”€ firefox/
β”‚   └── edge/
β”œβ”€β”€ webpack.config.js
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ tailwind.config.js
└── package.json

Available Scripts

# Development
npm run dev                 # Build and watch for changes

# Production Build
npm run build              # Build for current browser
npm run build:chrome       # Build for Chrome
npm run build:firefox      # Build for Firefox
npm run build:edge         # Build for Edge
npm run build:all          # Build for all browsers

# Code Quality
npm run type-check         # Run TypeScript type checking
npm run lint               # Run ESLint
npm run lint:fix           # Fix ESLint errors

# Utilities
npm run clean              # Clean dist folder

Development Workflow

  1. Start Development Mode

    npm run dev
    
  2. Load Extension in Browser

    • Chrome: Go to chrome://extensions/, enable β€œDeveloper mode”, click β€œLoad unpacked”, select dist/chrome
    • Firefox: Go to about:debugging#/runtime/this-firefox, click β€œLoad Temporary Add-on”, select manifest.json from dist/firefox
    • Edge: Same as Chrome, but use edge://extensions/
  3. Make Changes

    • Edit files in the src/ directory
    • Webpack will automatically rebuild
    • Reload the extension in your browser to see changes
  4. Debug

    • Content Script: Right-click on Facebook page β†’ Inspect β†’ Console tab
    • Popup: Right-click on extension icon β†’ Inspect popup
    • Background: Go to chrome://extensions/ β†’ Click β€œservice worker” link under extension

πŸ—οΈ Architecture

Technology Stack

Key Design Patterns

Feature-Based Architecture

The content script uses a modular feature-based architecture:

BaseFeature (abstract)
β”œβ”€β”€ ReelsFeature
β”œβ”€β”€ StoriesFeature
β”œβ”€β”€ SuggestedPostsFeature
β”œβ”€β”€ PeopleYouMayKnowFeature
└── GroupSuggestionsFeature

Each feature implements:

Services Layer

Clean Mode Logic

cleanMode acts as a master switch:

Performance Optimizations

  1. Pre-hiding CSS - Elements hidden before paint to prevent flickering
  2. Throttled MutationObserver - Limits DOM observation frequency
  3. Debounced Processing - Batches element processing
  4. Smart Selectors - Efficient CSS selectors for element detection
  5. Code Splitting - Webpack optimization for smaller bundles

πŸ”§ Configuration

Adding New Features

  1. Create Feature Class (src/content/features/new.feature.ts)
import { BaseFeature } from './base.feature';
import type { ExtensionSettings } from '@/types';

export class NewFeature extends BaseFeature {
  constructor(settings: ExtensionSettings) {
    super(settings, 'newFeature');
  }

  shouldProcess(element: Element): boolean {
    // Detection logic
    return /* condition */;
  }

  process(element: HTMLElement): void {
    element.style.display = 'none';
  }
}
  1. Register Feature (src/content/features/index.ts)
export { NewFeature } from './new.feature';
  1. Add Type Definition (src/types/index.ts)
export type FeatureKey = 'newFeature' | /* existing types */;
  1. Update Constants (src/constants/extension.constant.ts)
export const FEATURES: Feature[] = [
  {
    key: 'newFeature',
    label: 'New Feature',
    description: 'Description of new feature',
    enabled: true,
  },
  // ... existing features
];
  1. Create Icon Component (src/popup/components/icons/NewFeatureIcon.tsx)

Multi-Language Selectors

Facebook selectors support multiple languages. Update in src/constants/facebook-selectors.constant.ts:

export const SPONSORED_TEXTS = [
  'Sponsored', // English
  'Được tài trợ', // Vietnamese
  'スポンァー', // Japanese
  // Add more languages...
];

πŸ› Troubleshooting

Extension Not Working

  1. Check Clean Mode: Make sure β€œClean Mode” is enabled in the popup
  2. Reload Facebook: Refresh the Facebook page after changing settings
  3. Check Console: Open browser console (F12) and look for errors
  4. Reinstall Extension: Remove and reinstall the extension

Content Not Being Filtered

  1. Facebook Updates: Facebook may have changed their DOM structure
  2. Language Support: Check if your Facebook language is supported
  3. Update Selectors: Check and update selectors in constants
  4. Report Issue: Open an issue on GitHub with details

Flickering Issues

The extension uses CSS pre-hiding to prevent flickering. If you still see issues:

  1. Check that content.css is being loaded
  2. Verify the StyleInjectorService is working
  3. Report the specific element causing issues

🀝 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ—ΊοΈ Roadmap


Made with ❀️ for a cleaner Facebook experience

⭐ Star this repo if you find it useful!