Greasy Fork is available in English.

Leetcode Difficulty Hider

Replace difficulty labels with "Hidden" and apply custom styles.

  1. // ==UserScript==
  2. // @name Leetcode Difficulty Hider
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Replace difficulty labels with "Hidden" and apply custom styles.
  6. // @author You
  7. // @match https://leetcode.com/*
  8. // @exclude https://leetcode.com/
  9. // @exclude https://leetcode.com
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. // Helper function to replace text content and apply styles
  18. function replaceText(element, customText = "Hidden") {
  19. if (element.dataset.processed || element.closest("svg")) return; // Skip already processed elements
  20.  
  21. // Store the original text
  22. const originalText = element.textContent.trim();
  23.  
  24. // Replace text with "Hidden" and apply styles
  25. element.textContent = customText;
  26. element.style.color = "orchid";
  27. element.dataset.processed = "true";
  28.  
  29. // Add hover functionality to show the original text
  30. element.addEventListener("mouseenter", () => {
  31. element.textContent = originalText;
  32. element.style.color = ""; // Reset to original colour
  33. element.style.fontStyle = "";
  34. element.style.fontWeight = "";
  35. });
  36. element.addEventListener("mouseleave", () => {
  37. element.textContent = customText;
  38. element.style.color = "orchid";
  39. });
  40. }
  41.  
  42. // Apply the text replacement to specific elements
  43. function applyReplacements() {
  44. const selectors = [
  45. ".text-sd-hard",
  46. ".text-sd-medium",
  47. ".text-sd-easy",
  48. '[role="cell"] > .text-pink.dark\\:text-dark-pink',
  49. '[role="cell"] > .text-yellow.dark\\:text-dark-yellow',
  50. '[role="cell"] > .text-olive.dark\\:text-dark-olive',
  51. ".text-difficulty-hard",
  52. ".text-difficulty-medium",
  53. ".text-difficulty-easy",
  54. ".text-lc-yellow-60.dark\\:text-dark-lc-yellow-60",
  55. ".text-lc-red-60.dark\\:text-dark-lc-red-60",
  56. ".text-lc-green-60.dark\\:text-dark-lc-green-60",
  57. ".text-yellow",
  58. ".text-pink",
  59. ".text-green",
  60. ".text-olive"
  61. ];
  62.  
  63. const elements = document.querySelectorAll(selectors.join(","));
  64. elements.forEach((element) => replaceText(element));
  65. }
  66.  
  67. // Run the replacement initially
  68. applyReplacements();
  69.  
  70. // Observe changes in the DOM to handle dynamic content
  71. const observer = new MutationObserver((mutations) => {
  72. mutations.forEach((mutation) => {
  73. mutation.addedNodes.forEach((node) => {
  74. if (node.nodeType === Node.ELEMENT_NODE) {
  75. applyReplacements();
  76. }
  77. });
  78. });
  79. });
  80.  
  81. observer.observe(document.body, { childList: true, subtree: true });
  82. })();