1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-11-09 22:58:52 +01:00
CanvasBlocker/lib/modifiedNavigatorAPI.js

96 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-02-27 23:49:00 +01:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
"use strict";
2019-11-28 01:26:35 +01:00
let scope;
2019-02-27 23:49:00 +01:00
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
scope = require.register("./modifiedNavigatorAPI", {});
}
const {checkerWrapper, setProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
2020-01-26 01:11:18 +01:00
const extension = require("./extension");
2019-02-27 23:49:00 +01:00
const navigator = require("./navigator");
let cookieStoreId = false;
scope.setCookieStoreId = function(newCookieStoreId){
if (typeof newCookieStoreId === "string"){
cookieStoreId = (
newCookieStoreId !== "" &&
newCookieStoreId !== "firefox-default"
)? newCookieStoreId: "";
}
};
function getCookieStoreId(){
while (cookieStoreId === false){
2020-01-26 01:11:18 +01:00
extension.waitSync("to wait for cookie store id");
}
return cookieStoreId;
}
2019-02-27 23:49:00 +01:00
scope.changedGetters = navigator.allProperties.map(function(property){
return {
objectGetters: [function(window){return window.Navigator && window.Navigator.prototype;}],
name: property,
getterGenerator: function(checker){
2019-12-12 00:09:53 +01:00
const temp = {
get [property](){
2019-02-27 23:49:00 +01:00
return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, original} = check;
const originalValue = original.call(this, ...args);
const returnValue = navigator.getNavigatorValue(property, getCookieStoreId);
2019-02-27 23:49:00 +01:00
if (originalValue !== returnValue){
notify("fakedNavigatorReadout");
}
return returnValue;
});
}
2019-12-12 00:09:53 +01:00
};
2019-02-27 23:49:00 +01:00
return Object.getOwnPropertyDescriptor(temp, property).get;
}
};
});
scope.changedFunctions = {
estimate: {
objectGetters: [function(window){return window.StorageManager && window.StorageManager.prototype;}],
fakeGenerator: function(checker){
const quota = 10 * 1024 * 1024 * 1024;
return function estimate(){
return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, original, window} = check;
const This = this;
return new window.Promise(async function(resolve, reject){
try {
const originalValue = await original.call(This, ...args);
if (originalValue.quota !== quota){
originalValue.usage = Math.min(
quota,
Math.max(0, quota - (originalValue.quota - originalValue.usage))
);
originalValue.quota = quota;
notify("fakedNavigatorReadout");
}
resolve(originalValue);
}
catch (error){
reject(error);
}
});
});
};
}
}
};
setProperties(scope.changedFunctions, scope.changedGetters, {
2019-12-10 15:07:22 +01:00
type: "readout",
getStatus: getStatusByFlag("protectNavigator"),
api: "navigator"
2019-02-27 23:49:00 +01:00
});
}());