Skip to content

Instantly share code, notes, and snippets.

@alexcmgit
Last active October 6, 2025 15:24
Show Gist options
  • Select an option

  • Save alexcmgit/f70da60025249097e0778c2da9d32728 to your computer and use it in GitHub Desktop.

Select an option

Save alexcmgit/f70da60025249097e0778c2da9d32728 to your computer and use it in GitHub Desktop.
Tampermonkey LeetCode Utils
// ==UserScript==
// @name LeetCode Utils
// @namespace http://tampermonkey.net/
// @version 2025-02-11
// @description try to take over the world!
// @author You
// @match https://leetcode.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// ==/UserScript==
(function() {
'use strict';
let ready = false
window.addEventListener("load", function(e) {
ready = true
})
function copyToClipboard(text) {
navigator.clipboard.writeText(text)
}
GM_registerMenuCommand("Copy LeetCode Problem Description to Clipboard", function() {
if (!ready) return alert("Page is still loading, wait a moment.")
const titleLinkEl = document.querySelector("div.flex.items-start.gap-2 > div > a") || document.querySelector(".question-title")
const descriptionEl = document.querySelector(`div[data-track-load=description_content]`) || document.querySelector(".question-description__3U1T")
const problemDescription = descriptionEl.innerHTML
const difficultyEl = document.querySelector(`div[class*='text-difficulty-']`)
const difficulty = difficultyEl?.textContent?.toLowerCase() || "unspecified"
const title = titleLinkEl.textContent
console.log(`LeetCode Title: ${title}`)
const url = ((url) => {
url.search = ""
return url.toString()
})(new URL(window.location.toString()))
const content = `---
title: ${title}
url: ${url}
extra:
leetcode_difficulty: ${difficulty}
---
${problemDescription}
`
copyToClipboard(content)
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment