ČSFD ignore list

Skript sloužící k ignorování otravných uživatelů v ČSFD diskuzích

  1. // ==UserScript==
  2. // @name ČSFD ignore list
  3. // @namespace csfd.cz
  4. // @description Skript sloužící k ignorování otravných uživatelů v ČSFD diskuzích
  5. // @include *csfd.cz/*diskuze/*
  6. // @icon http://img.csfd.cz/assets/b1733/images/apple_touch_icon.png
  7. // @grant none
  8. // @version 1.2
  9. // ==/UserScript==
  10.  
  11.  
  12. var ignore = ["Jméno1", "Jméno2", "Jméno3", "Jméno4"];
  13.  
  14. var posts = document.getElementsByClassName("ui-posts-action-list")[0];
  15. var links = posts.getElementsByTagName("a");
  16. var toRemove = [];
  17.  
  18. function contains(array, value) {
  19. //noprotect
  20. for (var i = 0; i < array.length; i++) {
  21. if (array[i] == value) {
  22. return true;
  23. }
  24. }
  25. return false;
  26. }
  27.  
  28. function removeReactionsBlock(reactions) {
  29. var reChildren = reactions.children;
  30.  
  31. //noprotect
  32. for (var i = 0; i < reChildren.length; i++) {
  33. if (!contains(ignore, reChildren[i].textContent.trim())) {
  34. return false;
  35. }
  36. }
  37. toRemove.push(reactions);
  38. return true;
  39. }
  40.  
  41. function removeFirstComma(reactions) {
  42. var chNodes = reactions.childNodes;
  43. //noprotect
  44. for (var j = 0; j < chNodes.length; j++) {
  45. if (chNodes[j].nodeValue && chNodes[j].nodeValue.trim() == ",") {
  46. chNodes[j].remove();
  47. return;
  48. }
  49. }
  50. }
  51.  
  52. //noprotect
  53. for (var i = 0; i < links.length; i++) {
  54. if (contains(ignore, links[i].textContent.trim())) {
  55. var directParent = links[i].parentElement;
  56. if (directParent.className.trim() == "author") {
  57. toRemove.push(directParent.parentElement.parentElement);
  58. } else if (directParent.className.trim() == "reactions") {
  59. if (!removeReactionsBlock(directParent)) {
  60. toRemove.push(links[i]);
  61. removeFirstComma(directParent);
  62. }
  63. }
  64. }
  65. }
  66.  
  67. for (var i = 0; i < toRemove.length; i++) {
  68. toRemove[i].remove();
  69. }