Automatically push your accepted LeetCode solutions to GitHub with complete formatting preservation!
- 🚀 Automatic Push - Solutions are pushed to GitHub automatically when accepted
- 🎨 Perfect Formatting - Preserves Python indentation and all code formatting
- 📝 Rich Metadata - Includes problem description, difficulty, tags, and acceptance rate
- 🔄 Smart Extraction - Multiple strategies ensure complete code capture
- ✅ Order Correction - Automatically detects and fixes reversed code
- 🐍 Python-Optimized - Special validation for Python indentation and structure
- Go to: GitHub Settings → Tokens
- Click "Generate new token" → "Generate new token (classic)"
- Give it a name:
LeetCode Extension - Select scope: ✅
repo(Full control of private repositories) - Click "Generate token"
- COPY THE TOKEN immediately (you won't see it again!)
- Open Chrome and navigate to:
chrome://extensions/ - Enable "Developer mode" (toggle in top-right corner)
- Click "Load unpacked"
- Select the
leetcode_extensionfolder - The extension should appear in your extensions list
- Click the extension icon in Chrome toolbar (puzzle piece icon)
- Enter your details:
- Repository:
your-username/repo-name(e.g.,john/leetcode-solutions) - Token: Paste your GitHub Personal Access Token
- Repository:
- Click "Save"
✅ You're all set! The extension is now ready to use.
- Navigate to any LeetCode problem (e.g., https://leetcode.com/problems/two-sum/)
- Write your solution in the code editor
- Click Submit button
- Wait for "Accepted" result
- Done! Check your GitHub repo - the solution is automatically pushed
For debugging or to see what's happening:
- Open DevTools (press
F12) - Go to Console tab
- Look for messages starting with
[LeetCode Extension]
Expected console output:
[LeetCode Extension] 🚀 Submit button clicked!
[LeetCode Extension] ✅ Extracted code via Monaco Model API
[LeetCode Extension] Code Extraction Summary: {method: "monaco-model-api", lines: 15, ...}
[LeetCode Extension] Attempting to push to GitHub...
[LeetCode Extension] ✅ Successfully pushed to GitHub!
For each accepted solution, the extension creates a folder in your repository:
Make_Sum_Divisible_by_P/
├── Make_Sum_Divisible_by_P.py
└── README.md
Your complete code with:
- ✅ Perfect indentation (especially important for Python!)
- ✅ All lines in correct order
- ✅ Proper file extension based on language
Auto-generated with:
- Problem title and description
- Difficulty level (Easy/Medium/Hard)
- Tags (Array, Dynamic Programming, etc.)
- Acceptance rate
- Link to original LeetCode problem
- List of solution files
Example README:
# Make Sum Divisible by P
Given an array of positive integers nums, remove the smallest subarray...
---
## Metadata
- Language: Python
- Difficulty: Medium
- Acceptance: 25.4%
- Tags: Array, Hash Table, Prefix Sum
- URL: https://leetcode.com/problems/make-sum-divisible-by-p/
## Files
- Make_Sum_Divisible_by_P.pyCheck the Service Worker console:
- Go to
chrome://extensions/ - Find "LeetCode to GitHub" extension
- Click "service worker" (blue link)
- Look for error messages starting with
[LeetCode Extension BG]
Common issues:
- ❌ "Repo or token not set" → Configure extension via popup
- ❌ "GitHub API failed (401)" → Invalid/expired token, create a new one
- ❌ "GitHub API failed (404)" → Repository doesn't exist or wrong name format
- ❌ "No pending submission found" → Must click Submit BEFORE solution is accepted
The extension automatically detects and corrects reversed code. If you see:
[LeetCode Extension] ⚠️ Code appears to be in REVERSE order - auto-correcting!
[LeetCode Extension] ✅ Code order corrected!
This means the extension fixed the line order before pushing to GitHub.
If Python code has no indentation, check console for:
[LeetCode Extension] ⚠️ WARNING: Python code lacks indentation - may be corrupted!
Solution: Reload the extension:
- Go to
chrome://extensions/ - Click the reload icon ↻ on "LeetCode to GitHub"
- Refresh your LeetCode page (
Ctrl+Shift+R)
If you see:
[LeetCode Extension] ⚠️ Could not detect language, defaulting to py (Python)
The extension will use .py as default. This is fine if you're coding in Python!
Checklist:
- ✅ Extension is enabled in
chrome://extensions/ - ✅ You clicked Submit button (not just "Run")
- ✅ Solution got "Accepted" status
- ✅ Repository and token are configured in extension popup
- ✅ GitHub repository exists and token has
repopermissions
-
Monaco Model API (Primary)
- Accesses Monaco editor's internal data model
- Returns complete code in correct order
- Most reliable method
-
Monaco Editor Instance
- Direct access via DOM element property
- Fallback if global Monaco API unavailable
-
View-Lines with Sorting
- Reads
.view-lineDOM elements - Sorts by CSS
topposition for correct order - Handles virtual scrolling
- Reads
-
Textarea Fallback
- For older LeetCode UI
- Backward compatibility
-
Container Text
- Last resort
- May be incomplete
- Line Order Detection: Checks if
class/defappear at top - Auto-Reversal: Flips code if detected as backwards
- Python Validation: Verifies indentation and structure
- Completeness Check: Warns if code seems too short
- Submit Click: Captures problem metadata
- Accepted Detection: Extracts code using best available method
- Validation: Checks order, indentation, completeness
- GitHub API: Creates/updates folder with solution and README
- Confirmation: Logs success in console
- Supported Languages: Python, Java, C++, JavaScript, TypeScript, and all LeetCode languages
- File Naming: Problem title with underscores (e.g.,
Two_Sum.py) - Updates: Re-submitting updates the existing file (no duplicates)
- Privacy: Token is stored locally in Chrome storage only
Found a bug or have a suggestion? Feel free to:
- Report issues
- Submit pull requests
- Suggest improvements
This extension is provided as-is for personal use.
Happy Coding! 🚀
Made with ❤️ for LeetCode enthusiasts