Created
May 25, 2026 04:27
-
-
Save gdw2/5f049da0d885b8ce1b24cbb2a8042876 to your computer and use it in GitHub Desktop.
Mobile Facebook cleaner - removes sponsored posts, reels, People You May Know, and posts from non-followed accounts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Facebook Mobile Cleaner | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.2 | |
| // @description Removes sponsored posts, reels, people you may know, and posts from people you don't follow on mobile Facebook. Inspired by F.B. Purity. | |
| // @run-at document-idle | |
| // @author You | |
| // @match https://m.facebook.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=facebook.com | |
| // @grant none | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict' | |
| function getFeedContainer() { | |
| const root = document.querySelector('#screen-root') | |
| if (!root) return null | |
| return root.querySelector(':scope > div > div') | |
| } | |
| function walkToFeedItem(el) { | |
| const feed = getFeedContainer() | |
| if (!feed) return null | |
| while (el && el.parentElement && el.parentElement !== feed) { | |
| el = el.parentElement | |
| } | |
| return el && el.parentElement === feed ? el : null | |
| } | |
| function hide(item) { | |
| if (!item || item.classList.contains('fbp-hidden')) return | |
| item.classList.add('fbp-hidden') | |
| item.style.setProperty('display', 'none', 'important') | |
| } | |
| function clean() { | |
| const feed = getFeedContainer() | |
| if (!feed) return | |
| feed.querySelectorAll('span').forEach(span => { | |
| if (span.textContent.trimStart().startsWith('Sponsored')) { | |
| hide(walkToFeedItem(span)) | |
| } | |
| }) | |
| feed.querySelectorAll('h2').forEach(h2 => { | |
| if (h2.textContent.trim() === 'Reels') { | |
| hide(walkToFeedItem(h2)) | |
| } | |
| }) | |
| ;['People You May Know', 'People you may know'].forEach(text => { | |
| feed.querySelectorAll('span, div, h3').forEach(el => { | |
| if (el.textContent.trim() === text) { | |
| hide(walkToFeedItem(el)) | |
| } | |
| }) | |
| }) | |
| feed.querySelectorAll('button, [role="button"], a').forEach(el => { | |
| const t = el.textContent.trim() | |
| if (t === 'Follow' || t === 'Join') { | |
| hide(walkToFeedItem(el)) | |
| } | |
| }) | |
| } | |
| window.setTimeout(clean, 1000) | |
| let timer | |
| new MutationObserver(() => { | |
| clearTimeout(timer) | |
| timer = setTimeout(clean, 200) | |
| }).observe(document.body, { childList: true, subtree: true }) | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment