Skip to content

localhost433/LeetHub

 
 

Repository files navigation

LeetHub

Chrome extension (Manifest V3) that commits your accepted solutions from LeetCode and GeeksforGeeks to a GitHub repository.

Credits

This project is a fork in the LeetHub ecosystem:

What it does

  • Automated Submission Handling: When you submit a solution on LeetCode or GeeksforGeeks and it gets Accepted, the extension automatically creates/updates a folder for that problem in your configured GitHub repo.
  • Manual Import: You can manually import your existing accepted solutions from LeetCode by clicking the "Sync" button in the extension popup. This does not happen automatically to prevent unwanted commits.
  • Deduplication: It tracks solved counts and file SHAs in chrome.storage.local to avoid duplicate commits.

Comparison vs LeetHub-3.0

LeetHub-3.0 (raphaelheinz) focuses on LeetCode compatibility and adds:

  • LeetCode.cn support in addition to LeetCode.com.
  • A manual synchronization button (including syncing previously-selected submissions).
  • Notes about UI compatibility (old layout vs dynamic layout).

This fork’s notable additions/changes:

  • Manifest V3 + stricter CSP with PAT-first auth (fine-grained PAT recommended).
  • Repo sync seeding: scans an existing repo and seeds stats.sha to avoid duplicate uploads.
  • Manual Backfill: imports existing accepted solutions from LeetCode only when explicitly triggered.
  • Multi-accepted handling options: latest accepted per language, or keep all accepted submissions (suffix filenames with _<submissionId>).

Install (unpacked)

  1. Open chrome://extensions.
  2. Enable Developer mode.
  3. Click Load unpacked.
  4. Select this folder (LeetHub).

First-time setup

  1. Click the extension icon.
  2. Authenticate with GitHub using one of these:
    • Fine-grained PAT (recommended): create a fine-grained Personal Access Token restricted to a single repository, then paste it into the popup and click Save token.
    • OAuth (convenient): click Authorize with GitHub and complete the OAuth flow.
  3. On the setup (welcome) page, choose one:
    • Create repo (new repo), or
    • Link repo (use an existing repo).

Using an existing repo (sync)

If you link a repo that already contains solutions, LeetHub performs a one-time sync that:

  • Scans the repo file tree.
  • Seeds the internal stats.sha map so future uploads update existing files instead of re-creating them.
  • Updates the solved count based on existing problem folders.

Usage

  • LeetCode: solve a problem -> submit -> once it shows Accepted, the extension commits to GitHub.
  • GeeksforGeeks: same idea—when the submission is accepted, it commits to GitHub.

You can view your linked repo and progress stats from the extension popup.

Development

Install dev dependencies:

npm run setup

Common commands:

npm run format
npm run format-test
npm run lint
npm run lint-test

Troubleshooting

  • Auth loops / no token saved: finish the GitHub OAuth flow and ensure you didn’t block GitHub cookies/popups.
  • Nothing uploads after AC: confirm a repo is linked (mode is commit), and check extension errors in chrome://extensions -> Service worker -> Inspect.
  • GitHub API errors / rate limits: syncing very large repos can take time and can hit rate limits.

Privacy

  • Stores the GitHub token in chrome.storage.local.
  • Sends requests only to github.com, api.github.com, leetcode.com, and practice.geeksforgeeks.org.

Security note (GitHub permissions)

  • Creating a new repo does not automatically limit a GitHub OAuth token to that repo. OAuth scopes are account-wide.
  • If you want repo-scoped access, use a fine-grained PAT restricted to the single repo you want LeetHub to write to (grant Contents: Read and write).
  • LeetHub’s OAuth flow uses PKCE (no embedded client secret), but it’s still broader access than a repo-restricted fine-grained PAT.

Tutorial: Create a fine-grained PAT (recommended)

Goal: create a token that can only write to one repository.

  1. Open GitHub token settings:
  2. Under Token name, pick any name (e.g. leethub).
  3. Set an Expiration (recommended).
  4. Under Repository access, choose:
    • Only select repositories -> pick the repo you want LeetHub to write to.
  5. Under Permissions -> Repository permissions, set:
    • Contents: Read and write
    • Metadata: Read-only (usually required)
  6. Click Generate token.
  7. Copy it immediately (GitHub won’t show it again).
  8. In the extension popup -> paste into Fine-grained token -> click Save token.

Notes:

  • OAuth in this repo uses a fixed GitHub OAuth client id; for forks (this being one), OAuth may not work. Using a fine-grained PAT avoids this.
  • If your repo is owned by an organization, the org may need to allow/approve fine-grained PATs.
  • If you get 403 errors while uploading, your token likely lacks Contents: Read and write or the repo wasn’t selected.

About

For personal use.

Resources

License

Stars

Watchers

Forks

Contributors

Languages

  • JavaScript 88.5%
  • HTML 6.5%
  • CSS 5.0%