$ show maboloshi/github-chinese
This repository is a Tampermonkey/Greasemonkey userscript that translates the GitHub web interface into Chinese (Simplified and Traditional). It works by loading a dictionary file containing static translations and regex rules, then applying them to the DOM on page load and dynamically via MutationObserver. It includes a sophisticated patch for GitHub's React-based GlobalNav header that carefully times translations to avoid conflicts with React rendering. The repository also contains a VS Code extension that injects the script into VS Code's integrated browser via Chrome DevTools Protocol, enabling translation within the IDE. The codebase is well-structured with clear separation of configuration, state management, and translation logic. It includes a comprehensive test suite for regression testing. The project is actively maintained with frequent updates to keep pace with GitHub's UI changes.
The LLM identified 4 files worth highlighting for reuse:
A minimal Chrome DevTools Protocol client that wraps the VS Code proposed browser API's RawCdpSession. It handles request/response ID matching, event dispatching, and provides a clean send() method. This pattern is reusable for any VS Code extension that needs to communicate with browser tabs via CDP.
A self-contained manager for tracking untranslated terms encountered during page translation. It stores terms per page path using GM_setValue/GM_getValue for persistence, provides methods for recording, cleanup, export to JSON, and statistics. The pattern of collecting and exporting untranslated data is reusable for any userscript that needs to gather user-facing text for dictionary improvement.
A simple higher-order function that wraps any function with a try-catch block, logging errors without crashing the page. It's used throughout the codebase to isolate failures in translation routines. This pattern is a best practice for userscripts that operate on third-party pages where DOM assumptions may fail.
An optimized MutationObserver callback handler that collects changed nodes, filters out those matching ignore selectors, and then deduplicates by removing descendant nodes whose ancestors are also in the change set. This prevents redundant traversal of the same subtree multiple times. The ancestor deduplication algorithm is a reusable pattern for any MutationObserver-based DOM monitoring system.