Greasy Fork is available in English.

Facebook Marketplace - Sponsored products remover

Removes the suggested products from Facebook Marketplace.

// ==UserScript==
// @name        Facebook Marketplace - Sponsored products remover
// @namespace   https://greasyfork.org/en/users/2755-robotoilinc
// @author      RobotOilInc
// @version     0.1.2
// @license     MIT
// @description Removes the suggested products from Facebook Marketplace.
// @match       http*://www.facebook.com/*
// @icon        https://i.imgur.com/ECWTnDS.png
// @run-at      document-end
// ==/UserScript==

const MARKET_PLACE_REGEX = /(?:https?:\/\/)?(?:www\.)?(mbasic.facebook|m\.facebook|facebook|fb)\.(com|me)\/marketplace/ig

new MutationObserver(function(mutationList, observer) {
    // Ensure we are on the marketplace side of Facebook
    if (!window.location.href.match(MARKET_PLACE_REGEX)) {
        return;
    }

    // Hide "Sponored" results
    document.querySelectorAll('div.xjkvuk6.x1iorvi4.x1uepa24.x291uyu.xnpuxes.x150jy0e.x1e558r4.xs83m0k.x1iyjqo2.xdt5ytf.x1r8uery.x78zum5.x9f619 > span').forEach(function(element) {
        const parent = element.parentElement;
        if(!parent) {
            return;
        }

        parent.style.display = 'none';
        console.log("Hidden sponsored item", parent);

        // Grab the row that contains "Sponsored" + category name
        const parentBar = element.closest('.xkrivgy.x1gryazu.x1n2onr6')
        if(!parentBar) {
            return;
        }

        // Remove the actual "Sponsored" part
        const sponsoredBarItem = parentBar.querySelector('.x1pha0wt.x78zum5.x1r8uery.xdt5ytf.x1iyjqo2.x1qughib')
        if(!sponsoredBarItem) {
            return;
        }

        sponsoredBarItem.style.display = 'none';
        console.log("Hidden sponsored bar", sponsoredBarItem);
    });
}).observe(document.body, { childList: true, subtree: true });