Created
February 17, 2020 17:47
-
-
Save elsassph/80668c74ae02c48b987c345ee269c202 to your computer and use it in GitHub Desktop.
Hide Facebook sponsored stories
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 No sponsor | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Hide Facebook sponsored stories | |
// @author You | |
// @match https://www.facebook.com/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function getLabel(elem) { | |
// get visible letters from the subtitle | |
return Array.from(elem.querySelectorAll("[data-content]")).filter(e => e.offsetWidth > 0).map(e => e.dataset.content).join(""); | |
} | |
function getSubtitle(elem) { | |
return elem.querySelector("[data-testid=fb-test-id-feed-sub-tilte]"); | |
} | |
function getTitle(elem) { | |
const e = elem.querySelector("h5"); | |
return e ? e.innerText : ""; | |
} | |
function getStories() { | |
return document.querySelectorAll("[data-testid=fbfeed_story]"); | |
} | |
function hideSponsored() { | |
const stories = getStories(); | |
stories.forEach(story => { | |
if (story.__checked__) return; | |
const sub = getSubtitle(story); | |
if (sub) { | |
const title = getTitle(story); | |
const label = getLabel(sub); | |
if (label == "") return; | |
console.log('STORY', title, label); | |
if (label.startsWith("Sponsor")) { | |
story.style.display = 'none'; | |
} | |
} | |
story.__checked__ = true; | |
}); | |
} | |
setInterval(() => hideSponsored(), 2000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment