Facebook Filter Fork

Minimizes all posts your friends didn't post (friend liked, friend commented, friend attends...)

  1. // ==UserScript==
  2. // @name Facebook Filter Fork
  3. // @namespace thetom.facebook
  4. // @version 1.7.7b
  5. // @description Minimizes all posts your friends didn't post (friend liked, friend commented, friend attends...)
  6. // @author TheTomCZ <hejl.tomas@gmail.com> (Original Author)
  7. // @author <nazgand@gmail.com> (Maintainer of this fork)
  8. // @match https://www.facebook.com/*
  9. // @require https://code.jquery.com/jquery-2.1.4.min.js
  10. // @grant none
  11. // @homepage https://greatest.deepsurf.us/en/scripts/27554-facebook-filter-fork
  12. // ==/UserScript==
  13.  
  14. $(function() {
  15. 'use strict';
  16. console.log('FFF test');
  17. const timesToFilter=5, timeoutBetweenFilters=250;
  18. const keywords = [
  19. // comment out anything you want to not be filtered
  20. " was tagged in ",
  21. " was mentioned in ",
  22. " is with ",
  23. " followed ",
  24. " likes ",
  25. " liked ",
  26. " replied to a ",
  27. " commented on ",
  28. " now friends",
  29. " is interested in an event",
  30. " going to an event",
  31. " others wrote on ",
  32. "'s Birthday",
  33. " reacted to this",
  34.  
  35. //*Change the '//' to '/' if you want to not filter Czech
  36. " se líbí ",
  37. " se líbí uživateli ",
  38. " tady odpověděl",
  39. " okomentovali uživatelé",
  40. " okomentovali příspěvek ",
  41. " to okomentoval",
  42. " is now friends with ",
  43. " má zájem o událost",
  44. " má narozeniny",
  45. " na to zareagoval(a)",
  46. " se zúčastní události",//*/
  47. ];
  48. const badHtml = [
  49. //these will have an unhide option
  50. "Trump",
  51. "Obama",
  52. "Biden",
  53. "Clinton",
  54. "Sanders",
  55. ];
  56. const adHtml = [
  57. //these will not have an unhide option
  58. ">Suggested Post</span>",
  59. ">Suggested Page</div>",
  60. ">People you may know</span>",
  61. ];
  62. //customize variables above
  63.  
  64. prepare();
  65. filterAll();
  66. $(document).on("scroll",filterAll);
  67.  
  68. function prepare(){
  69. String.prototype.contains = function(it) { return this.indexOf(it) != -1; };
  70. /*jshint multistr: true */
  71. $("head").append("\
  72. <style>\
  73. .filteredOut .userContentWrapper > div:first-child > .userContent + div, .filteredOut ul{ \
  74. display: none!important; \
  75. } \
  76. .filteredOut { \
  77. padding: 0px!important; \
  78. margin: 3px 0!important; \
  79. opacity: 0.7; \
  80. } \
  81. .filteredOut h5 {\
  82. font-size: 12px!important; \
  83. margin-top: -2px!important; \
  84. padding: 3px!important; \
  85. }\
  86. .filteredOut .commentableItem, .filteredOut img, .filteredOut .userContentWrapper form, .filteredOut h5 + div{\
  87. display: none!important; \
  88. }\
  89. .filteredOut .fbUserContent > div, .filteredOut .fbUserContent button{ \
  90. display: none; \
  91. } \
  92. .filteredOut ._1dwg{\
  93. display: block!important;\
  94. }\
  95. .filteredOut .userContent+div{ \
  96. display: none!important; \
  97. } \
  98. .filteredOut .stat_elem, .filteredOut .userContent, .filteredOut.ad h5 span{\
  99. display: none!important;\
  100. }\
  101. .filteredOut *{\
  102. height: auto!important;\
  103. padding: 0!important;\
  104. margin: 0!important;\
  105. background-color: #e9ebee; \
  106. } \
  107. .fbFilterBtn {\
  108. position: absolute;\
  109. right: 35px;\
  110. top: 5px;\
  111. } \
  112. .filteredOut .fbFilterBtn {\
  113. right: 10px; \
  114. top: 1px; \
  115. } \
  116. </style>"
  117. );
  118. }
  119.  
  120. function minimize($elem, extraClass){
  121. var id = $elem.attr("id");
  122. if(extraClass){
  123. $elem.addClass(extraClass);
  124. }
  125. $elem.find("h5").append(" <a id='showStory_"+id+"' class='fbFilterBtn'>unhide</a><a id='rehideStory_"+id+"' style='display:none' class='fbFilterBtn'>rehide</a>");
  126. hideStory(id);
  127. $("#showStory_"+id).click(function(){showStory(id);});
  128. $("#rehideStory_"+id).click(function(){hideStory(id);});
  129. }
  130.  
  131. function showStory(id){
  132. $("#rehideStory_"+id).show();
  133. $("#showStory_"+id).hide();
  134. $("#"+id).removeClass("filteredOut");
  135. }
  136.  
  137. function hideStory(id){
  138. $("#rehideStory_"+id).hide();
  139. $("#showStory_"+id).show();
  140. $("#"+id).addClass("filteredOut").addClass("fbSpam");
  141. }
  142.  
  143. function filter(index,elem){
  144. if(!$(elem).attr){
  145. return;
  146. }
  147. var $elem = $(elem);
  148. if($elem.hasClass("fbFiltered") || !$elem.attr("id")){
  149. return;
  150. }
  151. if($elem.attr("id").substring(0,16)!=="hyperfeed_story_"){
  152. return;
  153. }
  154. setTimeout(function(){_filter($elem,timesToFilter);},0);
  155. }
  156. function _filter($elem,times){
  157. if($elem.hasClass("fbSpam")){
  158. return;
  159. }
  160. $elem.addClass("fbFiltered");
  161.  
  162. var title = $elem.find("h5").text();
  163. for(var i in keywords){
  164. if(title.contains(keywords[i])){
  165. minimize($elem);
  166. return;
  167. }
  168. }
  169. /*
  170. title = $elem.find("div._5g-l").text();
  171. for(i in keywords){
  172. if(title.contains(keywords[i])){
  173. minimize($elem);
  174. return;
  175. }
  176. }//*/
  177.  
  178. const elemInnerHTML=$elem.context.innerHTML;
  179. for(var j in badHtml){
  180. if(elemInnerHTML.indexOf(badHtml[j])>-1){
  181. minimize($elem);
  182. return;
  183. }
  184. }
  185. for(var k in adHtml){
  186. if(elemInnerHTML.indexOf(adHtml[k])>-1){
  187. minimize($elem, "ad");
  188. return;
  189. }
  190. }
  191. if(times>1){
  192. setTimeout(function(){_filter($elem,times-1);},timeoutBetweenFilters);
  193. }
  194. }
  195. function filterAll(){
  196. setTimeout(_filterAll,300);
  197. }
  198. function _filterAll(){
  199. $("[data-testid='fbfeed_story']").map(filter);
  200. }
  201. });