VK posts filter

Скрывает рекламные и политические посты в vk.com. Высокое быстродействие в сравнении с аналогичными скриптами.

Från och med 2016-09-17. Se den senaste versionen.

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

(function() {
    'use strict';
    console.time('VK posts filter load');
    var
    ads = 'побед(a|у) (в сражении|над боссом)|я повысил(|a) уровень|я тебя обогнал|вступай(|те) в|расска(зать|жите) дру(зьям|гу) про запись|сдела(й|йте|ете|ть) репост|добав(ь|те|ляем|ляй) (активн(ого|ых))|(пиар(|ся|ьтесь) (тут|здесь))|подпи(шись|саться|сывайся|шитесь) на|активно добавля(й|ем)|(быть|стать|будьте|станьте) (подписчиком|участником)|уровень в игре|получить бесплатно|зач(e|ё)тны(e|й) кореш(|а)|победител(ь|я|и) розыгрыш|победил(|а) босс|я одержал(|a) побед|внимание розыгрыш|добав(ь|ьте|ляйтесь|лю|ляю|ляемся|ить) (в дру|его|её|их|все|за|через)|(за|сделавшему) репост|при(ми|мите|нять|нимайте) участие|результат(|ы) конкурс|(прошел(|a)|меня|достиг(|ла)) [0-9]{1,} уров|зака(жи|жите|зывай|зывайте) по акции|я выполнил(|а) задание|успей(|те) (вступить|подписаться)|cмотреть ответ|читать продолжение|только для участников сообществ',
    urlads = 'vk\.com\/(app|top_cards|fotomimi|flower_cards|megatest|beauty_cards|fotomagic_su|we_love_cards|denegnoe_derevo|skanograf|pr0werka|musicwars|love1v|vkvoprosnik)|(clickerwars|schoolclicker)\.com\/vk|denezhnojederevo\.ru|ref=|act=invite&group_id=',
    politiс = 'выборы в|правительств|националист|оппозици|ополчен|петици|митинг|парламент|фальсификац|госдум|арест|террорист|теракт|антигосударств|#политика',
    regexp = new RegExp('(' + ads + '|' + urlads + '|' + politiс +')', 'mi'),
    showheader = true; // false - полностью скрывать пост

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

    function filter (e) {
        var text = e.querySelector('.wall_post_text');
        e.setAttribute('vpf', '1');
        if (e.querySelector('a.lnk[href*="vk.com/app"]') || (text && (regexp.test(text.textContent) === true))) {
            if (showheader === true) {
                e.querySelector('.post_header').classList.add('post_header_fix');
                e.querySelector('.post_content').innerHTML = '';
            } else {
                e.innerHTML = '';
            }
        }
    }

    if (!/^\/wall(.*)_(.*)/.test(window.location.pathname)) {
        for (var links = document.body.querySelectorAll('div[data-post-id]:not([vpf])'), i = links.length - 1; i >= 0; --i) {
            filter (links[i]);
        }
    }

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