mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-31 09:01:56 +01:00
Simplified code structure
This commit is contained in:
parent
0d331d91a6
commit
af1dfe755c
191
lib/intercept.js
191
lib/intercept.js
@ -315,40 +315,42 @@
|
|||||||
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){
|
|
||||||
if (object){
|
getAllFunctionObjects(windowToProcess, changedFunction).forEach(function(object){
|
||||||
const original = object[name];
|
if (!object) return;
|
||||||
const checker = generateChecker({
|
|
||||||
name, changedFunction, siteStatus, original,
|
const original = object[name];
|
||||||
window: windowToProcess, prefs, checkStack, ask, notify
|
const checker = generateChecker({
|
||||||
});
|
name, changedFunction, siteStatus, original,
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
window: windowToProcess, prefs, checkStack, ask, notify
|
||||||
if (descriptor){
|
|
||||||
if (descriptor.hasOwnProperty("value")){
|
|
||||||
if (changedFunction.fakeGenerator){
|
|
||||||
descriptor.value = exportFunction(
|
|
||||||
changedFunction.fakeGenerator(checker, original, windowToProcess),
|
|
||||||
windowToProcess
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
descriptor.value = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
descriptor.get = exportFunction(function(){
|
|
||||||
return exportFunction(
|
|
||||||
changedFunction.fakeGenerator(checker),
|
|
||||||
windowToProcess
|
|
||||||
);
|
|
||||||
}, windowToProcess);
|
|
||||||
}
|
|
||||||
Object.defineProperty(object, name, descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
||||||
|
if (!descriptor) return;
|
||||||
|
|
||||||
|
if (descriptor.hasOwnProperty("value")){
|
||||||
|
if (changedFunction.fakeGenerator){
|
||||||
|
descriptor.value = extension.exportFunctionWithName(
|
||||||
|
changedFunction.fakeGenerator(checker, original, windowToProcess),
|
||||||
|
windowToProcess,
|
||||||
|
original.name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
descriptor.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
descriptor.get = extension.exportFunctionWithName(function(){
|
||||||
|
return extension.exportFunctionWithName(
|
||||||
|
changedFunction.fakeGenerator(checker),
|
||||||
|
windowToProcess,
|
||||||
|
original.name
|
||||||
|
);
|
||||||
|
}, windowToProcess, descriptor.get.name);
|
||||||
|
}
|
||||||
|
Object.defineProperty(object, name, descriptor);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function interceptGetters(windowToProcess, siteStatus, {checkStack, ask, notify, prefs}){
|
function interceptGetters(windowToProcess, siteStatus, {checkStack, ask, notify, prefs}){
|
||||||
@ -356,71 +358,70 @@
|
|||||||
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){
|
|
||||||
const object = objectGetter(extension.getWrapped(windowToProcess));
|
changedGetter.objectGetters.forEach(function(objectGetter){
|
||||||
if (object){
|
const object = objectGetter(extension.getWrapped(windowToProcess));
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
if (!object) return;
|
||||||
if (descriptor && descriptor.hasOwnProperty("get")){
|
|
||||||
const original = descriptor.get;
|
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
||||||
const checker = generateChecker({
|
if (!descriptor) return;
|
||||||
name, changedFunction: changedGetter, siteStatus, original,
|
|
||||||
window: windowToProcess, prefs, checkStack, ask, notify
|
if (descriptor.hasOwnProperty("get")){
|
||||||
});
|
const original = descriptor.get;
|
||||||
const getter = changedGetter.getterGenerator(checker, original, windowToProcess);
|
const checker = generateChecker({
|
||||||
descriptor.get = extension.exportFunctionWithName(getter, windowToProcess, original.name);
|
name, changedFunction: changedGetter, siteStatus, original,
|
||||||
|
window: windowToProcess, prefs, checkStack, ask, notify
|
||||||
if (descriptor.hasOwnProperty("set") && descriptor.set && changedGetter.setterGenerator){
|
});
|
||||||
const original = descriptor.set;
|
const getter = changedGetter.getterGenerator(checker, original, windowToProcess);
|
||||||
const setter = changedGetter.setterGenerator(
|
descriptor.get = extension.exportFunctionWithName(getter, windowToProcess, original.name);
|
||||||
windowToProcess,
|
|
||||||
original,
|
if (descriptor.hasOwnProperty("set") && descriptor.set && changedGetter.setterGenerator){
|
||||||
prefs
|
const original = descriptor.set;
|
||||||
);
|
const setter = changedGetter.setterGenerator(
|
||||||
descriptor.set = extension.exportFunctionWithName(setter, windowToProcess, original.name);
|
windowToProcess,
|
||||||
}
|
original,
|
||||||
|
prefs
|
||||||
Object.defineProperty(object, name, descriptor);
|
);
|
||||||
}
|
descriptor.set = extension.exportFunctionWithName(setter, windowToProcess, original.name);
|
||||||
else if (
|
}
|
||||||
changedGetter.valueGenerator &&
|
|
||||||
descriptor && descriptor.hasOwnProperty("value")
|
Object.defineProperty(object, name, descriptor);
|
||||||
){
|
}
|
||||||
const protectedAPIFeatures = prefs("protectedAPIFeatures");
|
else if (
|
||||||
if (
|
changedGetter.valueGenerator &&
|
||||||
functionStatus.active &&
|
descriptor.hasOwnProperty("value")
|
||||||
(
|
){
|
||||||
!protectedAPIFeatures.hasOwnProperty(name + " @ " + changedGetter.api) ||
|
const protectedAPIFeatures = prefs("protectedAPIFeatures");
|
||||||
protectedAPIFeatures[name + " @ " + changedGetter.api]
|
if (
|
||||||
)
|
!protectedAPIFeatures.hasOwnProperty(name + " @ " + changedGetter.api) ||
|
||||||
){
|
protectedAPIFeatures[name + " @ " + changedGetter.api]
|
||||||
switch (functionStatus.mode){
|
){
|
||||||
case "ask": case "block": case "fake":
|
switch (functionStatus.mode){
|
||||||
descriptor.value = changedGetter.valueGenerator({
|
case "ask": case "block": case "fake":
|
||||||
mode: functionStatus.mode,
|
descriptor.value = changedGetter.valueGenerator({
|
||||||
original: descriptor.value,
|
mode: functionStatus.mode,
|
||||||
notify: function notifyCallback(messageId){
|
original: descriptor.value,
|
||||||
notify({
|
notify: function notifyCallback(messageId){
|
||||||
url: getURL(windowToProcess),
|
notify({
|
||||||
errorStack: (new Error()).stack,
|
url: getURL(windowToProcess),
|
||||||
messageId,
|
errorStack: (new Error()).stack,
|
||||||
timestamp: new Date(),
|
messageId,
|
||||||
functionName: name,
|
timestamp: new Date(),
|
||||||
api: changedGetter.api
|
functionName: name,
|
||||||
});
|
api: changedGetter.api
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Object.defineProperty(object, name, descriptor);
|
}
|
||||||
break;
|
});
|
||||||
}
|
Object.defineProperty(object, name, descriptor);
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
else {
|
|
||||||
logging.error("Try to fake non getter property:", changedGetter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
else {
|
||||||
|
logging.error("Try to fake non getter property:", changedGetter);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
scope.intercept = function intercept({subject: windowToProcess}, apis){
|
scope.intercept = function intercept({subject: windowToProcess}, apis){
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user