Remove "Ship to you" FB marketplace listings

Add button which if cliked removes all visible "Ship to you" FB marketplace listings

  1. // ==UserScript==
  2. // @name Remove "Ship to you" FB marketplace listings
  3. // @author Rolandas Valantinas
  4. // @description Add button which if cliked removes all visible "Ship to you" FB marketplace listings
  5. // @include *facebook.com/marketplace*
  6. // @namespace https://greasyfork.org/users/157178
  7. // @require https://code.jquery.com/jquery-3.2.1.min.js
  8. // @supportURL https://github.com/rolandas-valantinas/gists/issues
  9. // @version 1.0.1
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. var metricsButton = `<input type="button" id="filter-ship-to-you" value="Filter">`;
  14. setTimeout(addButton, 2000);
  15.  
  16. function hideListings() {
  17. var shipsToYou = $("a:contains('Ships to you')");
  18.  
  19. for (var i = 0; i < shipsToYou.length; i++) {
  20. console.log(shipsToYou[i].closest( "span" ).closest( "div.lcfup58g" ));
  21. shipsToYou[i].closest( "span" ).closest( "div.lcfup58g" ).remove();
  22. }
  23. }
  24.  
  25. function addButton() {
  26. console.log($("a:contains('Marketplace')"));
  27. $("a:contains('Marketplace')").closest( "span" ).append(metricsButton);
  28. $('#filter-ship-to-you').click(hideListings);
  29. }
  30. })();