GreasyFork Bullshit Filter

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

目前為 2015-09-03 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GreasyFork Bullshit Filter
  3. // @namespace rikkie
  4. // @description Hides scripts for popular browser games and social networks as well as scripts that use "foreign" characters in descriptions, when browsing scripts.
  5. // @version 1
  6. // @icon https://s3.amazonaws.com/uso_ss/icon/97145/large.png
  7. // @grant none
  8. // @include https://greasyfork.org/*/scripts*
  9. // This is an edited version of this script (http://userscripts-mirror.org/scripts/show/97145) by kuehlschrank.
  10. // Thanks a lot to kuehlschrank for making another great script.
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. var filters = {
  15. 'Games': /AntiGame|Astro\s*Empires|^\s*Attack|^\s*Battle|BiteFight|Blood\s*Wars|Bots4|Brawler|\bBvS\b|Business\s*Tycoon|Castle\s*Age|City\s*Ville|Comunio|Conquer\s*Club|CosmoPulse|Dark\s*Orbit|Dead\s*Frontier|\bDOA\b|Dossergame|Dragons\s*of\s*Atlantis|Dugout|\bDS[a-z]+\n|Empire\s*Board|eRep(ublik)?|Epic.*War|ExoPlanet|Falcon Tools|Feuerwache|Farming|FarmVille|Fightinfo|Frontier\s*Ville|Ghost\s*Trapper|Gladiatus|Goalline|Gondal|Grepolis|Hobopolis|\bhwm(\b|_)|Ikariam|\bIT2\b|Jellyneo|Kapi\s*Hospital|Kings\s*Age|Kingdoms?\s*of|knastv(ö|oe)gel|Knight\s*Fight|\b(Power)?KoC(Atta?ck)?\b|\bKOL\b|Kongregate|Last\s*Emperor|Legends?\s*of|Light\s*Rising|Lockerz|\bLoU\b|Mafia\s*(Wars|Mofo)|Menelgame|Mob\s*Wars|Mouse\s*Hunt|Molehill\s*Empire|NeoQuest|MyFreeFarm|Neopets|Nemexia|\bOGame\b|Pardus|Pennergame|Pigskin\s*Empire|PlayerScripts|Popmundo|Po?we?r\s*(Bot|Tools)|PsicoTSI|Ravenwood|Schulterglatze|SpaceWars|\bSW_[a-z]+\n|\bSnP\b|The\s*Crims|The\s*West|Travian|Treasure\s*Isl(and|e)|Tribal\s*Wars|TW.?PRO|Vampire\s*Wars|War\s*of\s*Ninja|West\s*Wars|\bWoD\b|World\s*of\s*Dungeons|wtf\s*battles|Wurzelimperium/i,
  16. 'Social Networks': /Face\s*book|Google(\+| Plus)|\bHabbo|Kaskus|\bLepra|Leprosorium|MySpace|meinVZ|odnoklassniki|Одноклассники|Orkut|sch(ue|ü)ler(VZ|\.cc)?|studiVZ|Unfriend|Valenth|vkontakte|ВКонтакте|Qzone|Twitter/i,
  17. 'Non-ASCII':/[^\x00-\x80\s]+/i,
  18. 'Clutter':/^\s*(.{1,3})\1+\n|^\s*(.+?)\n+\2\n*$|^\s*.{1,5}\n|do\s*n('|o)?t (install|download)|nicht installieren|just(\s*a)?\s*test|^\s*.{0,4}test.{0,4}\n|\ntest(ing)?\s*|^\s*(\{@|Smolka|Hacks)|\[\d{4,5}\]|free\s*download/i
  19. };
  20. if(typeof GM_getValue == 'undefined' || (typeof GM_getValue.toString == 'function' && GM_getValue.toString().indexOf('not supported') > -1)) {
  21. GM_getValue = my_GM_getValue;
  22. GM_setValue = my_GM_setValue;
  23. }
  24. insertStyle();
  25. insertStatus();
  26. filterScripts();
  27. insertSwitches();
  28. var flag;
  29. // ADD A NEWLINE AT THE END OF EACH FILTER
  30. if (document.querySelector('.filter-status').parentNode.childNodes[5].childNodes[0].innerHTML == 'Games' ) {
  31. flag = 5; }
  32. else {flag = 9}
  33. for (i=0; i<4; i++){
  34. document.querySelector('.filter-status').parentNode.childNodes[flag].childNodes[i].innerHTML += '<br>';
  35. }
  36. // Note: you may uncomment line 41 and comment out line 42, in order the filtered scripts to be highlighted yellow -instead of hiding them- so that you can check which scripts have been filtered
  37. function insertStyle() {
  38. var style = document.createElement('style');
  39. // style.textContent = 'article.filtered { background-color:yellow; !important; } .filter-status { margin-left: 6px; } .filter-switches { display:none; } *:hover > .filter-switches { display:inline; } .filter-switches a { text-decoration:none !important; color:inherit; cursor:pointer; } .filter-switches a { margin-left: 8px; padding: 0 4px; } a.filter-on { background-color:#ffcccc; color:#333333 } a.filter-off { background-color:#ccffcc; color:#333333 } ';
  40. style.textContent = 'article.filtered { display:none; !important; } .filter-status { margin-left: 6px; } .filter-switches { display:none; } *:hover > .filter-switches { display:inline; } .filter-switches a { text-decoration:none !important; color:inherit; cursor:pointer; } .filter-switches a { margin-left: 8px; padding: 0 4px; } a.filter-on { background-color:#ffcccc; color:#333333 } a.filter-off { background-color:#ccffcc; color:#333333 } ';
  41. style.type = 'text/css';
  42. document.querySelector('head').appendChild(style);
  43. }
  44. function insertStatus() {
  45. var p = document.querySelector('#script-list-option-groups');
  46. if(p) {
  47. var status = document.createElement('span');
  48. status.className = 'filter-status';
  49. p.appendChild(status);
  50. }
  51. p.innerHTML += '<br>'; // ADDS A NEWLINE AT THE END OF THE 'STATUS' ENTRY
  52. }
  53. function filterScripts() {
  54. var activeFilters = [];
  55. for(var filter in filters) {
  56. if(filters.hasOwnProperty(filter) && GM_getValue(filter, 'on') == 'on') {
  57. activeFilters.push(filters[filter]);
  58. }
  59. }
  60. var nodes = document.querySelectorAll('article > h2'), numActiveFilters = activeFilters.length, numFiltered = 0;
  61. for(var i = 0, numNodes = nodes.length, td = null; i < numNodes && (td = nodes[i]); i++) {
  62. td.parentNode.className = '';
  63. for(var j = 0; j < numActiveFilters; j++) {
  64. if(td.textContent.match(activeFilters[j])) {
  65. td.parentNode.className = 'filtered';
  66. numFiltered++;
  67. break;
  68. }
  69. }
  70. }
  71. document.querySelector('.filter-status').textContent = '(' + numFiltered + ' filtered)';
  72. }
  73. function insertSwitches() {
  74. var span = document.createElement('span');
  75. span.className = 'filter-switches';
  76. for(var filter in filters) {
  77. if(filters.hasOwnProperty(filter)) {
  78. span.appendChild(createSwitch(filter, GM_getValue(filter, 'on') == 'on'));
  79. }
  80. }
  81. document.querySelector('.filter-status').parentNode.appendChild(span);
  82. }
  83. function createSwitch(label, isOn) {
  84. var a = document.createElement('a');
  85. a.className = isOn ? 'filter-on' : 'filter-off';
  86. a.textContent = label;
  87. a.addEventListener('click', function(e) {
  88. if(this.className == 'filter-on') {
  89. this.className = 'filter-off';
  90. GM_setValue(this.textContent, 'off');
  91. } else {
  92. this.className = 'filter-on';
  93. GM_setValue(this.textContent, 'on');
  94. }
  95. filterScripts();
  96. e.preventDefault();
  97. }, false);
  98. return a;
  99. }
  100. function my_GM_setValue(name, value) {
  101. localStorage.setItem(name, value);
  102. }
  103. function my_GM_getValue(name, defaultValue) {
  104. var value;
  105. if (!(value = localStorage.getItem(name))) {
  106. return defaultValue;
  107. }
  108. return value;
  109. }
  110. })();