Last active
June 29, 2024 08:22
-
-
Save arafathusayn/2fe13bf471a639650ccec2cf2f8a8845 to your computer and use it in GitHub Desktop.
Remove "Reels and short videos" from Facebook News Feed with less than 35 lines of JavaScript code. It works both on Desktop and Mobile web version of Facebook.
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
chrome ??= browser; | |
function removeReels(node) { | |
if (!node) return; | |
const bannedInnerTexts = ["Reels and short videos", "Reels"]; | |
const text = node.querySelector?.(`div > span[dir="auto"]`)?.innerText ?? ""; | |
const matchedOnDesktop = bannedInnerTexts.find((t) => t === text); | |
const matchedOnMobile = bannedInnerTexts.includes( | |
node.querySelector("div > span")?.innerText, | |
); | |
if (matchedOnDesktop) { | |
const child = node.querySelector("div"); | |
child.style.display = "none"; | |
} else if (matchedOnMobile) { | |
node.style.display = "none"; | |
} | |
} | |
function mutationCallback(mutations) { | |
for (const mutation of mutations) { | |
for (const node of mutation.addedNodes) { | |
removeReels(node); | |
[100, 250, 500, 750, 1000, 1500].forEach((ms) => | |
setTimeout(() => removeReels(node), ms), | |
); | |
} | |
} | |
} | |
{ | |
const observer = new MutationObserver(mutationCallback); | |
window.addEventListener("load", () => { | |
observer.observe(document.body, { | |
subtree: true, | |
childList: true, | |
attributes: true, | |
}); | |
}); | |
} |
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
{ | |
"manifest_version": 3, | |
"name": "My Social Media Extension", | |
"description": "A helpful extension to enhance your social media experience", | |
"version": "1.0.0", | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"https://www.facebook.com/*", | |
"https://web.facebook.com/*", | |
"https://m.facebook.com/*" | |
], | |
"js": ["content_script.js"], | |
"run_at": "document_start" | |
}, | |
{ | |
"matches": [ | |
"https://www.facebook.com/*", | |
"https://web.facebook.com/*", | |
"https://m.facebook.com/*" | |
], | |
"js": ["content_script.js"], | |
"run_at": "document_idle" | |
} | |
], | |
"permissions": ["tabs", "activeTab", "storage", "scripting"], | |
"icons": { | |
"128": "icon128.png" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment