$ show gdh1995/vimium-c
Vimium C is a browser extension that provides keyboard-driven navigation and productivity features, forked from Vimium. Its architecture is a classic Chrome/Firefox extension with a background service worker or page, content scripts injected into every page, and extension pages (options, omnibar, show image). The background script manages state, settings, browsing data (history, bookmarks), and orchestrates commands like tab management, URL opening, and synchronization. Content scripts implement the core user-facing features: link hints (detecting clickable elements and overlaying markers), keyboard key handlers with a finite state machine for mapping keystrokes to commands, visual mode for text selection, find-in-page, scrolling with smooth animations, and an omnibar (Vomnibar) for search, history, bookmarks, and command execution. The Vomnibar is a rich UI component that communicates with the background via port messaging. The extension supports multiple browsers (Chrome, Firefox, Edge) and both Manifest V2 and V3, with extensive version-specific conditionals and polyfills. The build system uses TypeScript, gulp, rollup, and terser to produce optimized builds, and includes custom patches to vendored TypeScript and Terser. The codebase demonstrates high engineering effort in handling complex browser quirks and performance optimization, but also carries technical debt from accumulated workarounds and legacy browser support.
The LLM identified 5 files worth highlighting for reuse:
A self-contained JavaScript parser and evaluator that tokenizes, parses, and executes user-defined scripts in a sandboxed context. It supports scoping, closures, and limited environment access, and is used for dynamic settings and custom key mapping expressions. The implementation is standalone, with no dependencies on other internal modules, and can be extracted for any project requiring safe, controlled script evaluation.
A collection of safe DOM manipulation wrappers that guard against overridden or missing native properties (e.g., `textContent_s`, `contains_s`, `focus_`, `dispatchEvent_`). It provides consistent behavior across browsers with fallbacks for quirks like `openOrClosedShadowRoot`. The module is self-contained (uses only basic utilities) and demonstrates a robust pattern for writing secure extension code that must coexist with potentially hostile page scripts.
Provides viewport-relative rectangle calculations, zoom handling, element visibility checks, and bounding rect normalization. It is used heavily by link hints and scrolling logic. The module is isolated and could serve as a standalone utility for any browser extension needing precise element position computation across different zoom levels and iframe boundaries.
Implements a parser and state machine for user-defined key mappings. It parses key sequences, resolves conflicts, and builds a decision tree (FSM) for efficient keystroke dispatch. The logic handles modifiers, key sequences, and mode-specific mappings. This is a self-contained module that can be reused for any application needing parseable multi-key shortcuts with prioritization and conflict resolution.
Provides functions to synthetically dispatch mouse, click, hover, touch, and pointer events with realistic timing and browser-specific workarounds (e.g., `addEventListener` patching, picker interaction). It abstracts the complexities of simulating user interaction across different browsers and is self-contained with minimal dependencies. The pattern is useful for any extension or tool that needs to programmatically perform clicks or hovers with high fidelity.