This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Reddit Refine - Filter, Analyze is a Browser Extension (Chrome & Firefox) that filters Reddit posts based on configurable keywords and subreddits. Features filter packs system, neo-retro UI, and removal statistics tracking.
# First-time setup: Create filter-packs.json from sample
cp filter-packs.sample.json filter-packs.json
# Build the extension (defaults to Firefox)
npm run build
# Build for specific browser
npm run build:chrome # Outputs to dist/chrome
npm run build:firefox # Outputs to dist/firefox
# Package for release
npm run package # Create Firefox ZIP
npm run package:chrome # Create Chrome ZIP
# Install dependencies
npm install- Manifests:
manifest.chrome.json: Manifest V3 for Chromemanifest.firefox.json: Manifest V2 for Firefox
- Polyfill: Uses
webextension-polyfillto normalize API access via thebrowsernamespace across Chrome and Firefox. - Build: Webpack configured with
CopyPluginto generate separate builds indist/chromeanddist/firefox.
-
Content Script (
src/index.ts): Main filtering logic that runs on Reddit pagesFilterclass handles post detection, keyword matching, and removal- Uses MutationObserver to monitor dynamically loaded content
- Implements word-boundary regex matching to prevent false positives
- Tracks removal statistics with daily/total counters
-
Popup Interface (
src/popup/popup.ts+src/popup/popup.html): Extension popup UIPopupManagerclass manages settings and displays statistics- Tabbed interface for keywords and subreddits management
- Filter packs management with subscription system
- First-run onboarding for new users
- Real-time search/filtering of configured items
- Two-way communication with content script via
browser.runtimemessaging
-
Options Page (
src/options/options.ts+src/options/options.html): Full-page settings interfaceOptionsManagerclass for comprehensive filter management- Bulk keyword/subreddit management with search and filtering
- Statistics and counter display
- Settings stored in
browser.storage.localwith keyfilterSettings:keywords,subreddits,enabled,minAccountAge,accountAgeFilterEnabledenabledPacks: array of subscribed pack IDskeywordSources,subredditSources: track which pack each item comes from
- Counter data stored with key
filterCounters - Filter packs defined in
filter-packs.jsonwith curated keyword/subreddit collections (gitignored, copy from filter-packs.sample.json)
- Popup ↔ Content Script messaging via
browser.runtime.sendMessage() - Settings updates trigger
settingsUpdatedmessage to reload content script - Counter updates sent via
countersUpdatedmessage to refresh popup display - Content script requests counters via
requestCountersmessage on popup open
The extension targets these Reddit elements:
article[aria-label]elements (old Reddit format)shreddit-postelements (new Reddit format)- Uses
subreddit-prefixed-nameattributes for subreddit filtering - Implements word boundary matching for keyword filtering to avoid false positives
- TypeScript compilation via webpack with ts-loader
- JSON imports handled natively for filter packs and default filters
- Targeted Builds: Output to
dist/chromeordist/firefoxbased onTARGET_BROWSERenvironment variable - Assets: CopyPlugin handles copying icons, HTML, CSS, and the appropriate
manifest.json
- Pack definitions:
filter-packs.json(local, gitignored) contains curated collections with name, description, keywords, and subreddits. Sample available infilter-packs.sample.json - Subscription tracking:
enabledPacksarray in settings tracks active pack IDs - Source attribution:
keywordSourcesandsubredditSourcesmaps track pack origin for each filter item - Pack versioning (v1.4.0): Tracks pack versions to sync updates to subscribers
- Each pack has version field in filter-packs.json
- User storage tracks subscribed pack versions
- Auto-update strategy: new items from updated packs merged into user's filter lists
- Version tagging: items tagged with
{source: 'packId', version: '1.0'}
- Onboarding: First-run detection shows pack selection dialog to new users
- UI integration: Packs displayed in popup with toggle switches, subscription merges pack items into main filter lists
- Real-time post filtering with visual feedback in console
- Daily/total removal counters with automatic daily reset
- Search functionality for managing large keyword/subreddit lists
- Configurable enable/disable toggle
- Automatic r/ prefix handling for subreddit names
- Post collapse instead of hiding (v1.2.0): Posts are collapsed with show/hide buttons and filter reasons displayed
- Video autoplay prevention: Videos in collapsed posts are paused to prevent autoplay
- Smart URL targeting: Extension only runs on feeds (r/all, homepage, user profiles) and skips specific subreddit pages
- Filter packs system (v1.3.0): Subscribe to curated filter collections with one-click enable/disable
- First-run onboarding prompts new users to select starter packs
- Track filter sources to identify pack-originated vs user-added items
- Pack data stored in
filter-packs.json
- Neo-retro UI design (v1.3.0): Distinctive aesthetic with hard shadows, thick borders, blue-tinted neutrals, and variable fonts
- Options page (v1.3.0): Full-page interface accessible via browser.runtime.openOptionsPage() or options button in popup
- Fixed counter increment bug on filter toggle
- Optimized async processor to prevent infinite scroll blocking
- Hide filtered content when extension disabled (UX improvement)
- Filter packs system with sample file for public repo (filter-packs.json gitignored for privacy)
Before submitting to Mozilla Add-ons:
- Build:
npm run build:firefox - Package:
npm run package:firefox - Upload ZIP to: https://addons.mozilla.org/developers/addon/submit/upload-listed
- Check validation report for warnings
Local Firefox testing:
- Load from
dist/firefox/folder, NOT the ZIP - Firefox:
about:debugging#/runtime/this-firefox→ "Load Temporary Add-on" → selectmanifest.json
Local Chrome testing:
- Load from
dist/chrome/folder, NOT the ZIP - Chrome:
about:extensions→ "Load unpacked" → selectdist/chrome