How sindresorhus/refined-twitter works
Project type and purpose
• This is a browser extension (Chrome/Opera/Firefox) named “Refined Twitter.”
• Purpose: run in the user’s browser, inject UI-improving features into twitter.com pages, provide an options UI, and manage settings—all with zero external backend.
Key architectural components
a. Build-time pipeline
• Webpack (webpack.config.js)
• Input: source/ (JS modules, CSS, HTML, manifest.json)
• Output: distribution/ folder loaded into the browser.
b. Runtime components
1. Manifest (manifest.json)
• Declares permissions, content scripts, background script, options page.
2. Background script (background.js)
• Runs persistently (or as an event page/service worker).
• Listens for extension events, routes messages, stores/retrieves settings.
3. Content script (content.js)
• Injected into twitter.com pages.
• Imports source/features/*.js to modify the DOM, apply CSS, listen for keyboard shortcuts.
4. Options page (options.html + options.js)
• UI for toggling features, persisted in chrome.storage.
5. Shared utilities (source/libs/utils.js)
6. Styles (source/style/*.css)
c. Data storage
• chrome.storage.local / chrome.storage.sync for user preferences.
Relationships & interactions
• At install/load:
manifest → registers background script, content scripts, options page.
• On Twitter page load:
content.js ← manifest
→ imports and executes each feature module → manipulates page DOM & injects CSS
↔ background.js via chrome.runtime.sendMessage / onMessage (for e.g. reading settings)
• Options UI ↔ background.js (read/write settings)
• background.js ↔ chrome.storage (persist feature toggles)
Architectural patterns & design principles
• Modular feature-based design: each feature in source/features is a self-contained module.
• Separation of concerns:
• Background for messaging & storage
• Content for page DOM interaction
• Options for UI/configuration
• Single-page HTML for options; CSS scoped per content vs. options context.
Detail level
• Manifest at the center of build/runtime boundary.
• Which files live in source/, which get bundled, and which end up in distribution.
• Essential flows (injection, messaging, storage), but you don’t need to show every single feature file—group them logically.
Final checklist
• Components: manifest, background script, content script, feature modules, options page, storage, build pipeline.
• Clear labels & legends.