How toyfer/fontify works
Project Type and Purpose
• Fontify is a browser extension (Chrome & Firefox, Manifest V3) whose goal is to replace all fonts on the current webpage with a user-specified web font. It provides a popup UI for one-click exclusion, an options page for configuration, and uses content scripts to inject CSS at runtime.
File Structure Analysis
• Top-level:
• .github & docs: CI workflows and design/development documentation
• src: extension source
• src/html: static UI pages (popup.html, options.html)
• src/js:
• background.js – service worker handling storage, caching, events
• content.js – runs in page context to traverse DOM and inject @font-face rules
• options.js – logic for the options page (save URL, exclusion list)
• popup.js – logic for the popup (add current site to exclusion list)
• manifest.json: declares permissions, background scripts, content injection, UI pages
Key README Insights
• Uses Bulma CSS for UI
• Caches web font files (woff/ttf/otf) for performance
• Supports exclusion list per URL
• Future plans documented in docs/features and docs/development
Main Components
a. Browser Host
b. Extension Package
1. Manifest (controls wiring)
2. Background Service Worker (background.js)
3. Content Script Injector (content.js)
4. Popup UI (popup.html + popup.js + Bulma)
5. Options UI (options.html + options.js + Bulma)
6. Cache Storage (IndexedDB or chrome.storage.local)
c. External Web Font Server (remote font URL)
d. Web Page (any site to be fontified)
Relationships and Interactions
• On install/startup, the background worker registers event listeners (e.g., chrome.webNavigation, messages).
• When a page loads:
• content.js queries background for active font URL & exclusion status
• background checks exclusion list (chrome.storage)
• if not excluded, content.js downloads/caches the font from the external server (via background) and injects CSS (@font-face + override selectors)
• Popup UI ↔ background: sends message to add current origin to exclusion list
• Options UI ↔ background: CRUD operations on font URL and exclusion list
• Cached fonts live in chrome.storage.local or IndexedDB, managed by background
Architectural Patterns and Principles
• Event-driven: background.js responds to browser events and messages
• Separation of concerns:
• UI (popup/options) vs. business logic (background) vs. DOM manipulation (content script)
• Caching layer abstracted behind the background script
• Declarative wiring via manifest.json (permissions, script injection)
• Message flows with arrowheads and callouts (e.g., “getFontUrl() → returns URL from storage”)
• Caching logic (“if font not in cache → fetch & store”)
• Manifest-declared permissions (e.g., “webRequest”, “storage”, “activeTab”)