How obuchiyuki/gittohabu works
Project type and purpose
• This is a browser (Chrome) extension whose sole function is to Japanese-localize the GitHub UI. It injects translation logic into GitHub pages (content scripts), offers a popup UI for on-demand translation and enabling/disabling, and provides an options page for API-key configuration.
File structure
• manifest.json
• Defines extension metadata, permissions (tabs, storage, host permissions for github.com), and entry points (content scripts, popup page, options page).
• content.js + dictionary.js
• The “content” component that runs in the context of every GitHub page.
• Loads the built-in dictionary (dictionary.js), observes & replaces UI text, and conditionally calls external translation APIs.
• popup.html + popup.js
• Browser-action (toolbar) UI that lets the user trigger an immediate translation pass and toggle the extension on/off.
• options.html + options.css + options.js
• Options page where the user enters API-keys and toggles “use external API” on/off. Settings are stored via chrome.storage.
• Static assets for the extension’s toolbar and options UI.
• README.md
• Confirms project flow: injection → dictionary replace → optional API call → DOM patch.
README for architectural hints
• Confirms use cases (auto-translate, manual translate via popup, enable/disable via Alt+J).
• Mentions privacy boundaries (chrome.storage + external API).
• Notes runtime environment: SPA GitHub DOM changes, so content.js likely uses a MutationObserver.
a. Main components
• Browser (Chrome)
• Manifest (static config)
• Content Script (content.js + dictionary.js)
• Extension UI:
– Popup (popup.html/js)
– Options Page (options.html/css/js)
• Storage (chrome.storage.sync or local)
• External Translation Services (DeepL, Google Cloud, Azure)
b. Relationships and interactions
• Browser reads manifest.json and injects content.js into GitHub pages.
• Content script loads dictionary, observes DOM changes, and replaces text.
• If “external API” is enabled, content script issues HTTP requests to the chosen translation provider.
• Popup sends messages (chrome.runtime.sendMessage) to content script to trigger manual translation or toggle.
• Options page reads/writes user settings (API keys, toggles) into chrome.storage.
• Content script retrieves settings from chrome.storage when it initializes or whenever a toggle occurs.
c. Architectural patterns/design principles
• Event-driven: content script reacts to page load, DOM mutations, and messages from popup/options.
• Separation of concerns: translation logic (dictionary.js + API calls) is decoupled from UI (popup/options).
• State persistence via chrome.storage.
d. Key technologies, frameworks, or libraries
• Chrome Extension APIs (tabs, runtime, storage)
• Fetch or XHR for HTTP calls to translation services
• MutationObserver for dynamic SPA handling
• Plain JavaScript, HTML, CSS (no front-end frameworks)