Skip to content

Refactor content scripts into platform adapter pattern #10

@Olawoyin007

Description

@Olawoyin007

What

Refactor the content script architecture so each platform (Twitter, YouTube, Reddit) implements a shared adapter interface. Currently content.js is Twitter-specific.

From ROADMAP.md - Phase 3.4.

Problem

Adding YouTube and Reddit support means duplicating the classification flow, cache logic, and treatment application across multiple content scripts. This will become hard to maintain.

Proposed Architecture

extension/
  platforms/
    adapter.js        # Shared interface: extractContent(), applyTreatment()
    twitter.js        # Twitter-specific DOM selectors and extraction
    youtube.js        # YouTube-specific DOM selectors and extraction
    reddit.js         # Reddit-specific DOM selectors and extraction
  content.js          # Shared logic: observe, classify, treat (uses adapter)

Each adapter implements:

  • getContentElements() - Find new content in the DOM
  • extractText(element) - Pull classifiable text from an element
  • applyTreatment(element, result) - Apply blur/tag/hide to an element
  • getElementId(element) - Unique key for caching

Why

  • Adding a new platform becomes: implement one adapter file
  • Shared classification and caching logic stays DRY
  • Testing is easier with a clear interface

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestextensionChrome/browser extension

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions