Mail.ru Multi-session Bypass

Блокировка ограничений мультисессии в почте Mail.ru

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Mail.ru Multi-session Bypass
// @namespace    https://github.com/Computershik73/mailru-multisession-bypass
// @version      1.0.1
// @description  Блокировка ограничений мультисессии в почте Mail.ru
// @author       Ilya Vysotsky
// @match        *://e.mail.ru/*
// @run-at       document-start
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
	
    window.webpackChunk_mail_octavius = window.webpackChunk_mail_octavius ||[];
    const origPush = window.webpackChunk_mail_octavius.push;

    window.webpackChunk_mail_octavius.push = function(...args) {
        const chunk = args[0];    
        const modules = chunk[1]; 

        if (modules) {
            for (let moduleId in modules) {
                let funcStr = modules[moduleId].toString();
                let modified = false;

                if (funcStr.includes('MULTI_COOKIE_RESTRICTION_ENABLED')) {
                    funcStr = funcStr.replace(/[a-zA-Z0-9_$]+\.MULTI_COOKIE_RESTRICTION_ENABLED/g, 'false');
                    modified = true;
                }
               
                if (funcStr.includes('MULTI_COOKIE_ANALITYCS_ENABLED')) {
                     funcStr = funcStr.replace(/[a-zA-Z0-9_$]+\.MULTI_COOKIE_ANALITYCS_ENABLED/g, 'false');
                     modified = true;
                }

                if (funcStr.includes('#multi-session')) {
                    funcStr = funcStr.replace(/["']#multi-session["']/g, '"#inbox"');
                    modified = true;
                }

                if (funcStr.includes('octavius/user-sessions/check')) {
                    funcStr = funcStr.replace(/total:\s*[a-zA-Z0-9_$]+\.length/g, 'total: 0');
                    funcStr = funcStr.replace(/web:\s*[a-zA-Z0-9_$]+\.length/g, 'web: 0');
                    funcStr = funcStr.replace(/d\.fulfilled\.subscribe/g, '/* blocked sub */ d.fulfilled.subscribe');
                    modified = true;
                }

                if (modified) {
                    try {
                        modules[moduleId] = eval('(' + funcStr + ')');
                    } catch (e) {
                        console.error(`Ошибка патчинга модуля ${moduleId}:`, e);
                    }
                }
            }
        }

        return origPush.apply(this, args);
    };

    let realSotaConfig = window.sotaConfig || {};
        
    const configHandler = {
        get: function(target, prop, receiver) {
            if (prop === 'MULTI_COOKIE_RESTRICTION_ENABLED') return false;
            if (prop === 'MULTI_COOKIE_PROMO_ENABLED') return false;
            if (prop === 'authGate') return false;
            if (prop === 'isMultisession') return false;

            const value = Reflect.get(target, prop, receiver);
            if (value && typeof value === 'object') {
                return new Proxy(value, configHandler);
            }
            return value;
        }
    };

    function mutateConfig(cfg) {
        if (!cfg) return;
        try {
            if (cfg.cfg && cfg.cfg.omicron && cfg.cfg.omicron.Config) {
                cfg.cfg.omicron.Config['multi-cookie-restriction-enabled'] = false;
                cfg.cfg.omicron.Config['show-party-informer'] = false; 
            }
        } catch(e) {}
    }

    try {
        const descriptor = Object.getOwnPropertyDescriptor(window, 'sotaConfig');

        if (!descriptor || descriptor.configurable) {
            Object.defineProperty(window, 'sotaConfig', {
                get: function() {
                    return new Proxy(realSotaConfig, configHandler);
                },
                set: function(val) {
                    mutateConfig(val);
                    realSotaConfig = val;
                },
                configurable: true
            });
        } else {
            console.warn('[Mail.ru Bypass] sotaConfig защищен от перезаписи. Использую прямую мутацию.');
            mutateConfig(window.sotaConfig);
        }
    } catch (e) {
        console.warn('[Mail.ru Bypass] Ошибка при установке ловушки на sotaConfig:', e);
        mutateConfig(window.sotaConfig);
    }

    const isForbiddenUrl = (url) => typeof url === 'string' && url.includes('multi-session');

    const origPushState = history.pushState;
    const origReplaceState = history.replaceState;

    history.pushState = function(state, title, url) {
        if (isForbiddenUrl(url)) return;
        return origPushState.apply(this, arguments);
    };

    history.replaceState = function(state, title, url) {
        if (isForbiddenUrl(url)) return;
        return origReplaceState.apply(this, arguments);
    };
	
    const style = document.createElement('style');
    style.innerHTML = `
        #multi-session,
        .multisession-stub,
        [class*="multisession"],
        div[data-qa-id="multisession-stub"] {
            display: none !important;
            opacity: 0 !important;
            pointer-events: none !important;
        }
        
        .application-mail__layout_main {
            display: block !important;
            opacity: 1 !important;
            visibility: visible !important;
        }
    `;
    
    if (document.head || document.documentElement) {
        (document.head || document.documentElement).appendChild(style);
    } else {
        const observer = new MutationObserver(() => {
            if (document.head || document.documentElement) {
                (document.head || document.documentElement).appendChild(style);
                observer.disconnect();
            }
        });
        observer.observe(document, { childList: true, subtree: true });
    }

})();