Facebook Unsponsored Timeline

Remove sponsored article in timeline.

// ==UserScript==
// @name         Facebook Unsponsored Timeline
// @namespace    https://greasyfork.org/de/users/768305-mk1212
// @version      0.1.1
// @description  Remove sponsored article in timeline.
// @author       mk1212
// @license      GPL-3.0
// @match        https://www.facebook.com/
// @icon         https://www.google.com/s2/favicons?domain=facebook.com
// @grant        none
// ==/UserScript==


(function() {
	var f$ = {
    docLang: document.documentElement.lang,
    infoDiv: document.createElement('div'),
    tempDiv: document.createElement('div'),
    observeElement: null,
    curQuery: null,
    curLang: !1,
    nameAuthor: '',
    selectors: {
        qFeed: 'div[role="feed"]',
        qArticle: 'div[data-pagelet^="FeedUnit_"]',
        qAuthor: 'object[type="nested/pressable"] > a',
        qHref: 'a[href="#"]'
    },
		fbLang: [
				{ country: 'en', sponsored: 'Sponsored' }, // English (UK and US)
				{ country: 'de', sponsored: 'Gesponsert' }, // Deutsch
				{ country: 'nl', sponsored: 'Gesponsord' }, // Nederlands
				{ country: 'da', sponsored: 'Sponsoreret' }, // Dansk
				{ country: 'fr', sponsored: 'Sponsorisé' }, // Français (France)
				{ country: 'es', sponsored: 'Publicidad' }, // Español (España)
				{ country: 'it', sponsored: 'Sponsorizzato' }, // Italiano
				{ country: 'pt', sponsored: 'Patrocinado' } // Português (Portugal and Brasil)
		],
    gm_main: function() {
        new MutationObserver(function() {
            document.querySelectorAll(f$.selectors.qArticle).forEach(function(e) {
                e.hasAttribute('data-status') || (
                	f$.curQuery = e.querySelector(f$.selectors.qAuthor),
                	null !== f$.curQuery && (f$.nameAuthor = f$.curQuery.getAttribute('aria-label'),
                		console.log('Process article: ', f$.nameAuthor),
                		f$.curQuery = e.querySelector(f$.selectors.qHref),
                		null !== f$.curQuery && (f$.tempDiv.innerHTML = f$.curQuery.innerHTML.replace(/<[^>]+\sstyle\b[^>]+>?[^<]/gi, ''),
                			f$.curLang.sponsored == f$.tempDiv.innerText && (
                				e.remove(),
                				console.log('%cRemove sponsored article', 'color: red'),
                				f$.infoDiv.innerHTML = '<h2>Remove sponsor: <i>' + f$.nameAuthor + '</i></h2>',
                				f$.infoDiv.style.display = 'block', setTimeout(function() {
                    		    f$.infoDiv.style.display = 'none';}, 2e3)))),
                e.setAttribute('data-status', 'unsponsored')
                )
            })
        }).observe(f$.observeElement, {
            attributes: !1,
            childList: !0,
            subtree: !0
        })
    },
    gm_info: function() {
        var styles = "left: 50%;top: 90%;position: fixed;transform: translate(-50%, -10%);width: auto;" +
        	"display: none;border: 2px solid red;background: white;padding: 3px 5px;opacity: 0.9;" +
        	"borderRadius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em";
        f$.infoDiv.setAttribute("style", styles);
        document.body.appendChild(f$.infoDiv);
    },
    gm_init: function() {
        for (var e in f$.fbLang)
            if (f$.fbLang[e].country == f$.docLang) {
                f$.curLang = f$.fbLang[e];
                break;
            }
            f$.curLang && (f$.observeElement = document.querySelector(f$.selectors.qFeed),
 	           null !== f$.observeElement && (
 	           	f$.gm_info(),
	           	f$.gm_main()))
    }
};
f$.gm_init();
})();