|
|
@ -79,9 +79,12 @@ var navigatorSpoofer = " \
|
|
|
|
var pos = spoofedUserAgent.indexOf('/'); \n \
|
|
|
|
var pos = spoofedUserAgent.indexOf('/'); \n \
|
|
|
|
var appName = pos === -1 ? '' : spoofedUserAgent.slice(0, pos); \n \
|
|
|
|
var appName = pos === -1 ? '' : spoofedUserAgent.slice(0, pos); \n \
|
|
|
|
var appVersion = pos === -1 ? spoofedUserAgent : spoofedUserAgent.slice(pos + 1); \n \
|
|
|
|
var appVersion = pos === -1 ? spoofedUserAgent : spoofedUserAgent.slice(pos + 1); \n \
|
|
|
|
Object.defineProperty(navigator, 'userAgent', { get: function(){ return spoofedUserAgent; } }); \n \
|
|
|
|
Object.defineProperty(navigator, 'userAgent', { value: spoofedUserAgent }); \n \
|
|
|
|
Object.defineProperty(navigator, 'appName', { get: function(){ return appName; } }); \n \
|
|
|
|
Object.defineProperty(navigator, 'appName', { value: appName }); \n \
|
|
|
|
Object.defineProperty(navigator, 'appVersion', { get: function(){ return appVersion; } }); \n \
|
|
|
|
Object.defineProperty(navigator, 'appVersion', { value: appVersion }); \n \
|
|
|
|
|
|
|
|
var c = document.currentScript, \n \
|
|
|
|
|
|
|
|
p = c && c.parentNode; \n \
|
|
|
|
|
|
|
|
if ( p ) { p.removeChild(c); } \n \
|
|
|
|
} catch (e) { \n \
|
|
|
|
} catch (e) { \n \
|
|
|
|
} \n \
|
|
|
|
} \n \
|
|
|
|
})();";
|
|
|
|
})();";
|
|
|
@ -102,17 +105,35 @@ var injectNavigatorSpoofer = function(spoofedUserAgent) {
|
|
|
|
if ( spoofedUserAgent === navigator.userAgent ) {
|
|
|
|
if ( spoofedUserAgent === navigator.userAgent ) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var script = document.createElement('script');
|
|
|
|
var parent = document.head || document.documentElement,
|
|
|
|
script.type = 'text/javascript';
|
|
|
|
scriptText = navigatorSpoofer.replace('{{ua-json}}', JSON.stringify(spoofedUserAgent)),
|
|
|
|
script.id = 'umatrix-ua-spoofer';
|
|
|
|
script = document.createElement('script');
|
|
|
|
var js = document.createTextNode(navigatorSpoofer.replace('{{ua-json}}', JSON.stringify(spoofedUserAgent)));
|
|
|
|
script.setAttribute('type', 'text/javascript');
|
|
|
|
script.appendChild(js);
|
|
|
|
script.setAttribute('id', 'umatrix-ua-spoofer');
|
|
|
|
|
|
|
|
script.appendChild(document.createTextNode(scriptText));
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
parent.appendChild(script);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uMatrix/issues/771
|
|
|
|
|
|
|
|
var spoofer = document.querySelector('script#umatrix-ua-spoofer');
|
|
|
|
|
|
|
|
if ( spoofer !== null ) {
|
|
|
|
|
|
|
|
spoofer.parentNode.removeChild(spoofer);
|
|
|
|
|
|
|
|
script = document.createElement('script');
|
|
|
|
|
|
|
|
script.setAttribute('type', 'text/javascript');
|
|
|
|
|
|
|
|
script.setAttribute('id', 'umatrix-ua-spoofer');
|
|
|
|
|
|
|
|
script.setAttribute('src', 'data:application/javascript;base64,' + window.btoa(scriptText));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
var parent = document.head || document.documentElement;
|
|
|
|
|
|
|
|
parent.appendChild(script);
|
|
|
|
parent.appendChild(script);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
catch (ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
spoofer = document.querySelector('script#umatrix-ua-spoofer');
|
|
|
|
|
|
|
|
if ( spoofer !== null ) {
|
|
|
|
|
|
|
|
spoofer.parentNode.removeChild(spoofer);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The port will never be used again at this point, disconnecting allows
|
|
|
|
// The port will never be used again at this point, disconnecting allows
|
|
|
|