NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Facebook Blocker // @namespace facebookblocker // @version 0.1 // @author Tophness // @match http://www.facebook.com/* // @match https://www.facebook.com/* // @description True Facebook user blocking (including groups) // @require https://greasyfork.org/scripts/6217-gm-config/code/GM_config.js?version=23537 // @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js // @grant GM_getValue // @grant GM_setValue // @grant GM_log // @grant GM_registerMenuCommand // @run-at document-idle // ==/UserScript== var streamSelector = 'div[id^="stream_pagelet"]'; var storiesSelector = 'div[id^="topnews_main_stream"]'; var storySelector = 'div[id^="hyperfeed_story_id"]'; GM_config.init('Facebook Blocker Options', { 'filters': { 'label': 'Names to Block (Separate by commars)', 'type': 'text', 'default': '' } }); function opengmcf() { GM_config.open(); } GM_registerMenuCommand('Facebook Blocker Options', opengmcf); var names = GM_config.get('filters'); if (names.length != 0) { names = names.split(','); } var mutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; function remove(story) { if (!story) { return; } story.remove(); } function block(story) { if (!story) { return; } if (story.getElementsByTagName('a').length) { var links = story.getElementsByTagName('a'); for (var i = 0; i < links.length; i++) { var user = links[i].innerHTML; for (var i2 = 0; i2 < names.length; i2++) { if (user.indexOf(names[i2]) != - 1) { remove(story); break; } } } } } function process() { // Locate the stream every iteration to allow for FB SPA navigation which // replaces the stream element var stream = document.querySelector(streamSelector); if (!stream) { return; } var stories = stream.querySelectorAll(storiesSelector); if (!stories.length) { return; } for (var i = 0; i < stories.length; i++) { var story = stories[i].querySelectorAll(storySelector); if (!story.length) { return; } for (var i2 = 0; i2 < story.length; i2++) { block(story[i2]); } } } var observer = new mutationObserver(process); observer.observe(document.querySelector('body'), { 'childList': true, 'subtree': true });