Advertisement
Guest User

Point blacklist

a guest
Apr 7th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @id             point-blacklist
  3. // @name           Point blacklist
  4. // @version        1.0
  5. // @namespace      
  6. // @author         Tenno Seremel
  7. // @description    
  8. // @include        http://point.im/all
  9. // @include        https://point.im/all
  10. // @run-at         document-end
  11. // ==/UserScript==
  12. (function(){
  13. /*
  14. notification_block_id:
  15.     id элемента, в который будет выводиться информация о том,
  16.     что сообщения были удалены (может быть null, если эта информация не нужна)
  17.     на текущий момент это, например: content (блок с сообщениями), left-menu (сайдбар)
  18. notification_is_at_top:
  19.     Добавить текст уведомления до уже имеющегося текста в блоке (true) или после (false)
  20. notification_wrapper_style
  21.     CSS стиль для блока с текстом нотификации
  22. tag_black_list:
  23.     массив запрещённых тегов (строки должны быть в нижнем регистре)
  24. user_black_list:
  25.     массив запрещённых пользователей (строки должны быть в нижнем регистре)
  26. */
  27. var CONFIG = {
  28.     notification_block_id: "left-menu",
  29.     notification_is_at_top: true,
  30.     notification_wrapper_style: "margin-bottom: 1em",
  31.     tag_black_list: [
  32.         "mlp", "дао-какао", "мякотка", "созвездие", "перашки"
  33.     ],
  34.     user_black_list: [
  35.     ]
  36. }
  37. function remove_el(el)
  38. {
  39.     el.parentNode.removeChild(el);
  40. }
  41. function remove_blocked()
  42. {
  43.     var messages_removed = 0;
  44.     var messages = document.querySelectorAll("#content .post");
  45.     for (var i = messages.length; i > 0; i--) {
  46.         var current = messages[i - 1];
  47.         // tags
  48.         var x = current.querySelectorAll(".post-content > .tags > .tag");
  49.         for (var j = 0, len2 = x.length; j < len2; j++) {
  50.             if (CONFIG.tag_black_list.indexOf(x[j].textContent.trim().toLowerCase()) != -1) {
  51.                 remove_el(current);
  52.                 messages_removed++;
  53.                 break;
  54.             }
  55.         }
  56.         // users
  57.         x = current.querySelectorAll(".post-content > .user.author");
  58.         for (var j = 0, len2 = x.length; j < len2; j++) {
  59.             if (CONFIG.user_black_list.indexOf(x[j].textContent.trim().toLowerCase()) != -1) {
  60.                 remove_el(current);
  61.                 messages_removed++;
  62.                 break;
  63.             }
  64.         }
  65.     }
  66.     return messages_removed;
  67. }
  68. function notify_user(messages_removed)
  69. {
  70.     var output_owner = document.getElementById(CONFIG.notification_block_id);
  71.     if (output_owner) {
  72.         // prepare text
  73.         var notification_text = "";
  74.         if (messages_removed) {
  75.             notification_text = "Скрыто: " + messages_removed + ".";
  76.         }
  77.         // insert text
  78.         if (notification_text.length != 0) {
  79.             var output_el = document.createElement("div");
  80.             output_el.textContent = notification_text;
  81.             output_el.setAttribute("style", CONFIG.notification_wrapper_style);
  82.             if (CONFIG.notification_is_at_top) {
  83.                 output_owner.insertBefore(output_el, output_owner.firstChild);
  84.             }else{
  85.                 output_owner.appendChild(output_el);
  86.             }
  87.         }
  88.     }
  89. }
  90. var messages_removed = remove_blocked();
  91. notify_user(messages_removed);
  92. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement