1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

Simplified code structure

This commit is contained in:
kkapsner 2019-12-12 23:44:02 +01:00
parent 0d331d91a6
commit af1dfe755c
2 changed files with 100 additions and 95 deletions

View File

@ -315,21 +315,25 @@
const changedFunction = changedFunctions[name]; const changedFunction = changedFunctions[name];
const functionStatus = changedFunction.getStatus(undefined, siteStatus, prefs); const functionStatus = changedFunction.getStatus(undefined, siteStatus, prefs);
logging.verbose("status for", name, ":", functionStatus); logging.verbose("status for", name, ":", functionStatus);
if (functionStatus.active){ if (!functionStatus.active) return;
getAllFunctionObjects(windowToProcess, changedFunction).forEach(function(object){ getAllFunctionObjects(windowToProcess, changedFunction).forEach(function(object){
if (object){ if (!object) return;
const original = object[name]; const original = object[name];
const checker = generateChecker({ const checker = generateChecker({
name, changedFunction, siteStatus, original, name, changedFunction, siteStatus, original,
window: windowToProcess, prefs, checkStack, ask, notify window: windowToProcess, prefs, checkStack, ask, notify
}); });
const descriptor = Object.getOwnPropertyDescriptor(object, name); const descriptor = Object.getOwnPropertyDescriptor(object, name);
if (descriptor){ if (!descriptor) return;
if (descriptor.hasOwnProperty("value")){ if (descriptor.hasOwnProperty("value")){
if (changedFunction.fakeGenerator){ if (changedFunction.fakeGenerator){
descriptor.value = exportFunction( descriptor.value = extension.exportFunctionWithName(
changedFunction.fakeGenerator(checker, original, windowToProcess), changedFunction.fakeGenerator(checker, original, windowToProcess),
windowToProcess windowToProcess,
original.name
); );
} }
else { else {
@ -337,18 +341,16 @@
} }
} }
else { else {
descriptor.get = exportFunction(function(){ descriptor.get = extension.exportFunctionWithName(function(){
return exportFunction( return extension.exportFunctionWithName(
changedFunction.fakeGenerator(checker), changedFunction.fakeGenerator(checker),
windowToProcess windowToProcess,
original.name
); );
}, windowToProcess); }, windowToProcess, descriptor.get.name);
} }
Object.defineProperty(object, name, descriptor); Object.defineProperty(object, name, descriptor);
}
}
}); });
}
}); });
} }
function interceptGetters(windowToProcess, siteStatus, {checkStack, ask, notify, prefs}){ function interceptGetters(windowToProcess, siteStatus, {checkStack, ask, notify, prefs}){
@ -356,12 +358,16 @@
const name = changedGetter.name; const name = changedGetter.name;
const functionStatus = changedGetter.getStatus(undefined, siteStatus, prefs); const functionStatus = changedGetter.getStatus(undefined, siteStatus, prefs);
logging.verbose("status for", changedGetter, ":", functionStatus); logging.verbose("status for", changedGetter, ":", functionStatus);
if (functionStatus.active){ if (!functionStatus.active) return;
changedGetter.objectGetters.forEach(function(objectGetter){ changedGetter.objectGetters.forEach(function(objectGetter){
const object = objectGetter(extension.getWrapped(windowToProcess)); const object = objectGetter(extension.getWrapped(windowToProcess));
if (object){ if (!object) return;
const descriptor = Object.getOwnPropertyDescriptor(object, name); const descriptor = Object.getOwnPropertyDescriptor(object, name);
if (descriptor && descriptor.hasOwnProperty("get")){ if (!descriptor) return;
if (descriptor.hasOwnProperty("get")){
const original = descriptor.get; const original = descriptor.get;
const checker = generateChecker({ const checker = generateChecker({
name, changedFunction: changedGetter, siteStatus, original, name, changedFunction: changedGetter, siteStatus, original,
@ -384,15 +390,12 @@
} }
else if ( else if (
changedGetter.valueGenerator && changedGetter.valueGenerator &&
descriptor && descriptor.hasOwnProperty("value") descriptor.hasOwnProperty("value")
){ ){
const protectedAPIFeatures = prefs("protectedAPIFeatures"); const protectedAPIFeatures = prefs("protectedAPIFeatures");
if ( if (
functionStatus.active &&
(
!protectedAPIFeatures.hasOwnProperty(name + " @ " + changedGetter.api) || !protectedAPIFeatures.hasOwnProperty(name + " @ " + changedGetter.api) ||
protectedAPIFeatures[name + " @ " + changedGetter.api] protectedAPIFeatures[name + " @ " + changedGetter.api]
)
){ ){
switch (functionStatus.mode){ switch (functionStatus.mode){
case "ask": case "block": case "fake": case "ask": case "block": case "fake":
@ -418,9 +421,7 @@
else { else {
logging.error("Try to fake non getter property:", changedGetter); logging.error("Try to fake non getter property:", changedGetter);
} }
}
}); });
}
}); });
} }
scope.intercept = function intercept({subject: windowToProcess}, apis){ scope.intercept = function intercept({subject: windowToProcess}, apis){

View File

@ -85,6 +85,10 @@
{ {
"version": "0.5.15RC1", "version": "0.5.15RC1",
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.15RC1-an+fx.xpi" "update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.15RC1-an+fx.xpi"
},
{
"version": "0.5.15RC2",
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.15RC2-an+fx.xpi"
} }
] ]
} }