RU AdList JS Fixes

try to take over the world!

当前为 2016-05-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         RU AdList JS Fixes
// @namespace    ruadlist_js_fixes
// @version      0.2
// @description  try to take over the world!
// @author       lainverse & dimisa
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var qSelect = document.querySelector,
        qSelectAll = document.querySelectorAll,
        nRemove = function(node) {
            node.parentNode.removeChild(node);
        },
        scissors = function(selector, words) {
            var nodes = document.querySelectorAll(selector),
                i = nodes.length,
                ret = false;
            while (i--)
                if (words.test(nodes[i].innerHTML)) {
                    nodes[i].parentNode.removeChild(nodes[i]);
                    ret = true;
                }
            return ret;
        };

    var scripts = {};
    scripts['fs.to'] = function() {
        var divs = document.getElementsByTagName('div');
        var re = /\w{1,5}\d{1,5}\w{1,5}\d{1,5}/;
        for(var i = 0; i < divs.length; i++)
            if(re.test(divs[i].className))
                divs[i].style.display = 'none';

        var style = document.head.appendChild( document.createElement('style') );
        style.type = 'text/css';

        style.sheet.insertRule(['.b-aplayer-teasers > a',
                                '.b-player-popup__content > div[class][style="position: relative;"]',
                                'div[class^="b-adproxy"]',
                                'div[id^="admixer_async_"]'
                               ].join(',')+'{display:none!important}', 0);

        if (/\/view_iframe\//i.test(document.location.pathname)) {
            var p = qSelect('#player:not([preload="auto"])'),
                m = qSelect('.main'),
                adStepper = function(p) {
                    if (p.currentTime < p.duration)
                        p.currentTime++;
                },
                cl = function(p) {
                    function skipListener() {
                        p.pause();
                        p.classList.add('m-hidden');
                        setTimeout(adStepper, 1000, p);
                    }
                    p.addEventListener('timeupdate', skipListener, false);
                },
                o = new MutationObserver(function (mut) {
                    mut.forEach(function (e) {
                        for (var i = 0; i < e.addedNodes.length; i++) {
                            if (e.addedNodes[i].id === 'player' &&
                                e.addedNodes[i].nodeName === 'VIDEO' &&
                                e.addedNodes[i].getAttribute('preload') != 'auto') {
                                cl(e.addedNodes[i]);
                            }
                        }
                    });
                });
            if (p.nodeName === 'VIDEO')
                cl(p);
            else
                o.observe(m, {childList: true});
        }
    };
    scripts['brb.to'] = scripts['fs.to'];
    scripts['cxz.to'] = scripts['fs.to'];

    scripts['fishki.net'] = function() {
        scissors('.main-post', /543769|Реклама/);
    };

    scripts['yap.ru'] = function() {
        var words = /member1438|Administration/;
        scissors('form > table[id^="p_row_"]', words);
        var b = qSelectAll('tr > .holder.newsbottom');
        for (var i=0;i<b.length;i++)
            if (words.test(b[i].innerHTML)){
                var row = b[i].parentNode.rowIndex;
                var table = b[i].parentNode.parentNode;
                table.deleteRow(row);
                table.deleteRow(row-1);
                table.deleteRow(row-2);
            }
    };
    scripts['yaplakal.com'] = scripts['yap.ru'];

    scripts['auto.ru'] = function() {
        function check1(sci, i) {
            if (i && !sci('.listing-list > .listing-item, .listing-item_type_fixed.listing-item, div[class*="layout_catalog-inline"], .listing > tbody', /Реклама/))
                setTimeout(check1, 100, sci, i-1);
        }
        function check2(sci, i) {
            if (i && !sci('.sidebar-block, .pager-listing + div[class], div[class$="layout_horizontal"], .card > div[class][style], .sidebar > div[class], .main-page__section + div[class]', /Яндекс\.Директ/))
                setTimeout(check2, 100, sci, i-1);
        }
        check1(scissors, 30);
        check2(scissors, 30);
    };

    scripts['online.anidub.com'] = function() {
        var script = document.createElement('script');
        script.type = "text/javascript";
        script.innerHTML = "function ogonekstart1() {}";
        document.getElementsByTagName('head')[0].appendChild(script);

        var style = document.createElement('style');
        style.type = 'text/css';
        style.appendChild(document.createTextNode('.background {background: none!important;}'));
        style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
        document.head.appendChild(style);
    };

    if (document.domain in scripts) {
        scripts[document.domain]();
    } else if ((document.domain.match(/\./g) || []).length > 1) {
        var domainBlocks = document.domain.split('.'),
            i = domainBlocks.length - 2;
        while(i--) {
            var domain = domainBlocks.slice(-2-i).join('.');
            if (domain in scripts) {
                scripts[domain]();
                break;
            }
        }
    }
})();