Created
March 14, 2023 00:26
-
-
Save albert-zhang/ce54990730367882dc749333037e2ffd to your computer and use it in GitHub Desktop.
modify the UA of chrome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var actualCode = '(' + function() { | |
'use strict'; | |
var navigator = window.navigator; | |
var modifiedNavigator; | |
if ('userAgent' in Navigator.prototype) { | |
// Chrome 43+ moved all properties from navigator to the prototype, | |
// so we have to modify the prototype instead of navigator. | |
modifiedNavigator = Navigator.prototype; | |
} else { | |
// Chrome 42- defined the property on navigator. | |
modifiedNavigator = Object.create(navigator); | |
Object.defineProperty(window, 'navigator', { | |
value: modifiedNavigator, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
} | |
// Pretend to be Windows XP | |
Object.defineProperties(modifiedNavigator, { | |
userAgent: { | |
// value: navigator.userAgent.replace(/\([^)]+\)/, 'Windows NT 5.1'), | |
value: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 wxwork/3.1.3 MicroMessenger/7.0.1 Language/zh', | |
configurable: false, | |
enumerable: true, | |
writable: false | |
}, | |
// appVersion: { | |
// value: navigator.appVersion.replace(/\([^)]+\)/, 'Windows NT 5.1'), | |
// configurable: false, | |
// enumerable: true, | |
// writable: false | |
// }, | |
// platform: { | |
// value: 'Win32', | |
// configurable: false, | |
// enumerable: true, | |
// writable: false | |
// }, | |
}); | |
} + ')();'; | |
var s = document.createElement('script'); | |
s.textContent = actualCode; | |
document.documentElement.appendChild(s); | |
s.remove(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "chage-navigator-ua", | |
"description": "chage-navigator-ua", | |
"version": "1", | |
"manifest_version": 2, | |
"content_scripts": [{ | |
"run_at": "document_start", | |
"js": ["cs.js"], | |
"matches": [ | |
"*://*/*" | |
] | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment