FC - Hitman

Borra los temas (políticos, fútbol, apuestas, etc..) que quieras de Forocoches (FC)

当前为 2015-12-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name FC - Hitman
  3. // @namespace https://greasyfork.org/es/scripts/14670-fc-hitman
  4. // @version 1.7
  5. // @description Borra los temas (políticos, fútbol, apuestas, etc..) que quieras de Forocoches (FC)
  6. // @author DonNadie
  7. // @match http://*.forocoches.com/*
  8. // @match https://*.forocoches.com/*
  9. // @match http://www.forocoches.com/*
  10. // @match https://www.forocoches.com/*
  11. // @exclude http://www.forocoches.com/foro/private.php*
  12. // @exclude https://*.forocoches.com/foro/private.php*
  13. // @exclude http://*.forocoches.com/foro/private.php*
  14. // @exclude http://www.forocoches.com/foro/newthread.php*
  15. // @exclude https://*.forocoches.com/foro/newthread.php*
  16. // @exclude http://*.forocoches.com/foro/newthread.php*
  17. // @exclude http://www.forocoches.com/foro/newreply.php*
  18. // @exclude https://*.forocoches.com/foro/newreply.php*
  19. // @exclude http://*.forocoches.com/foro/newreply.php*
  20. // @grant none
  21. // @require http://code.jquery.com/jquery-latest.js
  22. // ==/UserScript==
  23. /* jshint -W097 */
  24. 'use strict';
  25.  
  26. var hitman = function ()
  27. {
  28. var words = {
  29. politics: ["partido popular", " C'S", "votado", "podemita","pudremitas", "riverita", "peperro","político", "Saenz de Santamaria", "Sáenz de Santamaría", "votantes", "pdr snchz", "partidos politicos", "partidos políticos", "partido político", "partido politico", "Pedro Sánchez", "Pedro Sanchez", "rajoy","soraya", "falange", "pableras", "upyd", "coletas","psoe","debate", "carmena", "voto", "pablemos", "ciudadanos", "ciutadans", "discurso", "albert", "rivera", "iglesias", "elecciones", "votar", "votación", "votacion", "pedro sanchez", "pedro sánchez", "podemos", "podemitas", " pp"],
  30. football: ["Peña Real Valladolid","Peña Bética", "Peña Athletic", "PEÑA COLCHONERA", "PENYA BLAUGRANA", "piqué", "PEÑA CELTISTA", "real madrid", "futbol", "fútbol", "porra", "apuesta", "penya culer", "peña culer", "culers", "culeros", "culerdos", "FC Barcelona", "barça", "Barsa", "atleti", "PEÑA VALENCIANISTA", "merengue"]
  31. },
  32. censorList = [];
  33. var init = function ()
  34. {
  35. if ($('#vB_Editor_001_iframe').length > 0) {
  36. return;
  37. }
  38. getCensoredWords();
  39. removeThreads();
  40. setupPanel();
  41. }
  42. var setupPanel = function ()
  43. {
  44. $(".cajasprin:nth-of-type(1) tr").eq(1).append('<td><div id="hitman-config" title="Configuración de Hitman (borrado de temas)">Hitman</div></d>');
  45. var html = parseTemplate(function()
  46. {/*
  47. <div id="hitman-panel">
  48. Esconder temas de:
  49. <ul>
  50. <li>
  51. <label>
  52. <input type="checkbox" value="politics"> Política
  53. </label>
  54. </li>
  55. <li>
  56. <label>
  57. <input type="checkbox" value="football"> Fútbol
  58. </label>
  59. </li>
  60. <li>
  61. <br>
  62. <label>
  63. Filtro propio:<br>
  64. <textarea name="hitman-custom" placeholder="gore,movistar"></textarea>
  65. </label>
  66. </li>
  67. </ul>
  68. <button>Guardar cambios</button>
  69. <br>
  70. <a href="https://greasyfork.org/es/scripts/14670-fc-hitman/versions">Ver actualizaciones</a>
  71. </div>
  72. <style>
  73. #hitman-config {
  74. cursor: pointer;
  75. color: #1CC4F9;
  76. }
  77. #hitman-panel {
  78. display: none;
  79. position: fixed;
  80. background: white;
  81. padding: 5px;
  82. border: 1px solid;
  83. margin-left: 74%;
  84. margin-top: 6%;
  85. }
  86. #hitman-panel ul {
  87. list-style-type: none;
  88. padding: 0px;
  89. margin-top: 0px;
  90. }
  91. </style>
  92. */});
  93. $("body").prepend(html);
  94. $("#hitman-config").on("click", function () {
  95. $('#hitman-panel').toggle();
  96. });
  97.  
  98. $("#hitman-panel input").on("change", function () {
  99. updateCensor($(this).val(), $(this).is(":checked"));
  100. });
  101. $("#hitman-panel textarea").on("change", function () {
  102. updateCensor("custom", $(this).val());
  103. });
  104. $("#hitman-panel button").on("click", function () {
  105. location.reload();
  106. });
  107. loadConfig();
  108. }
  109. var loadConfig = function ()
  110. {
  111. var config = getConfig(),
  112. k;
  113. for (k in config) {
  114. if (config[k]) {
  115. if (k == "custom") {
  116. $('#hitman-panel textarea[name="hitman-custom"]').val(config[k]);
  117. } else {
  118. $("#hitman-panel input[value=" + k + "]").prop("checked", true);
  119. }
  120. }
  121. }
  122. }
  123. var parseTemplate = function(func) {
  124. return func.toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');
  125. }
  126. var updateCensor = function (type, status)
  127. {
  128. var config = getConfig();
  129. config[type] = status;
  130. setConfig(config);
  131. }
  132. var getConfig = function ()
  133. {
  134. var config = localStorage.hitman;
  135. if (config === undefined) {
  136. // default config
  137. return {
  138. politics: true,
  139. };
  140. }
  141. return JSON.parse(config);
  142. }
  143. var setConfig = function (config) {
  144. localStorage.hitman = JSON.stringify(config);
  145. }
  146. // find and delete threads containing the censored words
  147. var removeThreads = function ()
  148. {
  149. var $mainForum = $('#threadbits_forum_2');
  150. if ($mainForum.length > 0)
  151. {
  152. var deletedCount = 0;
  153. $mainForum.append(parseTemplate(function(){/*
  154. <tr class="hitman-separator">
  155. <td></td>
  156. <td></td>
  157. <td></td>
  158. <td></td>
  159. <td></td>
  160. </tr>
  161. <tr class="hitman-separator">
  162. <td></td>
  163. <td></td>
  164. <td><a id="hitman-next-page" href="#">Siguiente página &gt;</a></td>
  165. <td></td>
  166. <td></td>
  167. </tr>
  168. <tr class="hitman-separator">
  169. <td></td>
  170. <td></td>
  171. <td></td>
  172. <td></td>
  173. <td></td>
  174. </tr>
  175. <tr class="hitman-separator">
  176. <td class="thead"></td>
  177. <td class="thead"></td>
  178. <td class="thead">&nbsp;</td>
  179. <td class="thead"></td>
  180. <td class="thead"></td>
  181. </tr>
  182. <tr class="hitman-separator">
  183. <td class="tcat"></td>
  184. <td class="tcat"></td>
  185. <td class="tcat">Posts eliminados por Hitman</td>
  186. <td class="tcat" id="hitman-count" align="right">0</td>
  187. <td class="tcat"></td>
  188. </tr>
  189. <tr>
  190. <td class="thead" colspan="2" width="57">&nbsp;</td>
  191. <td class="thead" width="100%">
  192. <span style="float:right"><a href="#" rel="nofollow">Calificación</a> </span>
  193. <a href="#">Tema</a> /
  194. <a href="#" rel="nofollow">Autor</a>
  195. </td>
  196. <td class="thead" width="150" align="center" nowrap="nowrap"><span style="white-space:nowrap"><a href="#">Último Mensaje</a></span></td>
  197. <td class="thead" align="center" nowrap="nowrap">
  198. <span style="white-space:nowrap">
  199. <a href="#" rel="nofollow" title="Respuestas">R.</a> </span> / <span style="white-space:nowrap"><a href="#" rel="nofollow" title="Visitas">V.</a>
  200. </span>
  201. </td>
  202. </tr>
  203. */}));
  204. // General section
  205. $('#threadbits_forum_2 tr:not(.hitman-separator)').each(function ()
  206. {
  207. var censoredWord = false,
  208. $tr = $(this),
  209. $title = $tr.find('td[title] a[style="font-weight:bold"]'),
  210. intro = $tr.find("td[title]").attr("title");
  211. if ($title.text().length == 0) {
  212. return true;
  213. }
  214. censoredWord = mustBeRemoved($title.text() + " " + intro);
  215. if (censoredWord !== false)
  216. {
  217. $tr.css('opacity', 0.2);
  218. $title.append(" (" + censoredWord + ")");
  219. // move tr to bottom
  220. $mainForum.append($tr);
  221. deletedCount++;
  222. }
  223. });
  224. $('#hitman-count').text(deletedCount);
  225. $('#hitman-next-page').attr("href", $('a[rel="next"]').eq(0).attr("href"));
  226. } else {
  227. // Home
  228. $('table[border="0"][cellpadding="2"][cellspacing="0"][width="100%"]').eq(3).find("tr").each(function ()
  229. {
  230. var $thread = $(this).find('td[align="left"] a').eq(1),
  231. text = $thread.text() + " " + $thread.attr("title");
  232. if (mustBeRemoved(text)) {
  233. $(this).remove();
  234. }
  235. });
  236. }
  237. }
  238. var getCensoredWords = function ()
  239. {
  240. if (censorList.length > 0) {
  241. return censorList;
  242. }
  243. var config = getConfig(),
  244. k;
  245. // setup the word censorship list
  246. for (k in config) {
  247. if (config[k]) {
  248. if (k == "custom" && config[k].length > 0) {
  249. censorList = censorList.concat(config[k].split(","));
  250. } else {
  251. censorList = censorList.concat(words[k]);
  252. }
  253. }
  254. }
  255. return censorList;
  256. }
  257. var mustBeRemoved = function (text)
  258. {
  259. var regex,
  260. k;
  261. for (k in censorList)
  262. {
  263. regex = new RegExp(censorList[k], "i");
  264. if (text.search(regex) !== -1) {
  265. return censorList[k];
  266. }
  267. }
  268. return false;
  269. }
  270. return {
  271. init: init
  272. }
  273. }();
  274.  
  275. $(document).ready(function() {
  276. hitman.init();
  277. });