Advertisement
shelegelah

Untitled

Feb 17th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Remove Subscriber Only Problems From Leetcode
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://leetcode.com/problemset/all/
  8. // @grant none
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12.  
  13. let tableObserver;
  14. const tableSelector = ".table-striped";
  15. const addMutationObserverToDocument = () => {
  16. if(tableObserver){
  17. tableObserver.disconnect()
  18. }
  19. let targetNode = document.querySelector(tableSelector);
  20. let observerOptions = {
  21. childList: true,
  22. subtree: true
  23. }
  24. let callback = (mutationList, observer) => {
  25. mutationList.forEach((mutation) => {
  26. if (mutation.type == 'childList') {
  27. targetNode.querySelectorAll('tr').forEach((row, index) => {
  28. if (row.cells.length>=3 && row.cells[2].querySelectorAll("i[class~='fa-lock']").length) {
  29. try{
  30. row.parentElement.removeChild(row);
  31. }
  32. catch(e){'I am bad';}
  33.  
  34. }
  35. })
  36. }
  37. })
  38. }
  39. tableObserver = new MutationObserver(callback);
  40. tableObserver.observe(targetNode, observerOptions);
  41. }
  42.  
  43. let docObserver = new MutationObserver((mutationList, observer) => {
  44. mutationList.forEach((mutation) => {
  45. if (mutation.type == 'childList') {
  46. if (document.querySelectorAll(tableSelector).length) {
  47. addMutationObserverToDocument();
  48. }
  49. }
  50. })
  51. });
  52.  
  53. docObserver.observe(document, {
  54. childList: true,
  55. subtree: true
  56. });
  57.  
  58. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement