mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Big linting
This commit is contained in:
parent
b5e6d049ce
commit
aef6bd3d59
58 changed files with 2074 additions and 1856 deletions
53
lib/frame.js
53
lib/frame.js
|
@ -14,13 +14,12 @@
|
|||
const iframeProtection = require("./iframeProtection");
|
||||
|
||||
const logging = require("./logging");
|
||||
const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = logging;
|
||||
setLogPrefix("frame script");
|
||||
logging.setPrefix("frame script");
|
||||
|
||||
// Variable to "unload" the script
|
||||
var enabled = true;
|
||||
let enabled = true;
|
||||
|
||||
message("starting", location.href);
|
||||
logging.message("starting", location.href);
|
||||
|
||||
function check(message){
|
||||
if (enabled){
|
||||
|
@ -72,38 +71,38 @@
|
|||
}
|
||||
computeExtensionSecret();
|
||||
|
||||
message("open port to background script");
|
||||
var port = browser.runtime.connect();
|
||||
logging.message("open port to background script");
|
||||
const port = browser.runtime.connect();
|
||||
if (window === window.top){
|
||||
message("Is top level window -> tab had navigation -> clear page action");
|
||||
logging.message("Is top level window -> tab had navigation -> clear page action");
|
||||
port.postMessage({"canvasBlocker-clear-page-action": true});
|
||||
}
|
||||
var tabId;
|
||||
let tabId;
|
||||
port.onMessage.addListener(function(data){
|
||||
message("Got data from port", data);
|
||||
logging.message("Got data from port", data);
|
||||
if (data.hasOwnProperty("tabId")){
|
||||
notice("my tab id is", data.tabId);
|
||||
logging.notice("my tab id is", data.tabId);
|
||||
tabId = data.tabId;
|
||||
}
|
||||
if (data.hasOwnProperty("cookieStoreId")){
|
||||
notice("my tab cookie store id is", data.cookieStoreId);
|
||||
logging.notice("my tab cookie store id is", data.cookieStoreId);
|
||||
const {persistent: persistentRnd} = require("./randomSupplies");
|
||||
persistentRnd.setCookieStoreId(data.cookieStoreId);
|
||||
}
|
||||
const persistentRndName = "persistent" + (extension.inIncognitoContext? "Incognito": "") + "Rnd";
|
||||
if (data.hasOwnProperty(persistentRndName)){
|
||||
const persistentRndValue = data[persistentRndName];
|
||||
notice("got persistent random data", persistentRndValue);
|
||||
logging.notice("got persistent random data", persistentRndValue);
|
||||
const {persistent: persistentRnd} = require("./randomSupplies");
|
||||
Object.keys(persistentRndValue).forEach(function(domain){
|
||||
verbose("random data for", domain, persistentRndValue[domain]);
|
||||
logging.verbose("random data for", domain, persistentRndValue[domain]);
|
||||
persistentRnd.setDomainRnd(domain, persistentRndValue[domain]);
|
||||
});
|
||||
}
|
||||
});
|
||||
var notifications = [];
|
||||
var notificationCounter = {};
|
||||
var sentAPIs = {};
|
||||
const notifications = [];
|
||||
const notificationCounter = {};
|
||||
const sentAPIs = {};
|
||||
function notify(data){
|
||||
if (!settings.ignoredAPIs[data.api]){
|
||||
if (settings.storeNotificationData){
|
||||
|
@ -128,16 +127,18 @@
|
|||
}
|
||||
|
||||
|
||||
var interceptedWindows = new WeakMap();
|
||||
const interceptedWindows = new WeakMap();
|
||||
function interceptWindow(window){
|
||||
let wrappedTry;
|
||||
try {
|
||||
var href = window.location.href;
|
||||
var wrappedTry = getWrapped(window);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const href = window.location.href;
|
||||
wrappedTry = getWrapped(window);
|
||||
}
|
||||
catch (e){
|
||||
catch (error){
|
||||
// we are unable to read the location due to SOP
|
||||
// therefore we also can not intercept anything.
|
||||
notice("NOT intercepting window due to SOP", window);
|
||||
logging.notice("NOT intercepting window due to SOP", window);
|
||||
return false;
|
||||
}
|
||||
const wrappedWindow = wrappedTry;
|
||||
|
@ -150,12 +151,12 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
message("intercepting window", window);
|
||||
logging.message("intercepting window", window);
|
||||
intercept(
|
||||
{subject: window},
|
||||
{check, checkStack, ask: askWrapper, notify, prefs}
|
||||
);
|
||||
message("prepare to intercept (i)frames.");
|
||||
logging.message("prepare to intercept (i)frames.");
|
||||
|
||||
function interceptAllFrames(){
|
||||
const currentLength = window.length;
|
||||
|
@ -185,7 +186,7 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
message("register listener for messages from background script");
|
||||
logging.message("register listener for messages from background script");
|
||||
extension.message.on(function(data){
|
||||
if (data["canvasBlocker-unload"]){
|
||||
enabled = false;
|
||||
|
@ -194,14 +195,14 @@
|
|||
data.hasOwnProperty("canvasBlocker-sendNotifications") &&
|
||||
data["canvasBlocker-sendNotifications"] === tabId
|
||||
){
|
||||
notice("sending notifications:", notifications);
|
||||
logging.notice("sending notifications:", notifications);
|
||||
extension.message.send({
|
||||
sender: tabId,
|
||||
url: window.location.href,
|
||||
"canvasBlocker-notificationCounter": notificationCounter,
|
||||
"canvasBlocker-notifications": notifications
|
||||
});
|
||||
notice("notifications sent");
|
||||
logging.notice("notifications sent");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue