- Introduction
- Features
- Screenshots
- Prerequisites
- Installation
- Usage
- Configuration
- How It Works
- Limitations
- License
- Acknowledgements
The LeetCode QuickAdd Script is an Obsidian plugin script designed to more seamlessly integrate LeetCode problem information into your Obsidian vault. This script leverages the QuickAdd plugin and a LeetCode API to fetch problem details and format them into a structured note, making it easier for users to track their LeetCode progress and study efficiently within Obsidian.
This is my first little coding project :) It aims to streamline the process of documenting LeetCode problems, allowing users to focus on problem-solving rather than manual note-taking.
- Fetch LeetCode problem details using the problem's URL or title slug
- Automatically format problem statements, examples, constraints, and follow-up questions
- Convert HTML content to Markdown for better compatibility with Obsidian
- Create structured notes with problem metadata, including difficulty and tags
- Format examples as collapsible callouts for better organization
- Include formatted hints as hidden callouts
- Customize tag prefixes for better integration with your existing tag system
Auto populated properties
Sample Output
Some support for more complex questions
Before using this script, ensure you have the following:
- Obsidian installed on your device
- The QuickAdd plugin installed and enabled in your Obsidian vault
- In your Obsidian vault, create a new folder named
scripts
(if it doesn't already exist) - Save
leetcode-quickadd.js
in thescripts
folder - Open the QuickAdd plugin settings in Obsidian
- Create a new Macro and add a "User Script" choice
- Select the
leetcode-quickadd.js
file as the script for this choice - Add a page template for your Macro to use. See my personal example below for reference
- Configure the Macro settings as desired (e.g., output folder for LeetCode notes)
- Trigger the QuickAdd menu in Obsidian
- Select the LeetCode QuickAdd Macro you created
- Enter the URL or title slug of the LeetCode problem when prompted
- The script will fetch the problem details and create a new note with the formatted information
You can customize the script behavior by modifying the following settings in the QuickAdd Macro configuration:
- LeetCode Tag Prefix: Set a prefix for LeetCode problem/tags (default: "leetcode/")
Tip
To change these settings:
- Open the QuickAdd plugin settings
- Edit the Macro you created for the LeetCode QuickAdd script
- Modify the values in the "User Script" choice settings
- The script prompts the user for a LeetCode problem title slug
- It sends a request to the LeetCode API to fetch problem details
- The received HTML content is converted to Markdown
- Problem information is formatted into a structured note, including:
- Problem title and ID
- Difficulty
- LeetCode problem link
- Problem statement
- Examples (as expanded callouts)
- Constraints (as a callout)
- Follow-up questions (as a hidden callout)
- Tags (with customizable prefix)
- Hints (as hidden callouts)
- The formatted note is created in the specified Obsidian folder
The LeetCode QuickAdd script provides several variables that you can use in your note templates. These variables are populated with data fetched from the LeetCode API. Here's a list of currently available variables and their descriptions:
Variable | Description | Example |
---|---|---|
{{VALUE:id}} |
The LeetCode problem ID | 1 |
{{VALUE:title}} |
The title of the problem | "Two Sum" |
{{VALUE:difficulty}} |
The difficulty level of the problem | "Easy" |
{{VALUE:link}} |
The URL of the problem | "https://leetcode.com/problems/two-sum" |
{{VALUE:problemStatement}} |
The full problem statement in Markdown format | (Markdown formatted text) |
{{VALUE:tags}} |
A formatted list of problem tags with customizable prefix | - leetcode/array |
{{VALUE:fileName}} |
A sanitized filename for the note | 1. "Two Sum" |
{{VALUE:formattedHints}} |
Formatted hints as hidden callouts | (Markdown formatted hints) |
To use these variables in your QuickAdd template, surround them with double curly braces. Here's my personal template:
---
created: {{DATE}}
modified:
completed: false
leetcode-index: {{VALUE:id}}
link: {{VALUE:link}}
difficulty: {{VALUE:difficulty}}
tags:
{{VALUE:tags}}
- programming/practice
- leetcode/problem
---
# {{VALUE:title}}
## Question
{{VALUE:problemStatement}}
### Hints
{{VALUE:formattedHints}}
---
## Solution
### Intuition
<!--Describe your first thoughts on how to solve this problem -->
### Approach
<!-- Describe your approach to solving the problem. -->
### Complexity
#### Time complexity
#### Space complexity
### Code
---
Effective tagging and the Dataview Plugin allow for some cool tracking and filtering of the problems. Check it out:
- Currently untested on mobile
- Due to the large varience in Leetcode questions it sometimes has small formatting issue, particularly with examples and constraints.
- Probably many more!
This project is licensed under the MPL-2 License - see the LICENSE file for details.
- QuickAdd plugin by Christian B. B. Houmann
- Alfa Leetcode by Arghya Das
- LeetCode for providing so many problems
- Obsidian for the amazing note-taking app
If you find this script helpful, consider starring the repository and sharing it with others! Thanks! Shane Z :)