mYbiib / Universal Link Bypasser

// ==UserScript==
// @name         Universal Link Bypasser
// @namespace    https://openuserjs.org/users/mYbiib
// @version      2.5.2
// @description  Bypassador universal de links encurtados e sistemas anti-adblock
// @author       mYbiib
// @match        *://*/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// @grant        GM_registerMenuCommand
// @license      MIT
// @noframes
// ==/UserScript==

/* jshint esversion: 6 */
/* globals GM_registerMenuCommand */

(function() {
    'use strict';
    
    var config = {
        blockFocusChecks: true,
        enableRightClick: false,
        autoDownload: true,
        bypassDelay: 5
    };

    var services = {
        'gplinks|linkvertise|ouo|shortcm': {
            selectors: ['#skip_button', '.btn-primary'],
            action: 'click'
        },
        'adfly|linkshrink|bcvc': {
            selectors: ['.content > div:nth-child(5)'],
            action: 'waitThenRedirect'
        }
    };

    function Bypasser() {
        this.init();
    }

    Bypasser.prototype = {
        init: function() {
            this.setupMenu();
            this.applyConfig();
            this.startEngine();
        },

        setupMenu: function() {
            if (typeof GM_registerMenuCommand === 'function') {
                GM_registerMenuCommand('⚙️ Configurar', this.showPanel.bind(this));
            }
        },

        applyConfig: function() {
            if(config.blockFocusChecks) this.enableFocusBypass();
            if(config.enableRightClick) this.enableContextMenu();
        },

        startEngine: function() {
            var self = this;
            setInterval(function() {
                self.scanPage();
            }, 2000);
        },

        scanPage: function() {
            var patterns = Object.keys(services);
            for(var i = 0; i < patterns.length; i++) {
                if(new RegExp(patterns[i]).test(location.hostname)) {
                    this.processService(services[patterns[i]]);
                    break;
                }
            }
        },

        processService: function(service) {
            var elements = this.findElements(service.selectors);
            elements.forEach(function(el) {
                this.executeAction(el, service.action);
            }, this);
        },

        findElements: function(selectors) {
            return selectors.reduce(function(acc, selector) {
                var el = document.querySelector(selector);
                return el ? acc.concat(el) : acc;
            }, []);
        },

        executeAction: function(element, action) {
            if(typeof this[action] === 'function') {
                this[action](element);
            }
        },

        click: function(element) {
            element.click();
            this.log('Element clicked: ' + element.tagName);
        },

        waitThenRedirect: function(element) {
            setTimeout(function() {
                window.location.href = element.href;
            }, config.bypassDelay * 1000);
        },

        enableFocusBypass: function() {
            window.onblur = window.onfocus = null;
            Object.defineProperty(document, 'hasFocus', {
                value: function() { return true; }
            });
        },

        enableContextMenu: function() {
            var events = ['contextmenu', 'copy', 'paste'];
            events.forEach(function(event) {
                document.addEventListener(event, function(e) {
                    e.stopPropagation();
                }, true);
            });
        },

        log: function(message) {
            console.log('[Bypasser]', message);
        },

        showPanel: function() {
            var panel = document.createElement('div');
            panel.style.cssText = [
                'position:fixed;top:20px;right:20px;',
                'background:#fff;padding:20px;z-index:9999;',
                'box-shadow:0 2px 10px rgba(0,0,0,0.1);font-family:Arial,sans-serif;'
            ].join('');

            panel.innerHTML = [
                '<h3 style="margin:0 0 15px 0;font-size:16px;">Configurações</h3>',
                '<label style="display:block;margin-bottom:10px;">',
                '<input type="checkbox"', config.blockFocusChecks ? ' checked' : '', '> ',
                'Bloquear verificações de foco</label>',
                '<label style="display:block;margin-bottom:15px;">',
                '<input type="checkbox"', config.enableRightClick ? ' checked' : '', '> ',
                'Ativar clique direito</label>',
                '<button style="padding:5px 15px;cursor:pointer;" onclick="this.parentNode.remove()">',
                'Fechar</button>'
            ].join('');

            document.body.appendChild(panel);
        }
    };

    // Inicialização
    new Bypasser();
})();