Greasy Fork is available in English.

cleanLeetcode

clean Leetcode

  1. // ==UserScript==
  2. // @name cleanLeetcode
  3. // @namespace mailto: fish404hsif@gmail.com
  4. // @version 0.1.0
  5. // @description clean Leetcode
  6. // @author fish-404
  7. // @run-at document-end
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=
  9. // @match https://leetcode.cn/problemset/*
  10. // @license MIT
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. cleanLeetCode();
  18. myMutation();
  19. })();
  20.  
  21. function cleanLeetCode() {
  22. hideNav();
  23. hideFooter();
  24. hideRightBlock();
  25. hideRightCornerIcon();
  26. stickyTopBottom();
  27. widenMain();
  28. hideTags();
  29. }
  30.  
  31. function hideElement(element) {
  32. element.style.display = "none";
  33. }
  34.  
  35. function hideSelf(selfSelector) {
  36. hideElement(document.querySelector(selfSelector));
  37. }
  38.  
  39. function hideParent(childSelector) {
  40. hideElement(document.querySelector(childSelector).parentElement);
  41. }
  42.  
  43. function hideGroup(groupSelector) {
  44. document.querySelectorAll(groupSelector).forEach((e) => {
  45. hideElement(e);
  46. });
  47. }
  48.  
  49. function hideNav() {
  50. hideSelf("nav");
  51. }
  52.  
  53. function hideFooter() {
  54. hideSelf("footer");
  55. }
  56.  
  57. function hideRightBlock() {
  58. hideSelf("#__next div.grid div.col-span-4:nth-child(2)");
  59. }
  60.  
  61. function hideRightCornerIcon() {
  62. hideParent("a[aria-label='feedback']");
  63. }
  64.  
  65. function hideCol() {
  66. hideGroup("div.mx-2:nth-child(6)");
  67. hideGroup("div.mx-2:nth-child(3)");
  68. }
  69.  
  70. function stickyTopBottom() {
  71. let wrapper = document.querySelector('div.grid').firstChild.lastChild;
  72. wrapper.firstChild.setAttribute('style', 'position: sticky; top: 0; background: black; padding: 5px;');
  73. wrapper.lastChild.setAttribute('style', 'position: sticky; bottom: 0; background: black; padding: 5px;');
  74. }
  75.  
  76. function widenMain() {
  77. document.querySelector('div.grid').removeAttribute('class');
  78. }
  79.  
  80. function hideTags() {
  81. hideGroup("div.z-base div.relative.flex");
  82. }
  83.  
  84. function myMutation() {
  85. let problemsNode, observer;
  86.  
  87. const config = {
  88. subtree: true
  89. , childList: true
  90. };
  91.  
  92.  
  93. problemsNode = document.querySelector("div[role='table']");
  94. observer = new MutationObserver(hidePlusProblemsWithoutTag);
  95. observer.observe(problemsNode, config);
  96. }
  97.  
  98. function hidePlusProblemsWithoutTag(mutationList, observer) {
  99. let preTargetRow;
  100. mutationList.forEach((mutation) => {
  101. let target;
  102. if (mutation.addedNodes.length > 0) {
  103. target = mutation.addedNodes[0];
  104. }
  105. else {
  106. target = mutation.target;
  107. }
  108. let curTargetRow = target.closest("div[role='row']");
  109. if (curTargetRow !== null && curTargetRow !== preTargetRow) {
  110. preTargetRow = curTargetRow;
  111. let searchPlus = curTargetRow.querySelector("svg.text-brand-orange");
  112. changeElementDisplay(curTargetRow, searchPlus === null);
  113. hideCol();
  114. }
  115. });
  116. }
  117.  
  118. function changeElementDisplay(element, displayOrNot) {
  119. const SHOW = "flex", HIDE = "none";
  120. element.style.display = displayOrNot ? SHOW : HIDE;
  121. }