Skip to content

Instantly share code, notes, and snippets.

@Hexalyse
Forked from zoran15/facebook-ticker.js
Created March 24, 2017 12:37
Show Gist options
  • Save Hexalyse/95a38e5a850c426ea2eb87681fe27127 to your computer and use it in GitHub Desktop.
Save Hexalyse/95a38e5a850c426ea2eb87681fe27127 to your computer and use it in GitHub Desktop.
Filter Facebook ticker stories with a RegEx
(function() {
var filterName = new RegExp(prompt("Insert the regex"), 'i');
if (!filterName) {
return alert('Invalid regex');
}
var MAX_ITERATIONS = 500;
var $profileNode = document.querySelector('[data-testid="blue_bar_profile_link"] > span');
var yourName = $profileNode.innerText;
var $ts = document.querySelector('.ticker_stream');
var $tsw = $ts.parentNode.parentNode.parentNode;
var i = 0;
function hideUselessStories() {
var els = [].slice.call( document.querySelectorAll('.fbFeedTickerStory') );
els.forEach(function(e) {
try {
var name = e.querySelector('.tickerFeedMessage .fwb').innerText;
if (filterName.test(name)) e.className += ' fbFeedTickerStoryShow';
} catch (ex) {
console.error(ex);
}
});
var st = document.createElement('style');
st.innerHTML = '.fbFeedTickerStory { display: none !important; } .fbFeedTickerStory.fbFeedTickerStoryShow { display: block !important; }';
document.body.appendChild(st);
}
function scrollTicker() {
$profileNode.innerText = yourName + ' (' + Math.floor( 100 * i / MAX_ITERATIONS ) + '%)';
if (i++ > MAX_ITERATIONS) {
$profileNode.innerText = yourName;
return hideUselessStories();
}
$tsw.scrollTop = $ts.clientHeight;
setTimeout(scrollTicker, 250);
}
scrollTicker();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment