How umerhd/gptrules works
Project Type and Purpose
• This is a browser extension built to inject custom “GPT Rules” into web pages. It leverages background scripts, content scripts, and a popup user interface to integrate with AI chat experiences.
• The README highlights features like “Custom Commands”, “Cursor-Style Prompting”, and “Browser Integration”. These are central to the function and are reflected in the division of source code into background, content, and popup modules.
File Structure
• Top-level configuration files (package.json, tsconfig.json, webpack.config.js, tailwind.config.js) indicate a TypeScript-based project with a bundling & style configuration.
• The src directory is organized by functionality:
• src/background contains the background script (background.ts) and default rules (defaultRules.ts).
• src/content holds various scripts (e.g., ContentEditableHandler, PopupManager, RulesInjector, etc.) that facilitate content script interactions (injection into web pages, handling text areas, and managing popups).
• src/popup contains the HTML and TSX for the popup interface.
• src/types provides TypeScript type definitions.
• The dist folder corresponds to compiled output for distribution and is used for Chrome extension installation (as detailed in the README).
Key Components to Highlight
a. Chrome Extension Manifest and Packaging
• A “Manifest” block representing manifest.json (both in dist and top-level manifest.json) which is the configuration entry point for the browser.
b. Background Script
• “Background” component (src/background/background.ts and defaultRules.ts). This script establishes global extension behaviors, manages state, and handles events that may not be tied directly to any tab.
c. Content Script
d. Popup UI
e. Build & Dependency Components
• A small section for “Build Tools” that covers webpack (webpack.config.js), TypeScript (tsconfig.json), and Tailwind CSS (tailwind.config.js, postcss.config.js). This gives context around the developer workflow and build process.
Relationships and Interactions
• Data flow starting from the Manifest which instructs the browser to load the Background Script, Content Script, and Popup UI.
– From Manifest to load Background and Content Scripts.
– Optionally, denote potential interactions between the Background Script and Content Script for managing shared state or message-passing between tabs.
Architectural Patterns & Design Principles
• Separation of concerns: The project is modularized into background, content, and popup components.
• That the project follows typical Chrome extension design patterns where:
– The Manifest acts as the configuration and entry point.
– The Background script is persistent and handles global events.
– The Content script directly manipulates the web page’s DOM.
– The Popup is a standalone UI component invoked on user action.
• Mention that TypeScript and React (through TSX) are used, promoting type safety and component-based UI design.