RU AdList JS Fixes

try to take over the world!

目前為 2016-05-27 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

(function() {
    'use strict';

    if (!/firefox/i.test(navigator.userAgent)) { // scripts for non-Firefox browsers
        // https://greasyfork.org/scripts/19144-websuckit/
        (function() {
            var to_block =[
                'et-code.ru',
                'wsp.marketgid.com',
                'trafmag.com',
                'ws.hghit.com'
            ];
            var ws = window.WebSocket;
            window.WebSocket = new Proxy(ws, {
                construct: function(e,i){
                    console.log('Opening WebSocket on', i[0], '…');
                    var d = i[0].match(/:\/\/[^:/]+/)[0];
                    if (d && to_block.indexOf(d.substring(3)) > -1) {
                        console.log("Nope! Not gonna happen!");
                        return {};
                    } else return new e(i[0],i[1]);
                }
            });
        })();
        // https://greasyfork.org/scripts/14720-it-s-not-important
        (function(){
            var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
                rplsf = function(str,grp){return grp;};

            function unimportanter(el, si) {
                if (!imptt.test(si) || el.style.display == 'none')
                    return 0; // get out if we have nothing to do here
                var so = si.replace(imptt, rplsf), ret = 0;
                if (si != so) {
                    ret = 1;
                    el.setAttribute('style', so);
                }
                return ret;
            }

            function logger(c) {
                if (c) console.log('Some page elements became a bit less important.');
            }

            function checkTarget(m, c) {
                var si = m.getAttribute ? m.getAttribute('style') : null;
                if (si && si.indexOf('!') > -1)
                    c+=unimportanter(m, si);
                return c;
            }

            function checkNodes(m, c) {
                var i = m.length;
                while(i--)
                    c = checkTarget(m[i], c);
                return c;
            }

            var observer = new MutationObserver(function(mutations) {
                setTimeout(function(m) {
                    var i = m.length, c = 0;
                    while(i--) {
                        if (m[i].target)
                            c = checkTarget(m[i].target, c);
                        if (m[i].addedNodes.length)
                            c = checkNodes(m[i].addedNodes, c);
                    }
                    logger(c);
                },0,mutations);
            });

            observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });

            window.addEventListener ("load", function(){
                var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
                while(i--) {
                    c+= checkTarget(imp[i], c);
                }
                logger(c);
            }, false);
        })();
    }

    document.addEventListener ("DOMContentLoaded", function() {
        var nRemove = function(node) {
            node.parentNode.removeChild(node);
        },
            scissors = function(selector, words, block) {
                var nodes = document.querySelectorAll(selector),
                    i = nodes.length,
                    toRemove = [],
                    ret = false;
                while (i--)
                    if (words.test(nodes[i].innerHTML)) {
                        if (!block) {
                            toRemove.push(nodes[i]);
                        } else {
                            var p = nodes[i],
                                iterFunc = block.siblings > 0 ? 'nextSibling' : 'previousSibling',
                                siblings = Math.abs(block.siblings) || 0;
                            while(block.parent &&
                                  p !== document.body &&
                                  p.tagName.toLowerCase() !== block.parent) {
                                p = p.parentNode;
                            }
                            if (p !== document.body) {
                                toRemove.push(p);
                                while(siblings) {
                                    p = p[iterFunc];
                                    toRemove.push(p);
                                    if (p.tagName) siblings--; //don't count text nodes
                                }
                            }
                        }
                        ret = true;
                    }
                i = toRemove.length;
                while(i--)
                    toRemove[i].parentNode.removeChild(toRemove[i]);
                return ret;
            };

        var scripts = {};
        scripts['fs.to'] = function() {
            function skipClicker(i) {
                if (!i) return;
                var skip = document.querySelector('.b-aplayer-banners__close');
                if (skip)
                    skip.click();
                else
                    setTimeout(skipClicker, 100, i-1);
            }
            setTimeout(skipClicker, 100, 30);

            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 = document.querySelector('#player:not([preload="auto"])'),
                    m = document.querySelector('.main'),
                    adStepper = function(p) {
                        if (p.currentTime < p.duration)
                            p.currentTime++;
                    },
                    cl = function(p) {
                        function skipListener() {
                            p.pause();
                            if (!p.classList.contains('m-hidden'))
                                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['hdrezka.me'] = function() {
            scissors('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
        };

        scripts['yap.ru'] = function() {
            var words = /member1438|Administration/;
            scissors('form > table[id^="p_row_"]', words);
            scissors('tr > .holder.newsbottom', words, {parent:'tr', siblings:-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);
        };

        var domain = document.domain;
        while (domain.indexOf('.') + 1) {
            if (domain in scripts) {
                scripts[domain]();
                break;
            }
            domain = domain.slice(domain.indexOf('.') + 1);
        }
    });
})();