FC - Hitman

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

当前为 2021-01-17 提交的版本,查看 最新版本

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