Live-comments unblock

Live-comments unblock. Thanks to https://greatest.deepsurf.us/en/scripts/19993-ru-adlist-js-fixes

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Live-comments unblock
// @name:ru-RU   Разблокировать лайв комментарии
// @namespace    Violentmonkey Scripts
// @match        https://tjournal.ru/*
// @match        https://dtf.ru/*
// @match        https://vc.ru/*
// @version      0.7
// @author       Dmitry
// @description  Live-comments unblock. Thanks to https://greatest.deepsurf.us/en/scripts/19993-ru-adlist-js-fixes
// @description:ru-RU  Разблокировать лайв комментарии. Способ взят из https://greatest.deepsurf.us/en/scripts/19993-ru-adlist-js-fixes
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==
(function () {
    'use strict';
    
    const win = (unsafeWindow || window),
      regex = /e\.isShowBanner/,
      regex2 = /function\((.*?)\){/,
      _bindCall = fun => Function.prototype.call.bind(fun),
      _toString = _bindCall(Function.prototype.toString);
    var isPatched = false;

    function wrapPush(webpack) {
        console.log('wrapPush define');
        let _push = webpack.push.bind(webpack);
        Object.defineProperty(webpack, 'push', {
            get() {
                return _push;
            },
            set(vl) {
                _push = new Proxy(vl, {
                    apply(fun, that, args) {
                        wrapper: {
                            if(isPatched)
                                break wrapper;
                            if (!(args[0]instanceof Array))
                                break wrapper;
                            let funs = args[0][1];
                            if (!(funs instanceof Object && !(funs instanceof Array)))
                                break wrapper;
                            //const noopFunc = (name, text) => () => console.log(`Skip webpack ${name}`, text);
                            let funstr;
                            for (let name in funs) {
                                if(isPatched)
                                    break;
                                if (typeof funs[name] !== 'function')
                                    continue;
                                funstr = _toString(funs[name]);
                                if (regex.test(funstr)) {
                                    isPatched = true;
                                    console.log('find', name);
                                    //console.log('code', funstr);
                                    let a = funstr.match(regex2);
                                    funs[name].a = a[1];
                                    funs[name].c = funstr.replace(regex, 'false').replace(a[0], 'console.log(\'patched ¯\_(ツ)_/¯\');').slice(0, -1);
                                    const handler = {
                                        apply(fun, that, args) {                                        
                                            return Reflect.apply(new Function(fun.a.split(","), fun.c), that, args);
                                        }
                                    }
                                    funs[name] = new Proxy(funs[name], handler);
                                }
                            }
                        }
                        return Reflect.apply(fun, that, args);
                    }
                });
                return true;
            }
        });
        return webpack;
    }

    let _webpackJsonp = wrapPush([]);
    Object.defineProperty(win, 'webpackJsonp', {
        get() {
            return _webpackJsonp;
        },
        set(vl) {
            if (vl === _webpackJsonp)
                return;
            _webpackJsonp = wrapPush(vl);
        }
    });
})();