Facebook Marketplace: Hide Unwanted Categories

Removes items from the categories listed below. Edit the list to your tastes, but back it up, as it will get overwritten when I next update

  1. // ==UserScript==
  2. // @name Facebook Marketplace: Hide Unwanted Categories
  3. // @description Removes items from the categories listed below. Edit the list to your tastes, but back it up, as it will get overwritten when I next update
  4. // @match https://www.facebook.com/*
  5. // @version 0.9
  6. // @author mica
  7. // @namespace greasyfork.org/users/12559
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. const list = [
  12. 'Auto',
  13. 'Books',
  14. 'Explore',
  15. 'Jewelry',
  16. 'Kids',
  17. 'Pet',
  18. 'Phones',
  19. 'Property',
  20. 'Women'
  21. ];
  22.  
  23. const observer = new MutationObserver(() => {
  24. if (location.pathname.includes('/marketplace') && !location.pathname.match(/category|propertyrentals|profile|you|notifications|inbox/g)) {
  25. document.querySelectorAll('div[role="main"] h2>span:not(.categoryChecked)').forEach(element => {
  26. if (list.some(item => element.innerText.toLowerCase().match(item.toLowerCase()))) {
  27. element.closest('div[class=""]').remove();
  28. } else {
  29. element.classList.add('categoryChecked');
  30. }
  31. });
  32. }
  33. });
  34. observer.observe(document.body, {
  35. childList: true,
  36. subtree: true
  37. });