OpenUserJS Bullshit Filter

Hides scripts for popular browser games and social networks as well as scripts that use "foreign" characters in descriptions.

  1. // ==UserScript==
  2. // @name OpenUserJS Bullshit Filter
  3. // @namespace darkred
  4. // @version 2019.12.5
  5. // @description Hides scripts for popular browser games and social networks as well as scripts that use "foreign" characters in descriptions.
  6. // @author kuehlschrank, darkred, valacar, Graphen
  7. // @license MIT
  8. // @include /^https:\/\/openuserjs\.org\/((\?(q|p|orderBy|library)=|group\/|users\/.*\/scripts).*)?$/
  9. // @include /^http:\/\/localhost:8080\/((\?(q|p|orderBy|library)=|group\/|users\/.*\/scripts).*)?$/
  10. // @grant none
  11. // @icon https://raw.githubusercontent.com/darkred/Userscripts/master/OpenUserJS_Bullshit_Filter/large.png
  12. // This is a modified version of this script (http://userscripts-mirror.org/scripts/show/97145) by kuehlschrank.
  13. // Thanks a lot to:
  14. // - kuehlschrank for making another great script,
  15. // - valacar for the refactoring,
  16. // - Graphen for the 'Non-Latin' regex.
  17. // @supportURL https://github.com/darkred/Userscripts/issues
  18. // ==/UserScript==
  19.  
  20.  
  21. (function() {
  22.  
  23. const DEBUGGING = 0;
  24.  
  25. const filters = {
  26. 'Non-ASCII': /[^\x00-\x7F\s]+/,
  27. 'Non-Latin': /[^\u0000-\u024F\u2000-\u214F\s]+/,
  28. 'Games': /Aimbot|AntiGame|Agar|agar\.io|alis\.io|angel\.io|ExtencionRipXChetoMalo|AposBot|DFxLite|ZTx-Lite|AposFeedingBot|AposLoader|Balz|Blah Blah|Orc Clan Script|Astro\s*Empires|^\s*Attack|^\s*Battle|BiteFight|Blood\s*Wars|Bloble|Bonk|Bots|Bots4|Brawler|\bBvS\b|Business\s*Tycoon|Castle\s*Age|City\s*Ville|chopcoin\.io|Comunio|Conquer\s*Club|CosmoPulse|cursors\.io|Dark\s*Orbit|Dead\s*Frontier|Diep\.io|\bDOA\b|doblons\.io|DotD|Dossergame|Dragons\s*of\s*Atlantis|driftin\.io|Dugout|\bDS[a-z]+\n|elites\.io|Empire\s*Board|eRep(ublik)?|Epicmafia|Epic.*War|ExoPlanet|Falcon Tools|Feuerwache|Farming|FarmVille|Fightinfo|Frontier\s*Ville|Ghost\s*Trapper|Gladiatus|Goalline|Gondal|gota\.io|Grepolis|Hobopolis|\bhwm(\b|_)|Ikariam|\bIT2\b|Jellyneo|Kapi\s*Hospital|Kings\s*Age|Kingdoms?\s*of|knastv(o|oe)gel|Knight\s*Fight|\b(Power)?KoC(Atta?ck)?\b|\bKOL\b|Kongregate|Krunker|Last\s*Emperor|Legends?\s*of|Light\s*Rising|lite\.ext\.io|Lockerz|\bLoU\b|Mafia\s*(Wars|Mofo)|Menelgame|Mob\s*Wars|Mouse\s*Hunt|Molehill\s*Empire|MooMoo|MyFreeFarm|narwhale\.io|Neopets|NeoQuest|Nemexia|\bOGame\b|Ogar(io)?|Pardus|Pennergame|Pigskin\s*Empire|PlayerScripts|pokeradar\.io|Popmundo|Po?we?r\s*(Bot|Tools)|PsicoTSI|Ravenwood|Schulterglatze|Skribbl|slither\.io|slitherplus\.io|slitheriogameplay|SpaceWars|splix\.io|Survivio|\bSW_[a-z]+\n|\bSnP\b|The\s*Crims|The\s*West|torto\.io|Travian|Treasure\s*Isl(and|e)|Tribal\s*Wars|TW.?PRO|Vampire\s*Wars|vertix\.io|War\s*of\s*Ninja|World\s*of\s*Tanks|West\s*Wars|wings\.io|\bWoD\b|World\s*of\s*Dungeons|wtf\s*battles|Wurzelimperium|Yohoho|Zombs/iu,
  29. 'Social Networks': /Face\s*book|Google(\+| Plus)|\bHabbo|Kaskus|\bLepra|Leprosorium|MySpace|meinVZ|odnoklassniki|Одноклассники|Orkut|sch(ue|ü)ler(VZ|\.cc)?|studiVZ|Unfriend|Valenth|VK|vkontakte|ВКонтакте|Qzone|Twitter|TweetDeck/iu,
  30. 'Clutter': /^\s*(.{1,3})\1+\n|^\s*(.+?)\n+\2\n*$|^\s*.{1,5}\n|do\s*n('|o)?t (install|download)|nicht installieren|(just )?(\ban? |\b)test(ing|s|\d|\b)|^\s*.{0,4}test.{0,4}\n|\ntest(ing)?\s*|^\s*(\{@|Smolka|Hacks)|\[\d{4,5}\]|free\s*download|theme|(night|dark) ?(mode)?/iu
  31. };
  32.  
  33. const commonCss = `
  34. .filter-status {
  35. margin-left: 6px;
  36. }
  37.  
  38. .filter-switches {
  39. display: none;
  40. }
  41.  
  42. :hover>.filter-switches {
  43. display: block;
  44. }
  45.  
  46. .filter-on,
  47. .filter-off {
  48. display: block;
  49. width: 125px;
  50. }
  51.  
  52. .filter-switches a {
  53. text-decoration: none;
  54. color: inherit;
  55. cursor: pointer;
  56. }
  57.  
  58. .filter-switches a {
  59. margin-left: 8px;
  60. padding: 0 4px;
  61. }
  62.  
  63. a.filter-on {
  64. background-color: #ffcccc;
  65. color: #333333;
  66. text-decoration: line-through;
  67. }
  68.  
  69. a.filter-off {
  70. background-color: #ccffcc;
  71. color: #333333
  72. }
  73. `;
  74.  
  75. // const isOnForum = window.location.href.includes('forum');
  76.  
  77. const site = {};
  78.  
  79.  
  80.  
  81. // if (isOnForum) {
  82. // // site.css = '.ItemDiscussion.filtered { display: none; } .filter-on, .filter-off { color: black; } ' + commonCss;
  83. // site.css = '.tr-link.filtered { display: none; } ' + commonCss;
  84. // site.cssDebug = '.tr-link.filtered { background-color: khaki; } ' + commonCss;
  85. // // site.filterStatusLocation = '#Head';
  86. // site.filterStatusLocation = '.col-md-2';
  87. // site.itemsToCheck = '.tr-link';
  88. // site.itemType = 'discussions';
  89. // site.removeFilter = function(el) {
  90. // el.classList.remove('filtered');
  91. // };
  92. // site.applyFilter = function(el, activeFilter) {
  93. // let textToFilter = el.firstElementChild.firstElementChild.innerText;
  94. // if (textToFilter.match(activeFilter) ) {
  95. // el.classList.add('filtered');
  96. // return true;
  97. // }
  98. // return false;
  99. // };
  100. // } else {
  101.  
  102. site.css = 'tr.filtered { display: none; } ' + commonCss;
  103. site.cssDebug = 'tr.filtered { background-color: khaki; } ' + commonCss;
  104. site.filterStatusLocation = '.col-sm-4';
  105. site.itemsToCheck = '.col-sm-8 tbody tr';
  106. site.itemType = 'scripts';
  107. site.removeFilter = function(el) {
  108. el.classList.remove('filtered');
  109. };
  110. site.applyFilter = function(el, activeFilter) {
  111. // if (el.innerText.match(activeFilter)) {
  112. let textToFilter = el.firstElementChild.querySelector('a.tr-link-a').innerText + ' ' + el.firstElementChild.lastElementChild.innerText ; // Script title + description
  113. if (textToFilter.match(activeFilter) ) {
  114.  
  115. el.classList.add('filtered');
  116. return true;
  117. }
  118. return false;
  119. };
  120. // }
  121.  
  122. insertStyle();
  123. insertStatus();
  124. filterScripts();
  125. insertSwitches();
  126.  
  127. function insertStyle() {
  128. const style = document.createElement('style');
  129. style.textContent = DEBUGGING ? site.cssDebug : site.css;
  130. style.type = 'text/css';
  131. document.head.appendChild(style);
  132. }
  133.  
  134. function insertStatus() {
  135. const p = document.querySelector(site.filterStatusLocation);
  136. if (p) {
  137. const status = document.createElement('span');
  138. status.className = 'filter-status';
  139. p.appendChild(status);
  140. }
  141. }
  142.  
  143.  
  144.  
  145. function filterScripts() {
  146. const activeFilters = [];
  147. for (let filterType of Object.keys(filters)) {
  148. if (configGetValue(filterType, 'on') === 'on') {
  149. activeFilters.push(filters[filterType]);
  150. }
  151. }
  152. const nodes = document.querySelectorAll(site.itemsToCheck);
  153. let numFiltered = 0;
  154. for (let node of nodes) {
  155. site.removeFilter(node);
  156. for (let activeFilter of activeFilters) {
  157. let filtered = site.applyFilter(node, activeFilter);
  158. if (filtered) {
  159. numFiltered++;
  160. break;
  161. }
  162. }
  163. }
  164. const filterStatus = document.querySelector('.filter-status');
  165. if (filterStatus) {
  166. const numUnfiltered = document.querySelectorAll(site.itemsToCheck).length - numFiltered;
  167. filterStatus.textContent = `${numUnfiltered} ${site.itemType} (${numFiltered} filtered)`;
  168. }
  169. }
  170.  
  171. function insertSwitches() {
  172. const span = document.createElement('span');
  173. span.className = 'filter-switches';
  174. for (let filterType of Object.keys(filters)) {
  175. span.appendChild(createSwitch(filterType, configGetValue(filterType, 'on') === 'on'));
  176. }
  177. const filterStatus = document.querySelector('.filter-status');
  178. if (filterStatus) {
  179. filterStatus.parentNode.appendChild(span);
  180. }
  181. }
  182.  
  183. function createSwitch(label, isOn) {
  184. const a = document.createElement('a');
  185. a.className = isOn ? 'filter-on' : 'filter-off';
  186. a.textContent = label;
  187. a.addEventListener('click', function(e) {
  188. if (this.className === 'filter-on') {
  189. this.className = 'filter-off';
  190. configSetValue(this.textContent, 'off');
  191. } else {
  192. this.className = 'filter-on';
  193. configSetValue(this.textContent, 'on');
  194. }
  195. filterScripts();
  196. e.preventDefault();
  197. }, false);
  198. return a;
  199. }
  200.  
  201. function configSetValue(name, value) {
  202. localStorage.setItem(name, value);
  203. }
  204.  
  205. function configGetValue(name, defaultValue) {
  206. const value = localStorage.getItem(name);
  207. return value ? value : defaultValue;
  208. }
  209.  
  210. })();