VK posts filter

Скрывает рекламные и политические посты в vk.com.

Tính đến 10-09-2016. Xem phiên bản mới nhất.

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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            VK posts filter
// @name:en         VK posts filter
// @namespace       FIX
// @version         0.1
// @description     Скрывает рекламные и политические посты в vk.com.
// @description:en  Hide ad and political posts from vk.com.
// @copyright		2016, raletag
// @author			raletag
// @supportURL      http://greasyfork.org/ru/forum/messages/add/raletag
// @include         *://vk.com/*
// @exclude         *://vk.com/*.php*
// @grant           GM_addStyle
// ==/UserScript==

(function() {
    'use strict';
    var
    ads = 'vk.com\/app|побед(a|у) (в сражении|над боссом)|я повысил(|a) уровень|я тебя обогнал|вступай(|те) в|расска(зать|жите) дру(зьям|гу) про запись|сдела(й|йте|ете) репост|добав(ь|те|ляем) (активн(ого|ых))|(пиар(|ся|ьтесь) тут)|подпи(шись|саться|сывайся) на|активно добавля(й|ем)|(быть|стать) подписчиком|уровень в игре|получить бесплатно',
    politiс = 'выборы в|правительств|националист|оппозици|петици|митинг|парламент|фальсификац|госдум|арест',
    regexp = new RegExp('(' + ads + '|' + politiс +')', 'mi'),
    showheader = true; // false - полностью скрывать пост

    if (showheader === true) GM_addStyle('.post_header_fix {padding: 15px 20px 15px!important;}');

    function filter (e) {
        var text = e.querySelector('.wall_text');
        if (e.querySelector('a.lnk[href*="vk.com/app"]') || (text && regexp.test(text.innerText) === true)) {
            if (showheader === true) {
                e.querySelector('.post_header').classList.add('post_header_fix');
                e.querySelector('.post_content').style.display = "none";
            } else {
                e.style.display = "none";
            }
        }
    }

    var links = document.querySelectorAll('div[data-post-id]');
    for (var i = links.length - 1; i >= 0; --i) {
        filter (links[i]);
    }

    var o = new MutationObserver(function(ms){
        ms.forEach(function(m){
            m.addedNodes.forEach(function(n){
                if (n.nodeType !== Node.ELEMENT_NODE) {
                    return;
                } else if (n.getAttribute('data-post-id')) {
                    filter (n);
                } else {
                    var links = n.querySelectorAll('div[data-post-id]');
                    for (var i = links.length - 1; i >= 0; --i) {
                        filter (links[i]);
                    }
                }
            });
        });
    });
    o.observe(document.body, {childList: true, subtree: true});
})();