自定义浏览器平台信息

自定义浏览器平台信息,以便于你可以自由访问目标网站的移动端或者桌面端。此脚本仅针对JavaScript检测有效,对于服务端检测无效。

  1. // ==UserScript==
  2. // @name Custom browser platform
  3. // @name:zh-CN 自定义浏览器平台信息
  4. // @namespace https://github.com/gam2046/userscript
  5. // @description Customize browser platform information so that you can freely access the mobile or desktop side of the target web site. This script is only valid for JavaScript detection and invalid for server-side detection.
  6. // @description:zh-CN 自定义浏览器平台信息,以便于你可以自由访问目标网站的移动端或者桌面端。此脚本仅针对JavaScript检测有效,对于服务端检测无效。
  7. // @version 2
  8. // @match *://*/*
  9. // @run-at document-start
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_addStyle
  13. // @grant GM_registerMenuCommand
  14. // @supportURL https://github.com/gam2046/userscript/issues/new
  15. // @require https://gf.qytechs.cn/scripts/38445-monkeyconfig/code/MonkeyConfig.js
  16. // @copyright 2018+, forDream <gan2046#gmail.com>
  17. // @author forDream
  18. // ==/UserScript==
  19.  
  20. (function () {
  21. 'use strict';
  22.  
  23. function isMobileDevice() {
  24. try {
  25. document.createEvent("TouchEvent");
  26. return (navigator.maxTouchPoints > 0 || 'ontouchstart' in document.documentElement) &&
  27. window.orientation > -1;
  28. }
  29. catch (e) {
  30. return false;
  31. }
  32. }
  33.  
  34. var originalUA = navigator.userAgent;
  35. var originalPlatform = navigator.platform;
  36.  
  37. var cfg = new MonkeyConfig({
  38. title: 'Custom Platform Information',
  39. menuCommand: true,
  40. params: {
  41. UserAgent: {
  42. type: 'text',
  43. default: originalUA
  44. },
  45. Platform: {
  46. type: 'text',
  47. default: originalPlatform
  48. },
  49. 'Analog mobile device': {
  50. type: 'checkbox',
  51. default: false,
  52. enable: false
  53. },
  54. 'Analog desktop device': {
  55. type: 'checkbox',
  56. default: false,
  57. enable: false
  58. }
  59. }
  60. });
  61.  
  62. var customUA = cfg.get('UserAgent');
  63. var customPlatform = cfg.get('Platform');
  64.  
  65. // 如果同时勾选移动端与桌面端模拟,则忽略桌面端选项
  66. if (true == cfg.get('Analog mobile device')) {
  67. cfg.set('Analog desktop device', false);
  68. window.orientation = 1;
  69. document.documentElement.ontouchstart =
  70. document.documentElement.ontouchmove =
  71. document.documentElement.ontouchend =
  72. document.documentElement.ontouchcancel = function () { };
  73. Object.defineProperty(navigator, 'maxTouchPoints', { get: function () { return 5; } });
  74. } else if (true == cfg.get('Analog desktop device')) {
  75. window.orientation = undefined;
  76. document.documentElement.ontouchstart =
  77. document.documentElement.ontouchmove =
  78. document.documentElement.ontouchend =
  79. document.documentElement.ontouchcancel = undefined;
  80. Object.defineProperty(navigator, 'maxTouchPoints', { get: function () { return 0; } });
  81. }
  82.  
  83. Object.defineProperty(navigator, 'userAgent', { get: function () { return customUA; } });
  84. Object.defineProperty(navigator, 'platform', { get: function () { return customPlatform; } });
  85.  
  86. console.log('Current is mobile ', isMobileDevice());
  87. })();

QingJ © 2025

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