hideLeetCodePlus

Hide Leetcode Plus Problems

  1. // ==UserScript==
  2. // @name hideLeetCodePlus
  3. // @name:zh-CN 隐藏力扣Plus题目
  4. // @namespace mailto: fish404hsif@gmail.com
  5. // @version 0.4.2
  6. // @license MIT
  7. // @description Hide Leetcode Plus Problems
  8. // @description:zh-CN 隐藏 Leetcode Plus 题目
  9. // @author fish-404
  10. // @match https://leetcode.cn/problemset/*
  11. // @match https://leetcode.cn/tag/*
  12. // @match https://leetcode.cn/problem-list/*
  13. // @match https://leetcode.com/problemset/*
  14. // @match https://leetcode.com/problem-list/*
  15. // @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.cn
  16. // @grant none
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21. const url = window.location.href;
  22. let problemsNode, tagFlag, observer;
  23.  
  24. const config = {
  25. subtree: true
  26. , childList: true
  27. };
  28.  
  29. if (url.includes("tag")) { // problemsets with tags
  30. console.log("tag: true");
  31. const container = document.querySelector("div#lc-content");
  32. observer = new MutationObserver(()=>{
  33. let tbody = document.querySelector("tbody.ant-table-tbody");
  34. if (tbody) {
  35. const innerObserver = new MutationObserver(hidePlusProblemsWithTag);
  36. innerObserver.observe(container, config);
  37. }
  38. });
  39. observer.observe(container, config);
  40. }
  41. else {
  42. problemsNode = document.querySelector("div[role='table']");
  43. observer = new MutationObserver(hidePlusProblemsWithoutTag);
  44. observer.observe(problemsNode, config);
  45. }
  46. })();
  47.  
  48. function hidePlusProblemsWithoutTag(mutationList, observer) {
  49. let preTargetRow;
  50. mutationList.forEach((mutation) => {
  51. let target;
  52. if (mutation.addedNodes.length > 0) {
  53. target = mutation.addedNodes[0];
  54. }
  55. else {
  56. target = mutation.target;
  57. }
  58. let curTargetRow = target.closest("div[role='row']");
  59. if (curTargetRow !== null && curTargetRow !== preTargetRow) {
  60. preTargetRow = curTargetRow;
  61. let searchPlus = curTargetRow.querySelector("svg.text-brand-orange");
  62. changeElementDisplay(curTargetRow, searchPlus === null);
  63. }
  64. });
  65. }
  66.  
  67. function hidePlusProblemsWithTag(mutationList) {
  68. mutationList.forEach((mutation) => {
  69. console.log(mutation);
  70. if (mutation.addedNodes.length > 0) {
  71. let curTargetRow = mutation.addedNodes[0];
  72. let searchPlus = curTargetRow.querySelector("img[alt='plus']");
  73. console.log(searchPlus);
  74. if (searchPlus) {
  75. curTargetRow.style.display = "none";
  76. }
  77. }
  78. });
  79. }
  80.  
  81. function changeElementDisplay(element, displayOrNot) {
  82. const SHOW = "flex", HIDE = "none";
  83. element.style.display = displayOrNot ? SHOW : HIDE;
  84. }