How swerve145/ai-reflector works
Project Type and Purpose
• This is a Chrome extension (“AI Reflection Helper”) designed to inject active‐learning prompts into the ChatGPT web UI.
• Its goal is to require students to reflect on AI‐generated answers before proceeding, boosting retention.
File Structure Analysis
• Top-level files:
• README.md – project overview and install instructions
• ai-reflector/ directory:
• manifest.json – extension metadata, permissions, content scripts, UI entries
• content.js – content script that runs in the context of chat.openai.com; watches for new responses and injects reflection prompts
• popup.html & popup.js – the toolbar popup UI (e.g., settings or brief guide)
• guide.html – a standalone help page explaining usage
• styles.css – shared styling for injected prompts and UIs
Key Insights from README
• No external backend or server component: everything runs client-side in the browser.
• Users load it via “Load unpacked” in Chrome; it operates by modifying the ChatGPT page DOM.
Main Components
a. Chrome Browser Host
b. Extension Manifest (manifest.json) – declares:
• Permissions (e.g., activeTab, storage)
• Content Script injection rules (match patterns for chat.openai.com)
• Browser action (popup) entry point
c. Content Script (content.js)
• Listens for DOM changes in the ChatGPT response area
• Injects a reflection prompt module into the page
• Reads/writes user settings via chrome.storage
• Optionally opens guide.html in a new tab
d. Popup UI (popup.html + popup.js)
• Provides on-click settings or quick guide access
• Communicates with content script via chrome.runtime.sendMessage or chrome.storage
e. Shared Resources
• styles.css for consistent styling
• guide.html loaded as a help page
f. User Interaction
• End user reads ChatGPT responses
• Content script pauses flow and displays prompt UI for reflection
• User’s input is collected before allowing continuation
Relationships and Data Flow
2. Popup may read/write settings via chrome.storage
3. User navigates to chat.openai.com → Manifest injects content.js
4. content.js detects new AI responses (DOM MutationObserver)
5. content.js inserts reflection prompt UI (styled by styles.css)
6. User enters reflection → content.js saves to chrome.storage (optional)
7. Once submitted, content.js re-enables the ChatGPT “Continue” button
Architectural Patterns & Principles
• Single-Page Integration: content.js hooks into a third-party SPA (ChatGPT)
• Event-Driven: DOM events/mutations trigger reflection UI
• Client-Only, No Server: all logic and data reside in-browser, leveraging chrome.storage
• Clear Separation of Concerns:
• manifest.json defines wiring
• content script handles page augmentation
• popup handles configuration
• CSS & guide page are shared assets