How ujjwalsharma01/leetcode2ankiplus works
Main Components
• Browser Environment & Userscript:
– LeetCode Web Interface: The webpage where users solve problems.
– Userscript (leetcode2ankibyUjjwal.user.js): Injected into the browser via Tampermonkey/Violentmonkey, responsible for detecting problem events, extracting solution data, and offering UI controls (e.g., “Save to Anki”, “Save to Sheet”).
• Anki Integration Component:
– Anki Application running on the user’s machine with the AnkiConnect add-on.
– API communication from the userscript to the locally running AnkiConnect (typically over a specific port).
• Google Sheets & Google Apps Script:
– Google Apps Script File (GoogleAppsScript.gs) deployed as a Web App that receives problem data submissions.
– Google Sheets (the database) holding problem data (columns like Timestamp, ID, Title, etc.) and interfacing with the SRS.
– Spaced Repetition System Script (LeetcodeSRS.gs) that operates within Google Sheets to manage review scheduling.
• Direct Test Utility:
– The Node.js script (direct_submission_node.js) which is used for testing the connectivity between the Google Apps Script endpoint and Google Sheets.
Relationships and Data Flow
– The userscript in the browser monitors LeetCode pages, captures problem completion and solution details, and initiates two key actions:
• It sends an HTTP request to the Google Apps Script Web App URL (via the googleScriptUrl configuration) to log the solved problem data to Google Sheets.
• It communicates with AnkiConnect (running locally) via an API call to create well-formatted flashcards.
– The Google Apps Script acts as an intermediary, receiving data from the userscript and updating the Google Sheet.
– The SRS script within the Google Sheet (LeetcodeSRS.gs or the separately opened SpacedRepetitionSystem.gs) manages review scheduling and user interactions directly within the spreadsheet interface.
– The Node.js script facilitates direct testing by simulating the submission of problem data to the Google Apps Script endpoint.
Architectural Patterns and Design Principles
– Client-Server Communication: Emphasize the communication flows between the browser (client-side userscript) and the Google Apps Script (server-side endpoint), as well as local inter-process communication with AnkiConnect.
– Extensibility: Note the possibility to update or swap out components (e.g., different problem detection strategies within the script) without impacting the entire architecture.
Relevant Technologies and Frameworks
– JavaScript is the primary programming language both in the userscript and the Apps Script files.
– Tampermonkey/Violentmonkey provides the runtime for the browser userscript.
– Google Apps Script and Google Sheets serve as lightweight backend services.
– Node.js is used for running test scripts.
– AnkiConnect is the bridge used to integrate with the Anki application.
Additional Details to Capture
– Integration points, especially where configuration variables (e.g., “googleScriptUrl” in the userscript) come into play.
– The overall flow from detection (when a problem is solved) to data logging and card generation.
– Where extensibility or error-handling components are implemented, such as the robust error handling strategy and retry logic described in the README.