Skip to content

ZhangCreations/anchor

Repository files navigation

Anchor

A Chrome extension that blocks distracting websites but allows access when AI determines the page is genuinely relevant to your allowed topics. Disabling the extension requires completing a deliberate challenge to prevent impulsive bypasses.

Example use cases

  • Block youtube.com, but still allow system design talks, database lectures, and debugging tutorials.
  • Block reddit.com, but allow posts that are clearly about your current study topics, such as networking or interview prep.
  • Block social and entertainment domains during work hours, while still letting through documentation, technical writeups, and course pages that match your allowed topics.
  • Hard-block specific URLs like infinite feeds or known distraction routes, even if the rest of the site is reviewed by AI.

How it works

  1. You configure a blocklist of domains (e.g. youtube.com, reddit.com).
  2. When you navigate to a blocked domain, the extension captures a live DOM snapshot from the actual tab and sends it to Claude for topic relevance analysis.
  3. If the page's primary purpose matches one of your allowed topics (e.g. "coding tutorials"), access is granted. Otherwise you're redirected to a block page.
  4. Full URLs in the blocklist (e.g. https://reddit.com/r/all) are hard-blocked immediately without an AI check.

Features

  • AI topic filtering — Claude reads page title, headings, and body text to decide relevance, not just the URL.
  • Exact URL blocking — add a full URL to the blocklist to block it unconditionally, bypassing the AI check.
  • Strict mode — disable AI checks entirely; all blocklisted domains are always blocked.
  • SPA navigation — detects pushState and Navigation API navigation on sites like YouTube and Reddit and re-checks each new page.
  • Title-first readiness — waits for a stable non-empty tab title plus meaningful content before sending a snapshot.
  • Stale-content protection — SPA reviews compare the current page against a baseline snapshot so a previous page is not accidentally re-classified.
  • LLM result cache — results are cached for 30 days, keyed by normalized URL + title + allowed topics.
  • Prompt injection protection — page content is wrapped in <page_content> tags and the system prompt instructs the model to ignore any directives found in scraped content.
  • Challenge gate — accessing settings requires typing a randomly generated phrase and waiting a configurable number of seconds (0–120), preventing impulsive disabling.

Setup

Requirements

Build

npm install
npm run build

The extension is output to dist/.

Load in Chrome

  1. Open chrome://extensions
  2. Enable Developer mode
  3. Click Load unpacked and select the dist/ folder

Configure

  1. Click the extension icon → open Settings
  2. Complete the challenge gate
  3. Add your Claude API key
  4. Edit your blocklist and allowed topics

Blocklist format

Each line in the blocklist is either a domain or a full URL:

Entry Behaviour
youtube.com Blocks all pages on youtube.com (and subdomains if enabled), runs AI check
https://reddit.com/r/all Blocks that exact path immediately, no AI check

Development

npm run dev      # watch mode — rebuilds on file changes
npm test         # run unit tests
npm run check:docs

Key source files:

File Purpose
src/background/service-worker.js Tab event listeners, blocking logic, LLM orchestration
src/content/content-script.js Runs at document_start; fast domain check, page snapshot, SPA navigation detection
src/shared/llm.js Claude API call, prompt construction, result caching
src/shared/review-utils.js Review IDs, snapshot summaries, baseline comparison, timeout-rescue helpers
src/shared/domain-utils.js Blocklist matching (domain and exact URL)
src/shared/constants.js All tunable values — timing, limits, defaults
src/blocked/ Block page UI (React)
src/options/ Settings page with challenge gate (React)
src/popup/ Toolbar popup — daily stats and enable toggle (React)

See CLAUDE.md, DESIGN.md, and docs/ for current development and runtime details.

About

Anchor is a Chrome extension that blocks distracting sites while allowing pages that are genuinely relevant to your chosen topics using live page-content analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages