-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfacebook.js
More file actions
61 lines (51 loc) · 1.96 KB
/
Copy pathfacebook.js
File metadata and controls
61 lines (51 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==UserScript==
// @name Facebook Feed Blocker (Main Role)
// @namespace http://tampermonkey.net/
// @version 3.0
// @description Blocks the main content div on the homepage, allows Messenger/Marketplace.
// @author User
// @match https://*.facebook.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// 1. Inject CSS that hides div[role="main"] ONLY when body has the class 'homepage-blocked'
const style = document.createElement('style');
style.textContent = `
body.homepage-blocked div[role="main"] {
display: none !important;
visibility: hidden !important;
}
`;
document.head.appendChild(style);
// 2. Logic to determine if we are on the specific feed page
function handleBlocking() {
const path = window.location.pathname;
// Exact match for root "/" or "/home.php"
// This ensures we don't block /marketplace, /messages, /groups, etc.
const isHomePage = path === '/' || path === '/home.php';
if (isHomePage) {
document.body.classList.add('homepage-blocked');
} else {
document.body.classList.remove('homepage-blocked');
}
}
// 3. Navigation Listeners (Facebook is a Single Page App)
// Check immediately
new MutationObserver(() => {
if (document.body) handleBlocking();
}).observe(document.documentElement, { childList: true, subtree: true });
// Hook into browser history for URL changes
const originalPushState = history.pushState;
history.pushState = function() {
originalPushState.apply(this, arguments);
handleBlocking();
};
const originalReplaceState = history.replaceState;
history.replaceState = function() {
originalReplaceState.apply(this, arguments);
handleBlocking();
};
window.addEventListener('popstate', handleBlocking);
})();