LeetCode Toolkit
https://github.com/eclipher/leetcode-toolkit
Features
This userscript enhances the LeetCode with various tweaking and additions. It supports both the US version of LeetCode.com, and the China version.
Problem Page
On Description Tab, these buttons are added:
- Copy Title: For some reason the problem title is an unclickable link, and you can't simply double click it to select the text. This button will copy the title to your clipboard.
- Copy Description: Copy the problem description in Markdown format. Ideal for pasting into into your notes, or for asking an AI assistant.
- Save as Jupyter Notebook: Bundles the problem title, description in Markdown, and the current code you have into a single
.ipynb
file. See About Jupyter Notebook section for more detail.
On Editorial Tab, these buttons are added:
- Find Screenshot(*): If you don't have access to an editorial, click on this button to try to find a screenshot of the editorial. If found, it will open the link to the screenshot. The source of the screenshots is Leetcode Screenshotter.
- Save Editorial as Markdown(*): If you do have access to an editorial, click on this button and the script will scrape the editorial and download it as one single
.md
file. See About Editorial Scraping section for more detail.
The code editor receives some quality-of-life adjustments:
- Format On Save: Automatically format code when pressing Ctrl + S.
- Unlock IntelliSense: Enjoy autocompletion and hover suggestions without paying for premium.
Explore Cards
- Save Article as Markdown(*): Scrape and download an Explore Card article as markdown file. See About Editorial Scraping section for more detail.
(*) These features are for US site only.
About Editorial Scraping
LeetCode editorial articles contains codes, slides, videos, math expressions and so on. You can use any Markdown readers to view the scraped .md
files, but I developed a dedicated LeetCode Editorial Reader app to view them in best layout.
A few things to notice:
- Codes: will be saved as multiple code blocks in different languages. LeetCode Editorial Reader can display them in tab layout.
- Slides are saved as a series of images. LeetCode Editorial Reader can display them in true slide layout.
- Speaking of images, they are saved as Base64-encoded string, which means they are directly inside the markdown without the risk of "image not found". (This also makes the file larger though.)
- Math expressions are saved, but you may need compatible viewers such as VS Code or LeetCode Editorial Reader to render them correctly.
- Videos are not saved. That's a headache I don't want to deal with.
About Jupyter Notebook
Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations, and narrative text.
The Save as Jupyter Notebook
feature helps you transfer LeetCode problems into a Jupyter Notebook document, so you can read the problem, write and run the solution, add additional notes, all at one place on your local machine.
You can open .ipynb
notebooks with clients such as VS Code. By default it supports Python, but kernels for many other languages are available too.
Installation
To use this userscript, you'll need a userscript manager like Tampermonkey (available for Chrome, Firefox, and other browsers).
- Install Tampermonkey or a similar userscript manager for your browser.
- Go to the GreasyFork Page, and click on the "Install this script" button.
- Visit a LeetCode problem page, and you should see the new features added by the script.
Credits
This script is inspired by the following projects:
License
MIT License