Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        govnoscript
  3. // @namespace   http://govnokod.ru
  4. // @description expand hidden comments and hide pidors
  5. // @include     http://govnokod.ru/*
  6. // @include     http://*.govnokod.ru/*
  7. // @exclude     http://govnokod.ru/comments
  8. // @exclude     http://*.govnokod.ru/comments
  9. // @version     1
  10. // @grant       none
  11. // ==/UserScript==
  12.  
  13.  
  14. pidors = ["passiv"]
  15.  
  16.  
  17. function is_pidor(nick) {
  18.   for (var pattern of pidors) {
  19.     re = new RegExp("^" + pattern + "$");
  20.    
  21.     if (re.test(nick)) {
  22.       return true;
  23.     }
  24.   }
  25.  
  26.   return false;
  27. }
  28.  
  29.  
  30. function fixup_comments() {
  31.   var pidor_comments = [];
  32.   var hidden_comments = [];
  33.  
  34.   for (var comment of document.getElementsByClassName("hcomment")) {
  35.     //console.log("Process comment: ", comment, comment.innerHTML);
  36.     var pidor = false;
  37.    
  38.     for (var author of comment.getElementsByClassName("entry-author")) {
  39.       for (var ref of author.getElementsByTagName("A")) {
  40.         if (is_pidor(ref.innerHTML)) {
  41.           //console.log("Hide comment: ", comment, comment.innerHTML);
  42.           pidor_comments.push(comment);
  43.           pidor = true;
  44.         }
  45.         break;
  46.       }
  47.       break;
  48.     }
  49.    
  50.     if (pidor) {
  51.       continue;
  52.     }
  53.    
  54.     for (var body of comment.getElementsByClassName("entry-comment")) {
  55.       if (body.classList.contains("entry-comment-hidden")) {
  56.         //console.log("Unhide comment: ", comment, comment.innerHTML);
  57.         hidden_comments.push(comment);
  58.       }
  59.      
  60.       break;
  61.     }
  62.   }
  63.  
  64.   for (var comment of pidor_comments) {
  65.     for (var body of comment.getElementsByClassName("entry-comment")) {
  66.       if (body.getElementsByClassName("hidden-text").length == 0) {
  67.         body.innerHTML = "<span class=\"hidden-text\"><a href=\"#\" class=\"ajax\">показать все, что скрыто</a></span>" + body.innerHTML
  68.       }
  69.      
  70.       if (!body.classList.contains("entry-comment-hidden")) {
  71.         body.classList.add("entry-comment-hidden")
  72.       }
  73.      
  74.       break;
  75.     }
  76.   }
  77.  
  78.   for (var comment of hidden_comments) {
  79.     for (var body of comment.getElementsByClassName("entry-comment")) {
  80.       for (var elem of body.getElementsByClassName("hidden-text")) {
  81.         if (elem.tagName == "SPAN") {
  82.           body.removeChild(elem);
  83.           break;
  84.         }
  85.       }
  86.       body.classList.remove("entry-comment-hidden");
  87.      
  88.       break;
  89.     }
  90.   }
  91. }
  92.  
  93.  
  94. fixup_comments()
  95.  
  96.  
  97. var observer = new window.MutationObserver(function(mutations, observer) {
  98.   fixup_comments()
  99. });
  100.  
  101. observer.observe(document, {
  102.   subtree: true,
  103.   childList: true
  104. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement