STagila post hider script

Скрывает определенные посты с форума.

La data de 29-08-2016. Vezi ultima versiune.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         STagila post hider script
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Скрывает определенные посты с форума.
// @author       [email protected] (eXponenta)
// @match        http://stagila.ru/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //Load
    // возвращает cookie с именем name, если есть, если нет, то undefined
    function getCookie(name) {
        var matches = document.cookie.match(new RegExp(
            "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
        ));
        return matches ? decodeURIComponent(matches[1]) : undefined;
    }
    var replaceAll = function(str, sel, to){
        while(str.indexOf(sel)>-1){
            str=str.replace(sel,to);
        }
        return str;
    };
    
    var filter = Array.prototype.filter;

    var preset = "<a id='ext_hide_click' href='javascript:document.ext_showPost(#postindex, true)' style='color:red;font-size:10pt; display:none'>Сообщение скрыто, показать? </a>" +
        "<a id='ext_show_click' style='color:red;font-size:10pt; display:none' href='javascript:document.ext_showPost(#postindex, false)'> Сообщение показано, скрыть? </a>"+
        "</span> <span style='float:right; display:inline'><input type='button' value='Скрывать' onclick='document.ext_filter(#postindex,true);' /> <input type='button' value='Не скрывать' onclick='document.ext_filter(#postindex,false);' />";

    var blacklist = [];
    var n = getCookie("stagila_black_list");
    if(n !== undefined){
        blacklist = n.split(",");
    }

    var posts = document.querySelectorAll(".post_block");

    posts.forEach(function(e,ind,arr){
        var newSpan = document.createElement("div");
        newSpan.id = "ext_hided";
        newSpan.style = "display: inline;";
        newSpan.innerHTML = replaceAll(preset, "#postindex",ind);
        e.querySelector(".row2").appendChild(newSpan);
    });
    

    document.ext_showPost = function(id, show) {
        var p = posts;
        p[id].querySelector(".post_body").style.display=show?'':'none';
        p[id].querySelector(".author_info").style.display = show?'':'none';

        p[id].querySelector('#ext_show_click').style.display = show?'':'none';
        p[id].querySelector('#ext_hide_click').style.display = show?'none':'';
    };
    
    posts.forEach(function(e, ind, arr){
        var name = e.querySelector("[itemprop=name]").innerHTML;
        if( blacklist.indexOf(name) > -1)
            document.ext_showPost(ind,false);
    });
    
   document.ext_filter =  function(e, add){
       var name = posts[e].querySelector("[itemprop=name]").innerHTML;
       var b = blacklist;
       if(add){
           b.push(name);
       }
       else{
           var i = blacklist.indexOf(name);
           if(i > -1){
               b.splice(i, 1);
           }
       }
       var date = new Date();
       date.setDate(date.getDate() + 30);
       document.cookie = "stagila_black_list="+b.join(',') + "; expires=" + date.toUTCString() +";";
       window.location.reload();
   };


})();