How cschiller/zhongwen works
Project type and purpose
• This is a browser extension (Chrome/Firefox) named “Zhongwen” that provides a pop-up Chinese dictionary and learning tool.
• Key functionality: on-page hover lookups, keyboard navigation, built-in word list, options page, and integration with external learning resources.
File structure
Top-level files
• manifest.json – extension configuration and permissions
• background.js / background.html – background (event) page for managing state, context menus, keyboard shortcuts
• content.js – content script injected into web pages for DOM interaction and pop-up rendering
• dict.js – dictionary lookup logic, wrapper around data files
• data/ – raw data: CEDICT files and JSON keyword lists
• css/, js/ – UI assets for options, word list, pop-up styling and behavior
• options.html + js/options.js – configuration UI
• wordlist.html + js/wordlist.js – built-in word list UI and export
• help.html, background.html – auxiliary UI for keyboard shortcut summary
• package.json / .eslintrc.json – build & lint configuration for development
Key insights from README
• Architecture is event-driven: content script captures hover & keyboard events; background page handles long-running tasks, storage, and external navigation.
• Data flow involves reading local dictionary files, performing lookups in dict.js, then presenting results.
• Multiple UIs (pop-up, options, word list, help) each in its own HTML/JS subcomponent.
Main components
• Browser Extension Shell (manifest)
• Background Component
– Event page (background.js)
– Context menu & keyboard shortcut handlers
– chrome.storage for options & word list persistence
• Content Script Component
– Injected into web pages (content.js + css/content.css)
– Listens for hover & key events
– Sends/receives messages to/from Background
– Renders pop-up UI (background.html or dynamic DOM insertion)
• Data Layer
– dict.js module
– data/cedict idx & u8 files
– grammarKeywordsMin.json, vocabularyKeywordsMin.json
• UI Subsystems
– Pop-up window (hover/keyboard lookup)
– Options page (options.html + js/options.js + css)
– Word list page (wordlist.html + js/wordlist.js + css/wordlist.css)
– Help page (help.html)
• External Services
– Chinese Grammar Wiki
– Skritter, Anki (via export)
– Online dictionaries (via Alt+1..7 shortcuts)
Relationships and interactions
1. User hovers or presses key → content script captures event.
2. Content script sends message to background: “lookup word X”.
3. Background or dict.js reads data files, returns lookup result.
5. On “remember” (R) or “export” (C/S) → content script notifies background to update chrome.storage or open export tab.
6. Options page reads/writes settings via chrome.storage.
7. Word list page retrieves stored words, offers export.
8. Context menu and keyboard shortcuts are registered by background, trigger content script or open new tabs for external services.
Architectural patterns and design principles
• Event-driven, message-passing within extension boundaries
• Separation of concerns:
• content scripts handle UI injection, user interactions
• background page handles data access, state, and cross-tab actions
• dedicated HTML/JS modules for each UI view
• Data abstraction in dict.js isolating raw data from presentation
• Configurable behavior via options stored in chrome.storage