绕过403

Bypass the local verification that redirects to 403 page

נכון ליום 10-04-2025. ראה הגרסה האחרונה.

// ==UserScript==
// @name         绕过403
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Bypass the local verification that redirects to 403 page
// @author       Brian
// @match        *://*/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Store the original createElement method
    const originalCreateElement = document.createElement;

    // Override createElement to intercept script creation
    document.createElement = function(tagName) {
        // Create the element using the original method
        const element = originalCreateElement.apply(document, arguments);

        // Only intercept script elements
        if (tagName.toLowerCase() === 'script') {
            // Store the original setter
            const originalSrcSetter = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src').set;

            // Override the src property
            Object.defineProperty(element, 'src', {
                set: function(value) {
                    // Check if this is the local verification request
                    if (value && value.includes('127.0.0.1:50018')) {
                        console.log('[Bypass] Intercepted local verification request:', value);

                        // Call the original setter with the URL to maintain script behavior
                        originalSrcSetter.call(this, value);

                        // Override the onerror handler to prevent 403 redirect
                        setTimeout(() => {
                            this.onerror = function(e) {
                                console.log('[Bypass] Prevented redirect to 403 page');

                                // Create a mock response
                                const mockResponse = {
                                    result: window.be.encode(JSON.stringify({
                                        data: [{
                                            UserNo: window._t.lvdunUserNo // Use the same UserNo from the app
                                        }]
                                    }))
                                };

                                // If there's a success handler defined, call it with our mock response
                                if (typeof window.localHandler === 'function') {
                                    console.log('[Bypass] Calling success handler with mock response');
                                    window.localHandler(mockResponse);
                                }

                                // Make sure loading state is completed
                                if (window.z && typeof window.z.done === 'function') {
                                    window.z.done();
                                }

                                if (window.kt && window.kt.commit) {
                                    window.kt.commit("loading/OPPEN_LOADING", {show: false});
                                }

                                return true; // Prevent the default error behavior
                            };

                            // Also override onload to ensure our mock response is used
                            this.onload = function() {
                                console.log('[Bypass] Script loaded, ensuring mock response is used');
                                // The script might define its own localHandler, so we'll wait a bit and then check
                                setTimeout(() => {
                                    if (typeof window.localHandler === 'function') {
                                        const mockResponse = {
                                            result: window.be.encode(JSON.stringify({
                                                data: [{
                                                    UserNo: window._t.lvdunUserNo
                                                }]
                                            }))
                                        };
                                        console.log('[Bypass] Calling success handler with mock response');
                                        window.localHandler(mockResponse);
                                    }
                                }, 100);
                            };
                        }, 0);

                        return;
                    }

                    // For all other scripts, use the original setter
                    originalSrcSetter.call(this, value);
                },
                get: function() {
                    return Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src').get.call(this);
                }
            });
        }

        return element;
    };

    // Create a backup method to handle the AJAX request if it's made directly
    const originalAjax = window.ve && window.ve.ajax;
    if (originalAjax) {
        window.ve.ajax = function(options) {
            if (options.url && options.url.includes('127.0.0.1:50018')) {
                console.log('[Bypass] Intercepted AJAX request to local service');

                // Create a mock response
                const mockResponse = {
                    result: window.be.encode(JSON.stringify({
                        data: [{
                            UserNo: window._t.lvdunUserNo
                        }]
                    }))
                };

                // Call the success callback with our mock response
                if (options.success && typeof options.success === 'function') {
                    setTimeout(() => {
                        options.success(mockResponse);
                    }, 50);
                }

                // Don't actually make the AJAX request
                return;
            }

            // For all other AJAX requests, use the original method
            return originalAjax.apply(this, arguments);
        };
    }

    // Add a global error handler for the specific script
    window.addEventListener('error', function(event) {
        if (event.target && event.target.src && event.target.src.includes('127.0.0.1:50018')) {
            console.log('[Bypass] Caught error event for local service script');
            event.preventDefault();
            event.stopPropagation();
            return true;
        }
    }, true);

    console.log('[Bypass] Local verification bypass script initialized');
})();