This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
YouTube Amazon Link Finder is a Chrome Extension (Manifest v3) that extracts Amazon affiliate links from YouTube video descriptions and displays them in an overlay. Users can save videos with their Amazon links to a Rails backend, which also generates AI summaries using Google's Gemini API.
The extension follows standard Chrome Extension Manifest v3 architecture:
-
content/content.js: Content script injected into YouTube pages. The
AmazonLinkFinderclass observes URL changes (YouTube is a SPA), extracts descriptions fromytInitialPlayerResponse(YouTube's embedded JSON), parses Amazon links using regex patterns, and displays them in an overlay. Falls back to DOM scraping if JSON extraction fails. -
background/background.js: Service worker that handles:
- Gemini API calls for generating summaries (
generateSummaryaction) - Saving videos to the backend (
saveSummaryaction) - Opening the videos page with auth token injection (
openVideosPageaction) - User authentication status (
getAuthStatusaction)
- Gemini API calls for generating summaries (
-
options/options.js: Settings page for:
- Configuring the Gemini API key
- User login/registration with the backend
- Import/export settings
-
content/content.css: Styles for the overlay including dark theme support
- Extracts Amazon links from descriptions (amazon.com, amzn.to, smile.amazon, etc.)
- Content script uses MutationObserver to detect YouTube SPA navigation
- Descriptions extracted from
ytInitialPlayerResponseJSON with video ID verification - On SPA navigation, may require page reload to fetch new video's description (user is notified)
- API keys and auth tokens stored in
chrome.storage.sync - "Save" button generates AI summary via Gemini and saves to backend
- "View all saved videos" opens backend page with auth token passed via URL hash
The extension communicates with a Rails backend (URL configured in API_BASE_URL):
POST /session- User loginPOST /registration- User registrationDELETE /session- User logoutPOST /summaries- Save video with Amazon links and AI summaryGET /amazon_links- Fetch saved Amazon links (used by web view)
- Load extension:
chrome://extensions/> Enable Developer mode > Load unpacked > Select this folder - After code changes: Click refresh icon on extension card in
chrome://extensions/ - Toggle
API_BASE_URLbetween localhost and production incontent.js,background.js, andoptions.js - Test on YouTube video pages that have Amazon links in their descriptions
- Gemini API key: Get at https://makersuite.google.com/app/apikey (required for summary generation). Uses
gemini-2.5-flashmodel. - Backend account: Register via extension options page (required for saving videos)