-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcontentscript.js
More file actions
28 lines (25 loc) · 798 Bytes
/
contentscript.js
File metadata and controls
28 lines (25 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// see https://stackoverflow.com/questions/23202136/changing-navigator-useragent-using-chrome-extension
var actualCode = '(' + function() {
// Get the correct platform for navigator.userAgent
var candidates = ["Android", "iPhone", "iPod", "iPad"];
var modifiedPlatform;
for(var maybe of candidates) {
if(navigator.userAgent.match(maybe)) {
modifiedPlatform = maybe;
break;
}
}
if(!modifiedPlatform) {
return;
}
// Reset platform
Object.defineProperty(navigator, 'platform', {
get: function(){
return modifiedPlatform;
}});
} + ')();';
// Inject custom js
var s = document.createElement('script');
s.textContent = actualCode;
document.documentElement.appendChild(s);
s.remove();