Platform Spoofer

Modify platform Only.

  1. // ==UserScript==
  2. // @name Platform Spoofer
  3. // @namespace https://viayoo.com/
  4. // @version 0.6.1
  5. // @description Modify platform Only.
  6. // @author Via
  7. // @match *://*/*
  8. // @exclude *://*.baidu.*/*
  9. // @exclude *://*.bing.*/*
  10. // @exclude *://*.github.com/*
  11. // @exclude *://*.google.*/*
  12. // @exclude *://*.ifeng.com/*
  13. // @exclude *://*.iqiyi.com/*
  14. // @exclude *://*.mgtv.com/*
  15. // @exclude *://*.pptv.com/*
  16. // @exclude *://*.qq.com/*
  17. // @exclude *://*.sina.com.cn/*
  18. // @exclude *://*.sohu.com/*
  19. // @exclude *://*.v.qq.com/*
  20. // @exclude *://*.yandex.*/*
  21. // @exclude *://github.com/*
  22. // @exclude *://gf.qytechs.cn/*
  23. // @exclude *://rebang.today/*
  24. // @exclude *://scriptcat.org/*
  25. // @exclude *://twitter.com/*
  26. // @exclude *://x.com/*
  27. // @license MIT
  28. // @grant none
  29. // @run-at document-start
  30. // ==/UserScript==
  31.  
  32. (function() {
  33. 'use strict';
  34. const FAKE_PLATFORM = 'Mac';
  35. const spoofNavigator = new Proxy(navigator, {
  36. get(target, prop) {
  37. return prop === 'platform' ? FAKE_PLATFORM : Reflect.get(target, prop);
  38. },
  39. getOwnPropertyDescriptor(target, prop) {
  40. if (prop === 'platform') {
  41. return {
  42. value: FAKE_PLATFORM,
  43. writable: false,
  44. configurable: true,
  45. enumerable: true
  46. };
  47. }
  48. return Object.getOwnPropertyDescriptor(target, prop);
  49. }
  50. });
  51. try {
  52. const descriptor = Object.getOwnPropertyDescriptor(navigator, 'platform');
  53. if (descriptor?.configurable) {
  54. Object.defineProperty(navigator, 'platform', {
  55. get: () => FAKE_PLATFORM,
  56. configurable: true,
  57. enumerable: true
  58. });
  59. } else if (navigator.__defineGetter__) {
  60. navigator.__defineGetter__('platform', () => FAKE_PLATFORM);
  61. }
  62. Object.defineProperty(window, 'navigator', {
  63. value: spoofNavigator,
  64. writable: false,
  65. configurable: true
  66. });
  67. const protoDescriptor = Object.getOwnPropertyDescriptor(Navigator.prototype, 'platform');
  68. if (protoDescriptor?.configurable) {
  69. Object.defineProperty(Navigator.prototype, 'platform', {
  70. get: () => FAKE_PLATFORM,
  71. configurable: true,
  72. enumerable: true
  73. });
  74. }
  75. const originalIndexOf = String.prototype.indexOf;
  76. String.prototype.indexOf = function(searchString) {
  77. if (this === FAKE_PLATFORM) {
  78. if (searchString === 'Win' || searchString === 'Linux' || searchString === 'X11') return -1;
  79. if (searchString === 'Mac') return 0;
  80. }
  81. return originalIndexOf.call(this, searchString);
  82. };
  83.  
  84. } catch (e) {
  85. console.warn('Platform spoofing fallback:', e);
  86. window.navigator = spoofNavigator;
  87. }
  88. Object.freeze(window.navigator);
  89. if (document.readyState === 'loading') {
  90. document.addEventListener('DOMContentLoaded', () => {
  91. if (navigator.platform !== FAKE_PLATFORM) {
  92. Object.defineProperty(window, 'navigator', {
  93. value: spoofNavigator,
  94. writable: false,
  95. configurable: true
  96. });
  97. Object.freeze(window.navigator);
  98. }
  99. }, {
  100. once: true
  101. });
  102. }
  103. })();

QingJ © 2025

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