mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-22 03:18:31 +01:00
Remove all "var" from intercept.js
This commit is contained in:
parent
2222ba65c8
commit
a89bf0aba8
@ -4,7 +4,7 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
var scope;
|
||||
let scope;
|
||||
if ((typeof exports) !== "undefined"){
|
||||
scope = exports;
|
||||
}
|
||||
@ -20,8 +20,8 @@
|
||||
const extension = require("./extension");
|
||||
|
||||
setRandomSupply(randomSupplies.nonPersistent);
|
||||
var apiNames = Object.keys(changedFunctions);
|
||||
var undef;
|
||||
const apiNames = Object.keys(changedFunctions);
|
||||
let undef;
|
||||
function setRandomSupplyByType(type){
|
||||
switch (type){
|
||||
case "persistent":
|
||||
@ -42,7 +42,7 @@
|
||||
});
|
||||
|
||||
function getURL(window){
|
||||
var href;
|
||||
let href;
|
||||
try {
|
||||
href = window.location.href;
|
||||
}
|
||||
@ -80,7 +80,7 @@
|
||||
changedFunction.object:
|
||||
[changedFunction.object]
|
||||
).forEach(function(object){
|
||||
var constructor = getWrapped(window)[object];
|
||||
const constructor = getWrapped(window)[object];
|
||||
if (constructor){
|
||||
callback({name, object: constructor.prototype});
|
||||
}
|
||||
@ -100,7 +100,7 @@
|
||||
const doPreIntercept = function(){
|
||||
if (!preIntercepted){
|
||||
forEachFunction(function({name, object}){
|
||||
var map = originalPropertyDescriptors[name] || new WeakMap();
|
||||
const map = originalPropertyDescriptors[name] || new WeakMap();
|
||||
originalPropertyDescriptors[name] = map;
|
||||
|
||||
const originalPropertyDescriptor = Object.getOwnPropertyDescriptor(object, name);
|
||||
@ -121,16 +121,16 @@
|
||||
undoPreIntercept();
|
||||
settings.forceLoad();
|
||||
doRealIntercept();
|
||||
var descriptor = Object.getOwnPropertyDescriptor(object, name);
|
||||
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
||||
return descriptor.value || descriptor.get.call(this);
|
||||
}
|
||||
else {
|
||||
logging.notice("API blocked (%s)", name);
|
||||
var url = getURL(window);
|
||||
const url = getURL(window);
|
||||
if (!url){
|
||||
return undef;
|
||||
}
|
||||
var error = new Error();
|
||||
const error = new Error();
|
||||
apis.notify({
|
||||
url,
|
||||
errorStack: error.stack,
|
||||
@ -200,11 +200,11 @@
|
||||
}
|
||||
function generateChecker(name, changedFunction, siteStatus, original){
|
||||
return function checker(callingDepth = 2){
|
||||
var url = getURL(window);
|
||||
const url = getURL(window);
|
||||
if (!url){
|
||||
return undef;
|
||||
}
|
||||
var error = new Error();
|
||||
const error = new Error();
|
||||
try {
|
||||
// return original if the extension itself requested the function
|
||||
if (
|
||||
@ -222,7 +222,7 @@
|
||||
if (checkStack(error.stack)){
|
||||
return {allow: true, original, window};
|
||||
}
|
||||
var funcStatus = changedFunction.getStatus(this, siteStatus, prefs);
|
||||
const funcStatus = changedFunction.getStatus(this, siteStatus, prefs);
|
||||
|
||||
const This = this;
|
||||
function notifyCallback(messageId){
|
||||
@ -285,12 +285,12 @@
|
||||
};
|
||||
}
|
||||
|
||||
var siteStatus = check({url: getURL(window)});
|
||||
const siteStatus = check({url: getURL(window)});
|
||||
logging.verbose("status for page", window, siteStatus);
|
||||
if (siteStatus.mode !== "allow"){
|
||||
apiNames.forEach(function(name){
|
||||
var changedFunction = changedFunctions[name];
|
||||
var functionStatus = changedFunction.getStatus(undefined, siteStatus, prefs);
|
||||
const changedFunction = changedFunctions[name];
|
||||
const functionStatus = changedFunction.getStatus(undefined, siteStatus, prefs);
|
||||
logging.verbose("status for", name, ":", functionStatus);
|
||||
if (functionStatus.active){
|
||||
(
|
||||
@ -298,11 +298,11 @@
|
||||
changedFunction.object:
|
||||
[changedFunction.object]
|
||||
).forEach(function(object){
|
||||
var constructor = getWrapped(window)[object];
|
||||
const constructor = getWrapped(window)[object];
|
||||
if (constructor){
|
||||
var original = constructor.prototype[name];
|
||||
const original = constructor.prototype[name];
|
||||
const checker = generateChecker(name, changedFunction, siteStatus, original);
|
||||
var descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, name);
|
||||
const descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, name);
|
||||
if (descriptor){
|
||||
if (descriptor.hasOwnProperty("value")){
|
||||
if (changedFunction.fakeGenerator){
|
||||
@ -331,7 +331,7 @@
|
||||
});
|
||||
changedGetters.forEach(function(changedGetter){
|
||||
const name = changedGetter.name;
|
||||
var functionStatus = changedGetter.getStatus(undefined, siteStatus, prefs);
|
||||
const functionStatus = changedGetter.getStatus(undefined, siteStatus, prefs);
|
||||
logging.verbose("status for", changedGetter, ":", functionStatus);
|
||||
if (functionStatus.active){
|
||||
changedGetter.objectGetters.forEach(function(objectGetter){
|
||||
@ -339,7 +339,7 @@
|
||||
if (object){
|
||||
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
||||
if (descriptor && descriptor.hasOwnProperty("get")){
|
||||
var original = descriptor.get;
|
||||
const original = descriptor.get;
|
||||
const checker = generateChecker(name, changedGetter, siteStatus, original);
|
||||
const getter = changedGetter.getterGenerator(checker);
|
||||
descriptor.get = exportFunction(getter, window);
|
||||
|
Loading…
x
Reference in New Issue
Block a user