refactor: block script

This commit is contained in:
Andrei O 2022-04-05 18:57:34 +03:00
parent 6545e1ffe8
commit fffba0ae00
No known key found for this signature in database
GPG Key ID: B961E5B68389457E

View File

@ -1,50 +1,26 @@
let nav = function Navigator() {}; class Navigator {
let copyNavRef = window.navigator; constructor(copyNavRef) {
nav = nav.bind(function () { this.name = 'Navigator';
return window.navigator; this.prototype = copyNavRef;
}); for (let prop in copyNavRef) {
newNav = new nav(); if (prop === 'brave') {
const navClones = {
userAgent: window.navigator.userAgent,
appVersion: window.navigator.appVersion,
platform: window.navigator.platform,
vendor: window.navigator.vendor,
language: window.navigator.language,
oscpu: window.navigator.oscpu,
cookieEnabled: true,
appCodeName: window.navigator.appCodeName,
appName: window.navigator.appName,
product: window.navigator.product,
geolocation: window.navigator.geolocation,
onLine: window.navigator.onLine,
sendBeacon: window.navigator.sendBeacon.bind(window.navigator),
getBattery: window.navigator.getBattery.bind(window.navigator),
vibrate: window.navigator.vibrate.bind(window.navigator),
share: window.navigator.share.bind(window.navigator),
canShare: window.navigator.canShare.bind(window.navigator),
registerProtocolHandler: window.navigator.registerProtocolHandler.bind(window.navigator),
requestMediaKeySystemAccess: window.navigator.requestMediaKeySystemAccess.bind(window.navigator),
requestMIDIAccess: window.navigator.requestMIDIAccess.bind(window.navigator),
bluetooth: window.navigator.bluetooth.bind(window.navigator),
onLine: window.navigator.onLine,
};
const skipPropList = [...Object.keys(navClones), 'brave'];
for (let prop in window.navigator) {
if (skipPropList.includes(prop)) {
continue; continue;
} }
newNav[prop] = copyNavRef[prop]; Object.defineProperty(this, prop, {
} value: typeof copyNavRef[prop] === 'function' ? copyNavRef[prop].bind(copyNavRef) : copyNavRef[prop],
for (let prop in navClones) {
navClones.hasOwnProperty(prop) &&
Object.defineProperty(newNav, prop, {
value: navClones[prop],
writable: true, writable: true,
enumerable: false,
}); });
}
}
} }
Navigator = Navigator.bind(window.navigator);
newNav = new Navigator(window.navigator);
delete window.navigator.__proto__.brave;
newNav.__proto__.__proto__ = window.navigator.__proto__;
Object.defineProperty(window, 'navigator', { Object.defineProperty(window, 'navigator', {
value: newNav, value: newNav,
writable: true, writable: false,
enumerable: true, enumerable: false,
configurable: true, configurable: false,
}); });