HideComment

скрипт ведения игнор-листа на ИноСМИ

目前為 2014-12-19 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @id InoSMI_HideComments
  3. // @name HideComment
  4. // @version 1.01
  5. // @namespace MIT
  6. // @author
  7. // @description скрипт ведения игнор-листа на ИноСМИ
  8. // @include http://inosmi.ru/*
  9. // @require http://code.jquery.com/jquery.min.js
  10. // @grant FUNCTION
  11. // ==/UserScript==
  12.  
  13. //прототип очистки массива
  14. Array.prototype.clean = function() {
  15. // сортировка массива
  16. this.sort();
  17. // очистка массива от пустых переменных
  18. for (var i = this.length - 1; i > 0; i--) {
  19. if (this[i] == "")
  20. this.splice( i, 1);
  21. }
  22. // очистка массива от повторяющихся элементов
  23. for (var i = this.length - 1; i > 0; i--) {
  24. if (this[i] == this[i-1])
  25. this.splice( i, 1);
  26. }
  27. return this;
  28. };
  29.  
  30. var to_hide = new Array();
  31.  
  32. $(document).ready(function() {
  33. //инициируем и считываем массив игноров
  34. if (localStorage.getItem('to_hide')) {
  35. to_hide = localStorage.getItem('to_hide').split(",");
  36. }
  37. else {
  38. to_hide.push('u_193012875');
  39. to_hide.push('u_207772399');
  40. }
  41. to_hide.clean();
  42.  
  43. //скрываем комментарии после загрузки страницы
  44. DoHideComment();
  45. });
  46.  
  47. //отслеживаем событие добавления нового контента (разворачивание веток)
  48. $("li[id*='comment_']").bind("DOMSubtreeModified", DoHideComment);
  49.  
  50. //функция скрытия комментариев
  51. function DoHideComment() {
  52. if (to_hide.length != 0) {
  53. $.each(to_hide, function() {
  54. var obj = $("span[id*="+this+"]").parent();
  55. obj.html('Комментарий "'+$("span[id*="+this+"]").html()+'" скрыт скриптом');
  56. obj.append('<br><a class="unhide" id="'+this+'">Снять игнор</a>');
  57. obj.next().hide();
  58. obj.next().next().hide();
  59. });
  60. }
  61. //снимаем событие "click" с элементов
  62. $("span[id*='u_']").unbind("click");
  63. $(".unhide").unbind("click");
  64. //отслеживаем клик по нику для добавления в игнор
  65. $("span[id*='u_']").click(function() {
  66. var obj = $(this).attr("id").substr(0,11);
  67. if (confirm('Добавить пользователя ID='+obj+' в игнор-лист?')) {
  68. to_hide.push(obj);
  69. localStorage.setItem('to_hide', to_hide);
  70. DoHideComment();
  71. }
  72. });
  73. //остлеживаем событие снятия игнора
  74. $(".unhide").one("click", function() {
  75. var obj = $(this).attr("id");
  76. if (confirm('Вы действительно хотите снять игнор c пользователя?')) {
  77. to_hide.splice($.inArray(obj, to_hide), 1);
  78. localStorage.setItem('to_hide', to_hide);
  79. location.reload();
  80. }
  81. });
  82. }