FC - Hitman

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

  1. // ==UserScript==
  2. // @name FC - Hitman
  3. // @license MIT
  4. // @namespace https://greasyfork.org/es/scripts/14670-fc-hitman
  5. // @version 2.4
  6. // @description Borra los temas (políticos, fútbol, apuestas, etc..) que quieras de Forocoches (FC)
  7. // @author DonNadie
  8. // @match http://*.forocoches.com/*
  9. // @match https://*.forocoches.com/*
  10. // @match http://www.forocoches.com/*
  11. // @match https://www.forocoches.com/*
  12. // @exclude http://www.forocoches.com/foro/private.php*
  13. // @exclude https://*.forocoches.com/foro/private.php*
  14. // @exclude http://*.forocoches.com/foro/private.php*
  15. // @exclude http://www.forocoches.com/foro/newthread.php*
  16. // @exclude https://*.forocoches.com/foro/newthread.php*
  17. // @exclude http://*.forocoches.com/foro/newthread.php*
  18. // @exclude http://www.forocoches.com/foro/newreply.php*
  19. // @exclude https://*.forocoches.com/foro/newreply.php*
  20. // @exclude http://*.forocoches.com/foro/newreply.php*
  21. // @exclude http://www.forocoches.com/foro/showthread.php?t=*
  22. // @exclude https://*.forocoches.com/foro/showthread.php?t=*
  23. // @exclude http://*.forocoches.com/foro/showthread.php?t=*
  24. // @grant none
  25. // ==/UserScript==
  26. /* jshint -W097 */
  27. 'use strict';
  28.  
  29. class Hitman {
  30.  
  31. constructor() {
  32. this.words = {
  33. politics: ["ayuso", "vox", "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"],
  34. catalan: ["lazis", "independencia", "puigdemont", " cup", "catalufos", "pantumaker", "indepes", "pruses", "prusés", "tv3", "cataluña", "catalunya", "catalanes", "pugdemon", "catalana", "independentista", "catalán", "catalan"],
  35. consoles: ["PlayStation", "XBOX", "PS5", "Xbox", "Ps5", "xbox", "ps5"],
  36. 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", "penya culer", "Real Sporting"],
  37. vaccines: ["vacuna", "pcr"]
  38. };
  39. this.censorList = [];
  40.  
  41. if (document.getElementById('vB_Editor_001_iframe') != null) {
  42. return;
  43. }
  44. this.getCensoredWords();
  45. this.removeThreads();
  46. this.setupPanel();
  47. }
  48.  
  49. setupPanel () {
  50. let td = document.createElement('td');
  51. td.innerHTML = '<div id="hitman-config" title="Configuración de Hitman (borrado de temas)">Hitman</div>';
  52.  
  53. document.querySelector(".cajasprin:nth-of-type(1) tr tr").append(td);
  54.  
  55. this.parseTemplate(function()
  56. {/* <div>
  57. <div id="hitman-panel">
  58. Esconder temas de:
  59. <ul>
  60. <li>
  61. <label>
  62. <input type="checkbox" value="politics"> Política
  63. </label>
  64. </li>
  65. <li>
  66. <label>
  67. <input type="checkbox" value="football"> Fútbol
  68. </label>
  69. </li>
  70. <li>
  71. <label>
  72. <input type="checkbox" value="catalan"> Cataluña
  73. </label>
  74. </li>
  75. <li>
  76. <label>
  77. <input type="checkbox" value="consoles"> Consolas
  78. </label>
  79. </li>
  80. <li>
  81. <label>
  82. <input type="checkbox" value="vaccines"> Vacunas
  83. </label>
  84. </li>
  85. <li>
  86. <br>
  87. <label>
  88. Filtro propio:<br>
  89. <textarea name="hitman-custom" placeholder="gore,movistar"></textarea>
  90. </label>
  91. </li>
  92. </ul>
  93. <button>Guardar cambios</button>
  94. <br>
  95. <a href="https://greasyfork.org/es/scripts/14670-fc-hitman/versions">Ver actualizaciones</a>
  96. </div>
  97. <style>
  98. #hitman-config {
  99. cursor: pointer;
  100. color: #1CC4F9;
  101. }
  102. #hitman-panel {
  103. display: none;
  104. position: fixed;
  105. background: white;
  106. padding: 5px;
  107. border: 1px solid;
  108. margin-left: 74%;
  109. margin-top: 6%;
  110. }
  111. #hitman-panel ul {
  112. list-style-type: none;
  113. padding: 0px;
  114. margin-top: 0px;
  115. }
  116. </style>
  117. </div>
  118. */}).then($html => {
  119. document.body.prepend($html);
  120.  
  121. const $hitmanPanel = document.getElementById("hitman-panel");
  122.  
  123. document.getElementById("hitman-config").addEventListener("click", () => {
  124. $hitmanPanel.style.display = $hitmanPanel.style.display === 'block' ? 'none' : 'block';
  125. });
  126.  
  127. $hitmanPanel.querySelectorAll("input").forEach(el => {
  128. el.addEventListener("change", () => {
  129. this.updateCensor(el.value, el.checked);
  130. });
  131. })
  132.  
  133. $hitmanPanel.querySelector("textarea").addEventListener("change", (e) => {
  134. this.updateCensor("custom", e.srcElement.value);
  135. })
  136.  
  137. $hitmanPanel.querySelector("button").addEventListener("click", () => {
  138. location.reload();
  139. });
  140.  
  141. this.loadConfig();
  142. });
  143. }
  144.  
  145. loadConfig () {
  146. const config = this.getConfig();
  147. let k;
  148.  
  149. for (k in config) {
  150. if (config[k]) {
  151. if (k == "custom") {
  152. document.querySelector('#hitman-panel textarea[name="hitman-custom"]').value = config[k];
  153. } else {
  154. document.querySelector("#hitman-panel input[value=" + k + "]").checked = true;
  155. }
  156. }
  157. }
  158. }
  159. parseTemplate (func) {
  160. return new Promise((resolve, deny) => {
  161. let div = document.createElement('div');
  162. div.innerHTML = func.toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');
  163. resolve(div.firstElementChild);
  164. });
  165. }
  166.  
  167. updateCensor (type, status) {
  168. let config = this.getConfig();
  169.  
  170. config[type] = status;
  171.  
  172. this.setConfig(config);
  173. }
  174.  
  175. getConfig () {
  176. let config = localStorage.hitman;
  177.  
  178. if (config === undefined) {
  179. // default config
  180. return {
  181. politics: true,
  182. };
  183. }
  184. return JSON.parse(config);
  185. }
  186.  
  187. setConfig (config) {
  188. localStorage.hitman = JSON.stringify(config);
  189. }
  190.  
  191. // find and delete threads containing the censored words
  192. removeThreads () {
  193. let $mainForum = null;
  194.  
  195. document.querySelectorAll('#threadslist tbody').forEach(el => {
  196. if (el.id.includes("threadbits_forum_")) {
  197. $mainForum = el;
  198. }
  199. });
  200.  
  201. if ($mainForum != null)
  202. {
  203. let deletedCount = 0;
  204.  
  205. this.parseTemplate(function(){/*
  206. <table><tbody>
  207. <tr class="hitman-separator">
  208. <td></td>
  209. <td></td>
  210. <td></td>
  211. <td></td>
  212. <td></td>
  213. </tr>
  214. <tr class="hitman-separator">
  215. <td></td>
  216. <td></td>
  217. <td><a id="hitman-next-page" href="#">Siguiente página &gt;</a></td>
  218. <td></td>
  219. <td></td>
  220. </tr>
  221. <tr class="hitman-separator">
  222. <td></td>
  223. <td></td>
  224. <td></td>
  225. <td></td>
  226. <td></td>
  227. </tr>
  228. <tr class="hitman-separator">
  229. <td class="thead"></td>
  230. <td class="thead"></td>
  231. <td class="thead">&nbsp;</td>
  232. <td class="thead"></td>
  233. <td class="thead"></td>
  234. </tr>
  235. <tr class="hitman-separator">
  236. <td class="tcat"></td>
  237. <td class="tcat"></td>
  238. <td class="tcat">Posts eliminados por Hitman</td>
  239. <td class="tcat" id="hitman-count" align="right">0</td>
  240. <td class="tcat"></td>
  241. </tr>
  242. <tr class="hitman-separator">
  243. <td class="thead" colspan="2" width="57">&nbsp;</td>
  244. <td class="thead" width="100%">
  245. <span style="float:right"><a href="#" rel="nofollow">Calificación</a> </span>
  246. <a href="#">Tema</a> /
  247. <a href="#" rel="nofollow">Autor</a>
  248. </td>
  249. <td class="thead" width="150" align="center" nowrap="nowrap"><span style="white-space:nowrap"><a href="#">Último Mensaje</a></span></td>
  250. <td class="thead" align="center" nowrap="nowrap">
  251. <span style="white-space:nowrap">
  252. <a href="#" rel="nofollow" title="Respuestas">R.</a> </span> / <span style="white-space:nowrap"><a href="#" rel="nofollow" title="Visitas">V.</a>
  253. </span>
  254. </td>
  255. </tr>
  256. </tbody></table>
  257. */}).then($html => {
  258. [...$html.firstElementChild.children].forEach(el => {
  259. $mainForum.append(el);
  260. });
  261.  
  262. // General section
  263. document.querySelectorAll('#' + $mainForum.id + ' tr:not(.hitman-separator)').forEach($tr => {
  264. const intro = $tr.querySelector("td[title]").title;
  265. let censoredWord = false,
  266. $title;
  267. $tr.querySelectorAll('td[title] a[id]').forEach(el => {
  268. if (el.id.includes("thread_title_")) {
  269. $title = el;
  270. }
  271. });
  272.  
  273. if ($title.innerText.length == 0) {
  274. return true;
  275. }
  276.  
  277. censoredWord = this.mustBeRemoved($title.innerText + " " + intro);
  278.  
  279. if (censoredWord !== false)
  280. {
  281. $tr.style.opacity = 0.2;
  282. $title.append(" (" + censoredWord + ")");
  283.  
  284. // move tr to bottom
  285. $mainForum.append($tr);
  286. deletedCount++;
  287. }
  288. });
  289.  
  290. document.getElementById('hitman-count').innerText = deletedCount;
  291. document.getElementById('hitman-next-page').href = document.querySelector('a[rel="next"]').href;
  292. });
  293. } else if(document.querySelector('.cajasnews') != null) { // Homepage
  294. document.querySelectorAll('table[border="0"][cellpadding="2"][cellspacing="0"][width="100%"]')[3].querySelectorAll('tr:not([bgcolor="#f5f5f5"])').forEach((el) =>
  295. {
  296. const $thread = el.querySelectorAll('td[align="left"] a')[1],
  297. text = $thread.innerText + " " + $thread.title;
  298.  
  299. if (this.mustBeRemoved(text)) {
  300. el.remove();
  301. }
  302. });
  303. }
  304. }
  305.  
  306. getCensoredWords () {
  307. if (this.censorList.length > 0) {
  308. return this.censorList;
  309. }
  310.  
  311. const config = this.getConfig();
  312. let k;
  313.  
  314. // setup the word censorship list
  315. for (k in config) {
  316. if (config[k]) {
  317. if (k == "custom" && config[k].length > 0) {
  318. this.censorList = this.censorList.concat(config[k].split(","));
  319. } else {
  320. this.censorList = this.censorList.concat(this.words[k]);
  321. }
  322. }
  323. }
  324. return this.censorList;
  325. }
  326.  
  327. mustBeRemoved (text) {
  328. let regex,
  329. k;
  330.  
  331. for (k in this.censorList)
  332. {
  333. if (this.censorList[k].length < 1) {
  334. continue;
  335. }
  336. regex = new RegExp(this.censorList[k], "i");
  337.  
  338. if (text.search(regex) !== -1) {
  339. return this.censorList[k];
  340. }
  341. }
  342. return false;
  343. }
  344. }
  345.  
  346. new Hitman();