Platform Spoofer

Modify platform Only.

目前為 2025-03-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Platform Spoofer
// @namespace    https://viayoo.com/
// @version      0.4
// @description  Modify platform Only.
// @author       Via
// @match        *://*/*
// @exclude      *://rebang.today/*
// @exclude      *://*.github.com/*
// @exclude      *://scriptcat.org/*
// @exclude      *://gf.qytechs.cn/*
// @exclude      *://github.com/*
// @exclude      *://*.google.*/*
// @exclude      *://x.com/*
// @exclude      *://twitter.com/*
// @exclude      *://*.bing.*/*
// @exclude      *://*.baidu.*/*
// @exclude      *://*.yandex.*/*
// @exclude      *://*.iqiyi.com/*
// @exclude      *://*.qq.com/*
// @exclude      *://*.v.qq.com/*
// @exclude      *://*.sohu.com/*
// @exclude      *://*.mgtv.com/*
// @exclude      *://*.ifeng.com/*
// @exclude      *://*.pptv.com/*
// @exclude      *://*.sina.com.cn/*
// @license      MIT
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const FAKE_PLATFORM = 'Mac';
    const platformGetter = () => FAKE_PLATFORM;
    if (navigator.platform === FAKE_PLATFORM) return;
    const descriptor = Object.getOwnPropertyDescriptor(navigator, 'platform');
    if (descriptor?.configurable) {
        Object.defineProperty(navigator, 'platform', {
            get: platformGetter,
            configurable: true,
            enumerable: true
        });
        if (navigator.platform === FAKE_PLATFORM) return;
    } else if (navigator.__defineGetter__) {
        navigator.__defineGetter__('platform', platformGetter);
        if (navigator.platform === FAKE_PLATFORM) return;
    }

    const spoofNavigator = new Proxy(navigator, {
        get(target, prop) {
            return prop === 'platform' ? FAKE_PLATFORM : Reflect.get(target, prop);
        }
    });

    try {
        Object.defineProperty(window, 'navigator', {
            value: spoofNavigator,
            writable: false,
            configurable: true
        });
    } catch (e) {
        console.warn('Navigator redefinition failed:', e);
        window.navigator = spoofNavigator;
    }

    const protoDescriptor = Object.getOwnPropertyDescriptor(Navigator.prototype, 'platform');
    if (protoDescriptor?.configurable) {
        Object.defineProperty(Navigator.prototype, 'platform', {
            get: platformGetter,
            configurable: true,
            enumerable: true
        });
    }
    const originalIndexOf = String.prototype.indexOf;
    const blockedTerms = new Set(['Win', 'Linux', 'X11']);
    String.prototype.indexOf = function(searchString) {
        if (this === FAKE_PLATFORM) {
            if (blockedTerms.has(searchString)) return -1;
            if (searchString === 'Mac') return 0;
        }
        return originalIndexOf.call(this, searchString);
    };

    // 仅在必要时添加DOMContentLoaded监听
    if (document.readyState === 'loading' && navigator.platform !== FAKE_PLATFORM) {
        document.addEventListener('DOMContentLoaded', () => {
            if (navigator.platform !== FAKE_PLATFORM) {
                Object.defineProperty(window, 'navigator', {
                    value: new Proxy(navigator, {
                        get: (target, prop) => prop === 'platform' ? FAKE_PLATFORM : target[prop]
                    }),
                    writable: false
                });
            }
        }, {
            once: true
        });
    }
})();

QingJ © 2025

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