How deepsuthar496/domkeeper works
Step 1 – Project Type & Purpose
• This is a Chrome browser extension (“DOMKeeper”) that lets users make permanent, client-side DOM edits which persist across page reloads.
• Key indicators: manifest.json (Chrome extension), background.js, content.js, popup.html/js, README’s “Chrome Storage API” and “MutationObserver.”
Step 2 – File Structure Analysis
Top-level files:
• manifest.json – Registers extension components & permissions
• background.js – Persistent service worker/event handler
• content.js – Injected script that manipulates the page DOM
• popup.html & popup.js – UI for toggling edit mode and managing settings
• README.md – Project description, usage, tech stack
Patterns:
• Separation of concerns: UI (popup), background logic (background.js), page interaction (content.js).
• Event‐driven messaging via Chrome extension APIs.
• Persistent state in Chrome Storage.
• MutationObserver in content.js for dynamic content handling.
Step 3 – README Insights
• Architecture isn’t explicitly drawn, but it lists:
• Chrome Storage API → for persisting changes
• MutationObserver → to detect DOM changes
• Modern JavaScript
Step 4 – Main Components & Interactions
a. Components:
1. Popup UI (popup.html, popup.js)
2. Background script (background.js)
3. Content script (content.js)
4. Chrome Storage (chrome.storage.local)
5. Page DOM
6. Chrome Extension Messaging API
b. Relationships & Data Flow:
• User clicks popup → popup.js sends a chrome.runtime.sendMessage() to background.js
• background.js processes the command, updates chrome.storage, then sends a message to content.js in the active tab
• content.js receives the message → toggles edit mode or applies changes to the DOM
• content.js listens via MutationObserver for added/changed elements → reads/writes persistent data to chrome.storage to re-apply edits on refresh
• background.js may also listen for storage.onChanged to notify content scripts of setting updates
c. Architectural Patterns:
• Event-driven “message bus” using chrome.runtime.sendMessage / onMessage
• Publisher/subscriber for storage changes (chrome.storage.onChanged)
• Observer pattern for DOM mutations
d. Key Technologies:
• manifest.json (Extension manifest v3 spec)
• chrome.runtime & chrome.storage APIs
• MutationObserver in content.js
• Standard HTML/CSS/JS for popup
• Tri-layer separation: UI layer (popup), logic layer (background service worker), page layer (content script + DOM).
• Storage as a shared datastore accessible by background & content scripts.
• Message flows:
1. Popup → Background → Content
2. Content ↔ Storage
3. Background ↔ Storage (for centralized state updates)
Step 6 – Diagramming Guidelines
• Gray rectangle for Page DOM
Step 7 – Detail & Completeness
• Every script and its role.
• Lifecycle: extension installed → user toggles edit → storage updates → content script applies edits → page reload triggers re-application.
• Failure points (e.g., dynamic sites requiring multiple storage reads).