Skip to content

Instantly share code, notes, and snippets.

@burdiuz
Created October 28, 2016 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burdiuz/b0387076cbed0fd2e6914b2c943ae029 to your computer and use it in GitHub Desktop.
Save burdiuz/b0387076cbed0fd2e6914b2c943ae029 to your computer and use it in GitHub Desktop.
Userscript Chrome/Tampermonkey to hide scrolled out stories from Facebook feed.

#FB stop news feed madness I Saw This!

Userscript that will hide stories from your Facebook feed when you scrolled them out. But will keep stories that you liked. There are two version of the script:

  • fb-isawthis.tm.user.js will hide stories from news feed temporarily and they will be restored after page was reloaded.
  • fb-isawthis.perm.tm.user.js will hide stories permanently via "Hide post" dialog. Liked stories or stories that cannot be hidden permanently will be hidden temporary and restored after page reload.

How To

  1. Install Tampermonkey
  2. Download userscript to hide temporarily or permanently
  3. Reload Facebook news feed if it was opened
  4. Scroll to death
// ==UserScript==
// @name FB I Saw This!
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Permanently hide story from FB news feed when its scrolled out.
// @author a_[w]
// @match https://www.facebook.com/
// @grant none
// ==/UserScript==
(function() {
'use strict';
var iid, timeout = 1000,
spaceToСhangeMind = 500,
find = () => {
let content = document.getElementById('contentArea');
let stories = Array.prototype.filter.call(content.querySelectorAll('div.userContentWrapper'), (story) => {
let rect = story.getBoundingClientRect();
if (story.dataset.ISawThis) {
return rect.bottom + spaceToСhangeMind < 0;
} else if (rect.top > -100 && rect.top < window.innerHeight) story.dataset.ISawThis = true;
return false;
});
return stories;
},
query = () => {
let list = find(),
next = () => {
if (list.length) {
//console.log('next: ', list.length - 1);
click();
hide(list.shift(), next);
}
};
//console.log('list of', list.length);
next();
},
scrollMagicNum = 60,
click = () => {
window.document.body.click && window.document.body.click();
},
//bodyHeight = () => document.body.getBoundingClientRect().height,
scroll = (story, hideStory) => {
let height = story.getBoundingClientRect().height;
hideStory && hideStory();
window.scrollBy(0, -height);
story.parentNode && story.parentNode.removeChild(story);
},
hide = (story, next) => {
let context;
let parent = story.parentNode;
if (story.querySelector('div.userContentWrapper a.UFILikeLink[aria-pressed="true"]')) {
scroll(parent);
} else context = story.querySelector('div.uiPopover a');
if (context) {
context.click();
var time = Date.now(), iid = setInterval(() => {
let result = false;
document.querySelectorAll('div.uiLayer:not(.hidden_elem) .uiContextualLayer').forEach((layer) => {
let hideLink = layer.querySelector('li.__MenuItem a[ajaxify^="/ajax/feed/filter_action/dialog_direct_action"]');
if (hideLink) {
/* 1 * /
let height = bodyHeight();
hideLink.click();
window.scrollBy(0, bodyHeight() - height + scrollMagicNum);
/* 2 * /
story.parentNode.style.minHeight = story.getBoundingClientRect().height + 'px';
hideLink.click();
/* 3 */
scroll(parent, () => hideLink.click());
//*/
result = true;
}
});
//console.log('interval');
if (result || Date.now() - time > 320) {
//console.log(result ? ' - story hidden' : ' - context link was not found');
scroll(parent);
clearInterval(iid);
next();
}
}, 50);
} else {
next();
}
},
stop = () => {
if (iid) {
clearTimeout(iid);
}
iid = 0;
},
start = () => {
stop();
iid = setTimeout(query, timeout);
};
window.addEventListener('scroll', () => {
//console.log(' - scroll');
start();
});
document.addEventListener('load', (event) => {
setTimeout(hide, 1000);
});
})();
// ==UserScript==
// @name FB I Saw This!
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Hide story from FB news feed when its scrolled out, it will return on page reload.
// @author a_[w]
// @match https://www.facebook.com/
// @grant none
// ==/UserScript==
(function() {
'use strict';
var iid,
timeout = 1000,
spaceToСhangeMind = 500,
scroll = (story, hideStory) => {
let height = story.getBoundingClientRect().height;
hideStory && hideStory();
window.scrollBy(0, -height);
story.parentNode && story.parentNode.removeChild(story);
},
hide = () => {
let content = document.getElementById('contentArea');
content.querySelectorAll('div[id^="substream_"]').forEach((story) => {
let rect = story.getBoundingClientRect();
if (story.dataset.ISawThis) {
if (rect.bottom + spaceToСhangeMind < 0) {
scroll(story);
}
} else if (rect.top > -100 && rect.top < window.innerHeight) story.dataset.ISawThis = true;
});
},
stop = () => {
if (iid) {
clearTimeout(iid);
}
iid = 0;
},
start = () => {
stop();
iid = setTimeout(hide, timeout);
};
window.addEventListener('scroll', () => {
start();
});
document.addEventListener('load', (event) => {
setTimeout(hide, 1000);
});
})();
// find open context menu
document.querySelector('div.uiLayer:not(.hidden_elem) .uiContextualLayer')
// find hide story link
document.querySelector('div.uiContextualLayer li.__MenuItem a[ajaxify^="/ajax/feed/filter_action/dialog_direct_action"]').click()
// find available stories
document.querySelectorAll('div.userContentWrapper')
// if story liked
document.querySelectorAll('div.userContentWrapper a.UFILikeLink[aria-pressed="true"]')
// or
document.querySelectorAll('div.userContentWrapper a.UFILikeLink.UFILinkBright')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment