A Chrome extension that automates the documentation of LeetCode problem solutions into professionally formatted .docx documents for academic submissions.
- Download leetcode-doc-generator
chrome://extensionsβ Developer mode β Load unpacked β Select folder leetcode-doc-generator-main- β Done!
- Features
- Architecture
- Installation
- Usage
- API Documentation
- Development
- Testing
- Contributing
- Troubleshooting
- License
- β Smart Code Extraction: Automatically capture LeetCode submission details from submission pages
- β Intelligent Line Number Removal: Removes line numbers while preserving code indentation
- β HTML Element Filtering: Ignores React syntax highlighter line number elements
- β Auto-Refresh: Automatically refreshes page if content script isn't loaded
- β
URL Redirection: Handles
/submissions/detail/{id}/URLs automatically
- β Keyboard Shortcut: Quick capture with Ctrl+Shift+K - opens popup and auto-captures
- β Problem Management: Full CRUD operations for problems and problem sets
- β Drag & Drop Reordering: Intuitive problem reordering interface
- β Visual Feedback: Real-time status updates with loading animations
- β Data Validation: Comprehensive input validation and error handling
- β Professional Formatting: Generate beautifully formatted .docx documents
- β Multi-Language Support: Smart language detection for various programming languages
- β Custom Styling: Arial for text, Courier New for code, proper spacing and structure
graph TB
A[LeetCode Page] --> B[Content Script]
B --> C[Background Service Worker]
C --> D[Popup Interface]
D --> E[Storage Manager]
E --> F[Document Generator]
F --> G[.docx File]
subgraph "Chrome Extension"
B
C
D
E
F
end
| Component | Responsibility | Key Files |
|---|---|---|
| Content Script | DOM extraction, code cleaning | content.js |
| Background Worker | Message routing, lifecycle management | background.js |
| Popup Interface | User interaction, state management | popup.js, popup.html, popup.css |
| Storage Manager | Data persistence, CRUD operations | storage.js |
| Document Generator | .docx file creation and formatting | docxGenerator.js |
- Extraction Phase: Content script extracts code from LeetCode submission pages
- Processing Phase: Background worker routes messages and manages state
- Storage Phase: Storage manager persists data with validation
- Generation Phase: Document generator creates formatted .docx files
- Chrome browser (version 88+)
- Developer mode enabled in Chrome extensions
- Internet connection (for docx library CDN)
# Clone the repository
git clone https://github.com/prithvi1236/leetcode-doc-generator.git
cd leetcode-doc-generator
# Load in Chrome
# 1. Open chrome://extensions/
# 2. Enable "Developer mode"
# 3. Click "Load unpacked"
# 4. Select the project directory- Download from Chrome Web Store (coming soon)
- Or use the manual installation method above
// Navigate to extension popup
// Fill in required information
{
"problemSetTitle": "Problem Set 6",
"studentName": "John Doe"
}- Navigate to LeetCode submission page
- Use keyboard shortcut
Ctrl+Shift+Kor click extension icon - Click "Capture from Current Page"
- Extension automatically handles page refresh if needed
- Reorder: Drag and drop problems in desired sequence
- Edit: Modify problem details using edit button
- Delete: Remove individual problems or clear all
- Click "Generate Document" to create .docx file
- File automatically downloads with format:
{Student Name} - {Problem Set Title}.docx
Ctrl+Shift+K: Open popup and auto-capture (if on submission page)
The extension automatically handles different LeetCode URL formats:
https://leetcode.com/problems/{slug}/submissions/{id}/β Direct supporthttps://leetcode.com/submissions/detail/{id}/β Auto-redirects to proper format
- Auto-refresh: Automatically refreshes page if content script fails to load
- Retry logic: Multiple attempts with exponential backoff
- Graceful degradation: Clear error messages with recovery suggestions
Saves problem set metadata.
Parameters:
info(Object): Problem set informationtitle(string): Problem set title (2-200 characters)submittedBy(string): Student name (2-100 characters)
Returns: Promise<void>
Throws: Error if validation fails
await saveProblemSetInfo({
title: "Problem Set 6",
submittedBy: "John Doe"
});Adds a new problem to the current problem set.
Parameters:
problem(Object): Problem dataname(string): Problem name (1-300 characters)submissionLink(string): Valid LeetCode submission URLcode(string): Source code (1-100,000 characters)language(string): Programming language
Returns: Promise<void>
await addProblem({
name: "Two Sum",
submissionLink: "https://leetcode.com/problems/two-sum/submissions/123456/",
code: "function twoSum(nums, target) { ... }",
language: "JavaScript"
});Generates a formatted .docx document.
Parameters:
documentData(Object): Complete document dataproblemSetInfo(Object): Problem set metadataproblems(Array): Array of problem objects
Returns: Document - docx Document instance
Extracts problem data from current LeetCode submission page.
Returns: Promise<Object> - Extracted problem data
Throws: Error if extraction fails
leetcode-doc-generator/
βββ docs/ # Documentation
β βββ API.md # API documentation
β βββ ARCHITECTURE.md # System architecture
β βββ CONTRIBUTING.md # Contribution guidelines
βββ src/ # Source code (future organization)
βββ tests/ # Test files (future)
βββ manifest.json # Extension configuration
βββ package.json # Project metadata
βββ popup.html # Popup UI
βββ popup.js # Popup logic
βββ popup.css # Popup styling
βββ content.js # Content script
βββ background.js # Background service worker
βββ docxGenerator.js # Document generation
βββ storage.js # Storage operations
βββ docx.min.js # External library
βββ icons/ # Extension icons
βββ icon16.png
βββ icon48.png
βββ icon128.png
βββ bmc-brand-icon.png
# Install development dependencies (if any)
npm install
# Enable Chrome extension developer mode
# Load unpacked extension from project directory
# For debugging
# Open Chrome DevTools on extension popup
# Check background page in chrome://extensions- Use ES6+ features where supported
- Prefer
async/awaitover Promises - Use descriptive variable and function names
- Add JSDoc comments for all functions
- Handle errors gracefully with try-catch blocks
- Use semantic HTML elements
- Follow BEM methodology for CSS classes
- Ensure responsive design principles
- Maintain accessibility standards
- Lazy Loading: Content script only loads on LeetCode submission pages
- Efficient DOM Queries: Minimize DOM traversal operations
- Memory Management: Clean up event listeners and temporary data
- Storage Optimization: Use Chrome's local storage efficiently
- Extension loads without errors
- Popup opens and displays correctly
- Problem set info saves and persists
- Code extraction works on various LeetCode pages
- Document generation produces valid .docx files
- Handle pages without code blocks
- Handle malformed submission URLs
- Handle network connectivity issues
- Handle storage quota exceeded
- Handle very large code submissions
- Chrome (latest)
- Chrome (version 88+)
- Different screen resolutions
- Different zoom levels
# Unit tests
npm test
# Integration tests
npm run test:integration
# E2E tests
npm run test:e2e- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes following the code style guidelines
- Test your changes thoroughly
- Commit with descriptive messages:
git commit -m 'Add amazing feature' - Push to your branch:
git push origin feature/amazing-feature - Open a Pull Request
- Issue Creation: Create an issue describing the bug or feature
- Branch Creation: Create a branch from
mainfor your changes - Development: Implement changes following coding standards
- Testing: Test changes manually and add automated tests if applicable
- Documentation: Update documentation as needed
- Review: Submit PR for code review
- Merge: Merge after approval and testing
- Functionality: Does the code work as intended?
- Performance: Are there any performance implications?
- Security: Are there any security vulnerabilities?
- Maintainability: Is the code readable and maintainable?
- Testing: Are there adequate tests for the changes?
Cause: Content script failed to inject or page not fully loaded Solution: Extension automatically refreshes page and retries
Cause: Page structure changed or submission not fully rendered Solutions:
- Ensure page is fully loaded before capture
- Refresh the page manually
- Check browser console for detailed error logs
Cause: Invalid data or docx library not loaded Solutions:
- Verify all required fields are filled
- Check internet connection (for docx library CDN)
- Try refreshing the extension popup
Cause: Too much data stored locally Solution: Clear old problem sets or reduce code size
Enable debug logging by opening browser console:
- Right-click extension popup β Inspect
- Check Console tab for detailed logs
- Background page logs:
chrome://extensionsβ Background page
If the extension feels slow:
- Check if you have too many problems stored
- Verify internet connection for CDN resources
- Close other Chrome extensions temporarily
- Restart Chrome browser
This project is licensed under the MIT License - see the LICENSE file for details.
- docx library for document generation
- Font Awesome for icons
- LeetCode for providing the platform that inspired this tool
- π Bug Reports: GitHub Issues
- π‘ Feature Requests: GitHub Discussions
- β Support Development: Buy me a coffee
