Baidu Netdisk UA Switcher

Force User-Agent to pan.baidu.com for specific domains

当前为 2025-03-25 提交的版本,查看 最新版本

// ==UserScript==
// @name         Baidu Netdisk UA Switcher
// @namespace    https://gf.qytechs.cn
// @version      1.2
// @description  Force User-Agent to pan.baidu.com for specific domains
// @author       Andy
// @match        *://resource.qblb.net/*
// @match        *://pan.baidu.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 自定义User-Agent
    const baiduUA = "pan.baidu.com";

    // 覆盖XMLHttpRequest的open方法
    const originalXhrOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
        this.setRequestHeader('User-Agent', baiduUA);
        originalXhrOpen.call(this, method, url, async, user, password);
    };

    // 覆盖fetch请求
    window.fetch = async (...args) => {
        const [url, options] = args;
        const newOptions = {
            ...options,
            headers: {
                ...(options?.headers || {}),
                'User-Agent': baiduUA
            }
        };
        return window.fetch(url, newOptions);
    };

    // 尝试修改navigator.userAgent(可能失败)
    try {
        Object.defineProperty(navigator, 'userAgent', {
            value: baiduUA,
            writable: true
        });
    } catch (error) {
        console.log('Failed to modify navigator.userAgent:', error.message);
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址