Facebook Filter

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

  1. // ==UserScript==
  2. // @name Facebook Filter
  3. // @namespace thetom.facebook
  4. // @version 1.7.8
  5. // @description Minimizes all posts your friends didn't post (friend liked, friend commented, friend attends...)
  6. // @author TheTomCZ <hejl.tomas@gmail.com>
  7. // @match https://www.facebook.com/*
  8. // @require https://code.jquery.com/jquery-2.1.4.min.js
  9. // @grant none
  10. // @homepage https://greatest.deepsurf.us/en/scripts/16232-facebook-filter
  11. // ==/UserScript==
  12.  
  13. $(function() {
  14. 'use strict';
  15. console.log('test');
  16. var keywords = [
  17. " likes ",
  18. " liked ",
  19. " replied to a ",
  20. " commented on ",
  21. " is now friends with ",
  22. " is interested in an event",
  23. " going to an event",
  24. " others wrote on ",
  25. "'s Birthday",
  26. " reacted to this",
  27.  
  28. " se líbí ",
  29. " se líbí uživateli ",
  30. " tady odpověděl",
  31. " okomentovali uživatelé",
  32. " okomentovali příspěvek ",
  33. " to okomentoval",
  34. " is now friends with ",
  35. " má zájem o událost",
  36. " má narozeniny",
  37. " na to zareagoval(a)",
  38. " se zúčastní události",
  39. ];
  40.  
  41. prepare();
  42. filterAll();
  43. $(document).on("scroll",filterAll);
  44.  
  45. function prepare(){
  46. String.prototype.contains = function(it) { return this.indexOf(it) != -1; };
  47. /*jshint multistr: true */
  48. $("head").append("\
  49. <style>\
  50. .filteredOut .userContentWrapper > div:first-child > .userContent + div, .filteredOut ul{ \
  51. display: none!important; \
  52. } \
  53. .filteredOut { \
  54. padding: 0px!important; \
  55. margin: 3px 0!important; \
  56. opacity: 0.7; \
  57. } \
  58. .filteredOut h5 {\
  59. font-size: 12px!important; \
  60. margin-top: -2px!important; \
  61. padding: 3px!important; \
  62. }\
  63. .filteredOut .commentableItem, .filteredOut img, .filteredOut .userContentWrapper form, .filteredOut h5 + div{\
  64. display: none!important; \
  65. }\
  66. .filteredOut .fbUserContent > div, .filteredOut .fbUserContent button{ \
  67. display: none; \
  68. } \
  69. .filteredOut ._1dwg{\
  70. display: block!important;\
  71. }\
  72. .filteredOut .userContent+div{ \
  73. display: none!important; \
  74. } \
  75. .filteredOut .stat_elem, .filteredOut .userContent, .filteredOut.ad h5 span, .filteredOut .fbUserPost > div:not([class]), .filteredOut .fbUserPost .userContent, .filteredOut .fbUserPost .uiLikePageButton{\
  76. display: none!important;\
  77. }\
  78. .filteredOut *{\
  79. height: auto!important;\
  80. padding: 0!important;\
  81. margin: 0!important;\
  82. background-color: #e9ebee; \
  83. } \
  84. .fbFilterBtn {\
  85. position: absolute;\
  86. right: 35px;\
  87. top: 5px;\
  88. } \
  89. .filteredOut .fbFilterBtn {\
  90. right: 10px; \
  91. top: 1px; \
  92. } \
  93. </style>"
  94. );
  95. }
  96.  
  97. function minimize($elem, extraClass){
  98. var id = $elem.attr("id");
  99. if(extraClass){
  100. $elem.addClass(extraClass);
  101. }
  102. $elem.find("h5").append(" <a id='showStory_"+id+"' class='fbFilterBtn'>unhide</a><a id='rehideStory_"+id+"' style='display:none' class='fbFilterBtn'>rehide</a>");
  103. hideStory(id);
  104. $("#showStory_"+id).click(function(){showStory(id);});
  105. $("#rehideStory_"+id).click(function(){hideStory(id);});
  106. }
  107.  
  108. function showStory(id){
  109. $("#rehideStory_"+id).show();
  110. $("#showStory_"+id).hide();
  111. $("#"+id).removeClass("filteredOut");
  112. }
  113.  
  114. function hideStory(id){
  115. $("#rehideStory_"+id).hide();
  116. $("#showStory_"+id).show();
  117. $("#"+id).addClass("filteredOut").addClass("fbFiltered");
  118. }
  119.  
  120. function filter(index,elem){
  121. if(!$(elem).attr){
  122. return;
  123. }
  124. var $elem = $(elem);
  125. if($elem.hasClass("fbFiltered") || !$elem.attr("id")){
  126. return;
  127. }
  128. if($elem.attr("id").substring(0,16)!=="hyperfeed_story_"){
  129. return;
  130. }
  131. setTimeout(function(){_filter($elem);},300);
  132. }
  133. function _filter($elem){
  134. if($elem.hasClass("fbFiltered")){
  135. return;
  136. }
  137. $elem.addClass("fbFiltered");
  138. var title = $elem.find("h5").text();
  139. for(var i in keywords){
  140. if(title.contains(keywords[i])){
  141. minimize($elem);
  142. return;
  143. }
  144. }
  145. if($elem.html().indexOf('>Suggested Post</span>')>1){
  146. minimize($elem, "ad");
  147. }
  148. }
  149. function filterAll(){
  150. setTimeout(_filterAll,300);
  151. }
  152. function _filterAll(){
  153. $("[data-testid='fbfeed_story']").map(filter);
  154. }
  155. });