ok.ru ad blocker

Block advertisements on the ok.ru social network

// ==UserScript==
// @name         ok.ru ad blocker
// @namespace    http://tampermonkey.net/
// @version      0.10
// @description  Block advertisements on the ok.ru social network
// @author       vite
// @match        *://*.ok.ru/*
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==

'use strict';

function adblock()
{
    switch (document.location.host)
    {
        case 'ok.ru':
        case 'www.ok.ru':
            main_processing();
            feed_processing();
            break;
        case 'm.ok.ru':
            var m1 = $('.item.it.feed-card.__adv');
            if (m1.length)
                m1.hide();
            break;
    }
}

function main_processing()
{
    var s1 = $('#hook_Block_FourthCol');
    if (s1.length)
    {
        var child = s1[0].childNodes[0];
        if (child)
        {
            child.hidden = true;
        }
    }
    var s2 = $('#hook_Block_CompactFooter');
    if (s2.length)
    {
        s2.parent().hide();
    }
}

function feed_processing()
{
    var feeds = $('.feed-w');
    for (var i = 0; i < feeds.length; i++)
    {
        var feed = feeds[i];
        if (feed.hidden) continue;
        switch(document.documentElement.lang)
        {
            case 'en':
                if (feed.innerText.includes('\nAd\n'))
                    feed.hidden = true;
                break;
            case 'az':
            case 'tr':
                if (feed.innerText.includes('\nReklam\n'))
                    feed.hidden = true;
                break;
            case 'be':
                if (feed.innerText.includes('\nРэклама\n'))
                    feed.hidden = true;
                break;
            case 'hy':
                if (feed.innerText.includes('\nԳովազդ\n'))
                    feed.hidden = true;
                break;
            case 'ru':
            case 'uk':
            case 'tt':
                if (feed.innerText.includes('\nРеклама\n'))
                    feed.hidden = true;
                break;
            case 'ka':
                if (feed.innerText.includes('\nრეკლამა\n'))
                    feed.hidden = true;
                break;
            case 'kk':
                if (feed.innerText.includes('\nЖарнама\n'))
                    feed.hidden = true;
                break;
            case 'mo':
            case 'ro':
                if (feed.innerText.includes('\nPublicitate\n'))
                    feed.hidden = true;
                break;
            case 'uz':
                if (feed.innerText.includes('\nReklama\n'))
                    feed.hidden = true;
                break;
        }
        if (feed.hidden || feed.childElementCount == 0)
            continue;
        var child = feed.children[0];
        switch (child.className)
        {
            case 'feed js-video-scope __no-ava h-mod':
                child.hidden = true;
                break;
        }
    }
}

document.body.addEventListener("DOMSubtreeModified", adblock);