Created
March 2, 2025 17:36
-
-
Save nqthqn/de146685b16365cf0392f5eaef2ec456 to your computer and use it in GitHub Desktop.
Facebook Feed Blocker
This file contains 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 Feed Blocker | |
// @namespace https://github.com/yourusername | |
// @version 1.0 | |
// @description Hides the Facebook news feed to reduce distractions | |
// @author You | |
// @match https://*.facebook.com/* | |
// @grant none | |
// @updateURL https://gist.github.com/raw/YOUR_GIST_ID/facebook-feed-blocker.user.js | |
// @downloadURL https://gist.github.com/raw/YOUR_GIST_ID/facebook-feed-blocker.user.js | |
// @run-at document-idle | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// CSS to hide the feed | |
const style = document.createElement('style'); | |
style.textContent = ` | |
/* Hide the main feed */ | |
div[role="feed"], | |
div[data-pagelet="FeedUnit"], | |
div[data-pagelet="Feed"], | |
div[data-pagelet="MainFeed"] { | |
display: none !important; | |
} | |
/* Replace with motivational message */ | |
div[role="main"] > div > div > div:nth-child(3) > div:before { | |
content: "Facebook feed hidden. Focus on what matters."; | |
display: block; | |
font-size: 24px; | |
font-weight: bold; | |
color: #1877f2; | |
text-align: center; | |
padding: 100px 20px; | |
background: #f0f2f5; | |
border-radius: 8px; | |
margin: 20px 0; | |
} | |
`; | |
document.head.appendChild(style); | |
// Periodically check and hide feed elements that may load dynamically | |
const observer = new MutationObserver(function() { | |
hideFeed(); | |
}); | |
// Start observing the document body for changes | |
observer.observe(document.body, { childList: true, subtree: true }); | |
// Function to hide feed elements | |
function hideFeed() { | |
const feedSelectors = [ | |
'div[role="feed"]', | |
'div[data-pagelet="FeedUnit"]', | |
'div[data-pagelet="Feed"]', | |
'div[data-pagelet="MainFeed"]' | |
]; | |
feedSelectors.forEach(selector => { | |
const elements = document.querySelectorAll(selector); | |
elements.forEach(el => { | |
el.style.display = 'none'; | |
}); | |
}); | |
} | |
// Initial hiding | |
hideFeed(); | |
// Log to console | |
console.log('Facebook Feed Blocker active'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment