Skip to content

feat: automatically check and mark already solved questions#99

Open
Saarthak50 wants to merge 1 commit into
raphaelheinz:mainfrom
Saarthak50:feat/auto-mark-pushed-questions
Open

feat: automatically check and mark already solved questions#99
Saarthak50 wants to merge 1 commit into
raphaelheinz:mainfrom
Saarthak50:feat/auto-mark-pushed-questions

Conversation

@Saarthak50

Copy link
Copy Markdown

Summary

This PR introduces a feature to dynamically identify and mark LeetCode questions that are already present in the user's linked GitHub repository. When visiting a problem page, the extension checks if the solution has already been pushed, and if so, styles the manual Push button as a green Pushed button.

How it works

  1. Direct Path Check: The extension first checks for the default structured location of the problem's README.md (taking user settings like language or difficulty folder structures into account).
  2. Search Fallback: If the folder is not found (status 404), it falls back to querying the GitHub Search API for the repository to search for files matching the problem slug, or camelCase/flat names (e.g. searching for "two-sum", filename:two-sum, or filename:twosum). This allows the extension to find solutions even if they are named differently (like TwoSum.java) or placed in custom paths.
  3. Auto-Sync on Link: When linking an existing repository on the welcome page, it now automatically triggers a sync of solved counts.

Key Changes

src/js/leetcode.js

  • LeetCodeV2.prototype.checkPushedStatus: Queries LeetCode GraphQL for question details, constructs the expected file path, checks if it exists in the GitHub repo, and falls back to a GitHub Code Search if it's not found in the default path.
  • LeetCodeV2.prototype.getLanguage: Added fallback logic to retrieve the current language from the page's dropdown when submissionData is null (on page load).
  • LeetCodeV2.prototype.addManualSubmitButton: Calls checkPushedStatus on page load to style the button as green and labeled Pushed if the solution is found.
  • LeetCodeV2.prototype.markUploaded: Transitions the manual push button state to Pushed and turns it green immediately upon a successful manual push.
  • getGitIcon: Changed hardcoded SVG fill color from #100f0d to currentColor so the icon adapts to the button text color (turns green when pushed).

src/js/welcome.js

  • linkRepo: Programmatically triggers the Sync counts click event upon linking an existing repository to automatically sync counts.

Verification Done

  • Formatted with Prettier (npm run format).
  • Verified with ESLint (npx eslint src/js/leetcode.js src/js/welcome.js).
  • Manually tested by linking repositories with both default folder structures and flat files (e.g. TwoSum.java), verifying that both are recognized and styled as Pushed on page load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant