Greasy Fork is available in English.

ok.ru ad blocker

Block advertisements on the ok.ru social network

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

'use strict';

function hide_ads()
{
    var host = document.location.host;
    if (host == 'www.ok.ru')
        host = 'ok.ru';

    switch (host)
    {
        case 'ok.ru':
            var token = 'Реклама';
            feed_processing(token);
            left_column_processing(token);
            right_column_processing();
            break;
        case 'm.ok.ru':
            var m1 = $('.item.it.feed-card.__adv');
            if (m1.length)
                m1.hide();
            break;
    }
}

function feed_processing(token)
{
    var feeds = $('.feed-w');
    for (var i = 0; i < feeds.length; i++)
    {
        var feed = feeds[i];
        if (feed.hidden) continue;
        if (feed.innerText.includes(token))
        {
            feed.hidden = true;
        }
        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;
        }
    }
}

function left_column_processing(token)
{
    var l_col = $('#leftColumn');
    if (l_col.length > 0)
    {
        for (var i = 0; i < l_col[0].childElementCount; i++)
        {
            var node = l_col[0].children[i];
            if (node.hidden) continue;
            if (node.innerText.includes(token))
            {
                node.hidden = true;
            }
        }
    }
}

function right_column_processing()
{
    var r_col = $('#hook_Block_FourthCol');
    if (r_col.length > 0)
    {
        for (var i = 0; i < r_col[0].childElementCount; i++)
        {
            var node = r_col[0].children[i];
            if (node.hidden) continue;
            if (node.innerText.includes('.ru') ||
                node.innerText.includes('.рф') ||
                node.innerText.includes('.com') ||
                node.innerText.includes('.net'))
            {
                node.hidden = true;
            }
        }
    }
}

document.addEventListener("DOMContentLoaded", hide_ads);
document.addEventListener("DOMSubtreeModified", hide_ads);