How 1m-n00b/atcoder-to-obsidian works
Project Type and Purpose
• This project is a browser extension for both Firefox and Chrome.
• Its purpose is to enable users to save AtCoder problem pages and related memo contents directly into an Obsidian vault. It does so by interfacing with the Obsidian Local REST API.
• The extension features a popup UI for user interaction, background scripts to manage extension-wide behavior, and content scripts to interact with the problem pages.
File Structure
• Key Directories:
• entrypoints/background: Contains the background script (index.ts) which likely handles events, messaging, or long-running tasks required by the extension.
• entrypoints/content: Contains the content script (index.ts) which interacts with the AtCoder problem pages.
• entrypoints/popup: Contains the React-based popup front-end (App.tsx, main.tsx, and index.html) that users interact with. This is the UI for entering settings (like Local REST API key and save path) and triggering actions (e.g., “Obsidianに保存”).
• components directory: Contains reusable UI components such as the SettingsModal.
• utils directory: Provides utility functions for markdown conversion, parsing, storage management, and custom types used by the project.
• Configuration and build files: package.json, tsconfig.json, tailwind.config.ts, and postcss.config.cjs are included to manage dependencies, TypeScript settings, and styling (Tailwind CSS). The presence of wxt.config.ts hints at some extension-specific configuration.
• The overall file structure suggests a modular, multi-entry point architecture typical of browser extension development.
README for Additional Insights
• The README clearly explains how to set up and use the extension across Firefox and Chrome.
• It details the user workflow: configuring the local REST API key and target vault path, and then using the popup to send data from AtCoder pages to Obsidian.
• The emphasis on the configuration and toggle settings indicates the critical role of both UI interactions (via popup) and background/configuration logic.
a. Main Components to Include:
• Browser Extension Shell: A high-level container representing the extension running in the browser.
• Background Script: Manages the extension’s lifecycle, messaging, and event handling.
• Popup UI: The front-end interface (built with React) that lets users input configurations (e.g., API key, vault path) and trigger actions.
• Content Script: Injected into AtCoder problem pages to capture or interact with page-specific elements.
• Utility Modules: Modules for markdown conversion, parsing, storage, and type definitions.
• External Service: Obsidian Local REST API that receives the saved data from the extension.
b. Relationships and Interactions:
• The Popup UI sends user commands and configuration settings to the Background Script.
• The Background Script communicates with the Content Script as needed (for example, to extract problem details from AtCoder pages).
• Utility modules are called throughout the extension by various components to handle data formatting, parsing the AtCoder content, and managing local storage of user configurations.
• Data flow from the extension (via popup or background) to the external Obsidian Local REST API is a critical path.
c. Architectural Patterns and Design Principles:
• Modular separation of concerns: Clearly dividing UI (popup), background processing (background scripts), and content interaction (content scripts).
• Separation between presentation (React components, e.g., in components/ and entrypoints/popup) and business logic (utility functions in utils/).
• Asynchronous communication: Likely implemented via message passing between content scripts, popup, and background scripts.
d. Technologies, Frameworks, and Libraries:
• React: For building the popup UI (evidence from *.tsx files).
• Tailwind CSS: For styling (inferred from tailwind.config.ts and postcss.config.cjs).
• TypeScript: Based on typescript configuration (tsconfig.json).
• Browser extension APIs: Specific to Firefox/Chrome, used in background and content scripts.
• Obsidian Local REST API: External dependency the extension communicates with.