mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-04-18 08:08:28 +02:00
Added logging lib with setting to control log level.
This commit is contained in:
parent
65ad3a5814
commit
9715eb09d2
@ -331,5 +331,38 @@
|
|||||||
"showReleaseNotes_label": {
|
"showReleaseNotes_label": {
|
||||||
"message": "Anzeigen",
|
"message": "Anzeigen",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
},
|
||||||
|
|
||||||
|
"logLevel_title": {
|
||||||
|
"message": "Aufzeichnungslevel",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_description": {
|
||||||
|
"message": "Für eine Fehlersuche ist eine detaillierte Aufzeichnung der Addon-Aktivitäten hilfreich. Mit diesem Parameter kann der Grad der Detailliertheit dieser Aufzeichnung eingestellt werden.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.none": {
|
||||||
|
"message": "nichts",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.error": {
|
||||||
|
"message": "Fehler",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.warning": {
|
||||||
|
"message": "Warnungen",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.message": {
|
||||||
|
"message": "Nachrichten",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.notice": {
|
||||||
|
"message": "Notizen",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.verbose": {
|
||||||
|
"message": "ausführlich",
|
||||||
|
"description": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -335,5 +335,38 @@
|
|||||||
"showReleaseNotes_label": {
|
"showReleaseNotes_label": {
|
||||||
"message": "Show",
|
"message": "Show",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
},
|
||||||
|
|
||||||
|
"logLevel_title": {
|
||||||
|
"message": "Logging level",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_description": {
|
||||||
|
"message": "To finde the cause for an error a detailed logging of the addon activities is helpful. This parameter controls the level of detail of the logging.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.none": {
|
||||||
|
"message": "none",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.error": {
|
||||||
|
"message": "error",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.warning": {
|
||||||
|
"message": "warning",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.message": {
|
||||||
|
"message": "message",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.notice": {
|
||||||
|
"message": "notice",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"logLevel_options.verbose": {
|
||||||
|
"message": "verbose",
|
||||||
|
"description": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,6 +20,7 @@
|
|||||||
const prefs = preferences.prefs;
|
const prefs = preferences.prefs;
|
||||||
const {parseErrorStack} = require("./callingStack");
|
const {parseErrorStack} = require("./callingStack");
|
||||||
const {URL} = require("sdk/url");
|
const {URL} = require("sdk/url");
|
||||||
|
const logging = require("./logging");
|
||||||
|
|
||||||
scope.check = function check({url, errorStack}){
|
scope.check = function check({url, errorStack}){
|
||||||
var match = checkBoth(errorStack, url, prefs.blockMode).match(/^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/);
|
var match = checkBoth(errorStack, url, prefs.blockMode).match(/^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/);
|
||||||
@ -50,14 +51,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkURL(url, blockMode){
|
function checkURL(url, blockMode){
|
||||||
|
logging.message("check url %s for block mode %s", url, blockMode);
|
||||||
url = new URL(url || "about:blank");
|
url = new URL(url || "about:blank");
|
||||||
switch (url.protocol){
|
switch (url.protocol){
|
||||||
case "about:":
|
case "about:":
|
||||||
if (url.href === "about:blank"){
|
if (url.href === "about:blank"){
|
||||||
|
logging.message("use regular mode on about:blank");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
logging.message("allow internal URLs");
|
||||||
return "allowInternal";
|
return "allowInternal";
|
||||||
case "chrome:":
|
case "chrome:":
|
||||||
|
logging.message("allow internal URLs");
|
||||||
return "allowInternal";
|
return "allowInternal";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +101,7 @@
|
|||||||
mode = "allow";
|
mode = "allow";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// console.log("Unknown blocking mode (" + blockMode + "). Default to block everything.");
|
logging.warning("Unknown blocking mode (" + blockMode + "). Default to block everything.");
|
||||||
}
|
}
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var settings = {
|
var settings = {
|
||||||
|
logLevel: 100,
|
||||||
whiteList: "",
|
whiteList: "",
|
||||||
blackList: "",
|
blackList: "",
|
||||||
blockMode: "fakeReadout",
|
blockMode: "fakeReadout",
|
||||||
@ -17,5 +18,6 @@ var settings = {
|
|||||||
showCallingFile: false,
|
showCallingFile: false,
|
||||||
showCompleteCallingStack: false,
|
showCompleteCallingStack: false,
|
||||||
enableStackList: false,
|
enableStackList: false,
|
||||||
stackList: ""
|
stackList: "",
|
||||||
|
isStillDefault: true
|
||||||
};
|
};
|
47
lib/frame.js
47
lib/frame.js
@ -4,33 +4,18 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
function log(...args){
|
|
||||||
function leftPad(str, char, pad){
|
|
||||||
str = "" + str;
|
|
||||||
return char.repeat(pad - str.length) + str;
|
|
||||||
}
|
|
||||||
args.unshift("frame script:");
|
|
||||||
var now = new Date();
|
|
||||||
args.unshift(
|
|
||||||
now.getFullYear() + "-" +
|
|
||||||
leftPad(now.getMonth() + 1, "0", 2) + "-" +
|
|
||||||
leftPad(now.getDate(), "0", 2) + " " +
|
|
||||||
leftPad(now.getHours(), "0", 2) + ":" +
|
|
||||||
leftPad(now.getMinutes(), "0", 2) + ":" +
|
|
||||||
leftPad(now.getSeconds(), "0", 2) + "." +
|
|
||||||
leftPad(now.getMilliseconds(), "0", 3)
|
|
||||||
);
|
|
||||||
console.log.apply(console, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
const {intercept} = require("./intercept.js");
|
const {intercept} = require("./intercept.js");
|
||||||
const {ask} = require("./askForPermission.js");
|
const {ask} = require("./askForPermission.js");
|
||||||
const {check: originalCheck, checkStack: originalCheckStack} = require("./check.js");
|
const {check: originalCheck, checkStack: originalCheckStack} = require("./check.js");
|
||||||
|
|
||||||
|
const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = require("./logging");
|
||||||
|
setLogPrefix("frame script");
|
||||||
|
|
||||||
// Variable to "unload" the script
|
// Variable to "unload" the script
|
||||||
var enabled = true;
|
var enabled = true;
|
||||||
|
|
||||||
log("starting", location.href);
|
message("starting", location.href);
|
||||||
|
|
||||||
function check(message){
|
function check(message){
|
||||||
if (enabled){
|
if (enabled){
|
||||||
@ -56,12 +41,12 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
log("open port to background script");
|
message("open port to background script");
|
||||||
var port = browser.runtime.connect();
|
var port = browser.runtime.connect();
|
||||||
var tabId;
|
var tabId;
|
||||||
port.onMessage.addListener(function(data){
|
port.onMessage.addListener(function(data){
|
||||||
if (data.hasOwnProperty("tabId")){
|
if (data.hasOwnProperty("tabId")){
|
||||||
log("my tab id is", data.tabId);
|
notice("my tab id is", data.tabId);
|
||||||
tabId = data.tabId;
|
tabId = data.tabId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -89,16 +74,16 @@
|
|||||||
catch (e){
|
catch (e){
|
||||||
// we are unable to read the location due to SOP
|
// we are unable to read the location due to SOP
|
||||||
// therefore we also can not intercept anything.
|
// therefore we also can not intercept anything.
|
||||||
log("NOT intercepting window du to SOP", window);
|
warning("NOT intercepting window du to SOP", window);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log("intercepting window", window);
|
message("intercepting window", window);
|
||||||
intercept(
|
intercept(
|
||||||
{subject: window},
|
{subject: window},
|
||||||
{check, checkStack, ask: askWrapper, notify, prefs}
|
{check, checkStack, ask: askWrapper, notify, prefs}
|
||||||
);
|
);
|
||||||
log("prepare to intercept (i)frames.");
|
message("prepare to intercept (i)frames.");
|
||||||
|
|
||||||
[window.HTMLIFrameElement, window.HTMLFrameElement].forEach(function(constructor){
|
[window.HTMLIFrameElement, window.HTMLFrameElement].forEach(function(constructor){
|
||||||
var oldContentWindowGetter = constructor.prototype.__lookupGetter__("contentWindow");
|
var oldContentWindowGetter = constructor.prototype.__lookupGetter__("contentWindow");
|
||||||
@ -137,34 +122,34 @@
|
|||||||
|
|
||||||
interceptWindow(window);
|
interceptWindow(window);
|
||||||
|
|
||||||
log("register listener for messages from background script");
|
message("register listener for messages from background script");
|
||||||
browser.runtime.onMessage.addListener(function(data){
|
browser.runtime.onMessage.addListener(function(data){
|
||||||
if (data["canvasBlocker-unload"]){
|
if (data["canvasBlocker-unload"]){
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
if (data.hasOwnProperty("canvasBlocker-sendNotifications") && data["canvasBlocker-sendNotifications"] === tabId){
|
if (data.hasOwnProperty("canvasBlocker-sendNotifications") && data["canvasBlocker-sendNotifications"] === tabId){
|
||||||
log("sending notifications:", notifications);
|
notice("sending notifications:", notifications);
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
sender: tabId,
|
sender: tabId,
|
||||||
"canvasBlocker-notifications": notifications
|
"canvasBlocker-notifications": notifications
|
||||||
});
|
});
|
||||||
log("notifications sent");
|
notice("notifications sent");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
log("load settings");
|
message("load settings");
|
||||||
browser.storage.local.get().then(function(data){
|
browser.storage.local.get().then(function(data){
|
||||||
Object.keys(data).forEach(function(key){
|
Object.keys(data).forEach(function(key){
|
||||||
log("loaded setting:", key, ":", data[key]);
|
notice("loaded setting:", key, ":", data[key]);
|
||||||
settings[key] = data[key];
|
settings[key] = data[key];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
log("register listener for settings changes");
|
message("register listener for settings changes");
|
||||||
browser.storage.onChanged.addListener(function(change, area){
|
browser.storage.onChanged.addListener(function(change, area){
|
||||||
if (area === "local"){
|
if (area === "local"){
|
||||||
Object.keys(change).forEach(function(key){
|
Object.keys(change).forEach(function(key){
|
||||||
log("setting changed:", key, ":", change[key].newValue);
|
notice("setting changed:", key, ":", change[key].newValue);
|
||||||
settings[key] = change[key].newValue;
|
settings[key] = change[key].newValue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
88
lib/logging.js
Normal file
88
lib/logging.js
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/* jslint moz: true */
|
||||||
|
/* 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";
|
||||||
|
|
||||||
|
var scope;
|
||||||
|
if ((typeof exports) !== "undefined"){
|
||||||
|
scope = exports;
|
||||||
|
}
|
||||||
|
else if (window.scope){
|
||||||
|
window.scope.logging = {};
|
||||||
|
scope = window.scope.logging;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.logging = {};
|
||||||
|
scope = window.logging;
|
||||||
|
}
|
||||||
|
|
||||||
|
var prefix = "";
|
||||||
|
|
||||||
|
function leftPad(str, char, pad){
|
||||||
|
str = "" + str;
|
||||||
|
return char.repeat(pad - str.length) + str;
|
||||||
|
}
|
||||||
|
|
||||||
|
var queue = [];
|
||||||
|
function performLog(level, args, date){
|
||||||
|
if (!date){
|
||||||
|
date = new Date();
|
||||||
|
}
|
||||||
|
if (settings.isStillDefault){
|
||||||
|
queue.push({level, args, date});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (settings.logLevel >= level){
|
||||||
|
if (prefix){
|
||||||
|
args.unshift(prefix + ":");
|
||||||
|
}
|
||||||
|
args.unshift(
|
||||||
|
"[" +
|
||||||
|
date.getFullYear() + "-" +
|
||||||
|
leftPad(date.getMonth() + 1, "0", 2) + "-" +
|
||||||
|
leftPad(date.getDate(), "0", 2) + " " +
|
||||||
|
leftPad(date.getHours(), "0", 2) + ":" +
|
||||||
|
leftPad(date.getMinutes(), "0", 2) + ":" +
|
||||||
|
leftPad(date.getSeconds(), "0", 2) + "." +
|
||||||
|
leftPad(date.getMilliseconds(), "0", 3) +
|
||||||
|
"]"
|
||||||
|
);
|
||||||
|
console.log.apply(console, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function error (...args){performLog( 1, args);}
|
||||||
|
function warning(...args){performLog( 25, args);}
|
||||||
|
function message(...args){performLog( 50, args);}
|
||||||
|
function notice (...args){performLog( 75, args);}
|
||||||
|
function verbose(...args){performLog(100, args);}
|
||||||
|
function metaLog(...args){performLog(999, args);}
|
||||||
|
|
||||||
|
scope.setPrefix = function(newPrefix){
|
||||||
|
if (!prefix){
|
||||||
|
prefix = newPrefix;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
warning("logging prefix already set (%s) cannot be set to %s", prefix, newPrefix);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
scope.clearQueue = function(){
|
||||||
|
if (queue.length){
|
||||||
|
metaLog("clear logging queue");
|
||||||
|
var tmp = queue;
|
||||||
|
queue = [];
|
||||||
|
tmp.forEach(function(item){
|
||||||
|
performLog(item.level, item.args, item.date);
|
||||||
|
});
|
||||||
|
metaLog("logging queue cleared");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
scope.error = error;
|
||||||
|
scope.warning = warning;
|
||||||
|
scope.message = message;
|
||||||
|
scope.notice = notice;
|
||||||
|
scope.verbose = verbose;
|
||||||
|
}());
|
54
lib/main.js
54
lib/main.js
@ -5,25 +5,25 @@
|
|||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function log(...args){
|
const logging = require("./logging");
|
||||||
args.unshift("main script:");
|
const {error, warning, message, notice, verbose, } = logging;
|
||||||
args.unshift(new Date());
|
logging.setPrefix("main script");
|
||||||
console.log.apply(console, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
log("start");
|
message("start");
|
||||||
log("loading storage");
|
message("loading storage");
|
||||||
browser.storage.local.get().then(function(data){
|
browser.storage.local.get().then(function(data){
|
||||||
Object.keys(data).forEach(function(key){
|
Object.keys(data).forEach(function(key){
|
||||||
settings[key] = data[key];
|
settings[key] = data[key];
|
||||||
});
|
});
|
||||||
|
settings.isStillDefault = false;
|
||||||
|
logging.clearQueue();
|
||||||
return settings;
|
return settings;
|
||||||
}).then(function(settings){
|
}).then(function(settings){
|
||||||
log("everything loaded");
|
notice("everything loaded");
|
||||||
const lists = require("./lists");
|
const lists = require("./lists");
|
||||||
lists.updateAll();
|
lists.updateAll();
|
||||||
|
|
||||||
log("build persistent storage");
|
notice("build persistent storage");
|
||||||
var persistentRnd = Object.create(null);
|
var persistentRnd = Object.create(null);
|
||||||
try {
|
try {
|
||||||
let storedData = JSON.parse(settings.persistentRndStorage);
|
let storedData = JSON.parse(settings.persistentRndStorage);
|
||||||
@ -41,8 +41,8 @@
|
|||||||
catch(e){}
|
catch(e){}
|
||||||
|
|
||||||
function updateContentScripts(){
|
function updateContentScripts(){
|
||||||
log("update content scripts");
|
message("update content scripts");
|
||||||
log("build settings blob");
|
notice("build settings blob");
|
||||||
var settingsBlob = new Blob(
|
var settingsBlob = new Blob(
|
||||||
[
|
[
|
||||||
"var settings = " + JSON.stringify(settings) + ";",
|
"var settings = " + JSON.stringify(settings) + ";",
|
||||||
@ -52,15 +52,15 @@
|
|||||||
type: "text/javascript"
|
type: "text/javascript"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
log("TODO: register content scripts -> have to wait for the API to be released");
|
warning("TODO: register content scripts -> have to wait for the API to be released");
|
||||||
}
|
}
|
||||||
updateContentScripts();
|
updateContentScripts();
|
||||||
|
|
||||||
log("register non port message listener");
|
message("register non port message listener");
|
||||||
browser.runtime.onMessage.addListener(function(data){
|
browser.runtime.onMessage.addListener(function(data){
|
||||||
log("got data without port", data);
|
notice("got data without port", data);
|
||||||
if (data["canvasBlocker-new-domain-rnd"]){
|
if (data["canvasBlocker-new-domain-rnd"]){
|
||||||
log("got new domain rnd");
|
verbose("got new domain rnd", data["canvasBlocker-new-domain-rnd"]);
|
||||||
data["canvasBlocker-set-domain-rnd"] = data["canvasBlocker-new-domain-rnd"];
|
data["canvasBlocker-set-domain-rnd"] = data["canvasBlocker-new-domain-rnd"];
|
||||||
persistentRnd[data["canvasBlocker-new-domain-rnd"].domain] = data["canvasBlocker-new-domain-rnd"].rnd;
|
persistentRnd[data["canvasBlocker-new-domain-rnd"].domain] = data["canvasBlocker-new-domain-rnd"].rnd;
|
||||||
browser.storage.local.get("storePersistentRnd").then(function(prefs){
|
browser.storage.local.get("storePersistentRnd").then(function(prefs){
|
||||||
@ -70,7 +70,7 @@
|
|||||||
});
|
});
|
||||||
updateContentScripts();
|
updateContentScripts();
|
||||||
}
|
}
|
||||||
log("pass the message to the tabs");
|
notice("pass the message to the tabs");
|
||||||
browser.tabs.query({}).then(function(tabs){
|
browser.tabs.query({}).then(function(tabs){
|
||||||
tabs.forEach(function(tab){
|
tabs.forEach(function(tab){
|
||||||
browser.tabs.sendMessage(tab.id, data);
|
browser.tabs.sendMessage(tab.id, data);
|
||||||
@ -78,10 +78,10 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
log("register port listener");
|
message("register port listener");
|
||||||
browser.runtime.onConnect.addListener(function(port){
|
browser.runtime.onConnect.addListener(function(port){
|
||||||
log("got port", port);
|
notice("got port", port);
|
||||||
log("send back the tab id", port.sender.tab.id);
|
verbose("send back the tab id", port.sender.tab.id);
|
||||||
port.postMessage({tabId: port.sender.tab.id});
|
port.postMessage({tabId: port.sender.tab.id});
|
||||||
var url = new URL(port.sender.url);
|
var url = new URL(port.sender.url);
|
||||||
port.onMessage.addListener(function(data){
|
port.onMessage.addListener(function(data){
|
||||||
@ -96,22 +96,22 @@
|
|||||||
browser.pageAction.show(port.sender.tab.id);
|
browser.pageAction.show(port.sender.tab.id);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
log("got data", data, "from port", port);
|
verbose("got data", data, "from port", port);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
log("register storage change event listener");
|
message("register storage change event listener");
|
||||||
browser.storage.onChanged.addListener(function(change, area){
|
browser.storage.onChanged.addListener(function(change, area){
|
||||||
if (area === "local"){
|
if (area === "local"){
|
||||||
log("settings changed", change);
|
notice("settings changed", change);
|
||||||
log("update settings object");
|
notice("update settings object");
|
||||||
Object.keys(change).forEach(function(key){
|
Object.keys(change).forEach(function(key){
|
||||||
settings[key] = change[key].newValue;
|
settings[key] = change[key].newValue;
|
||||||
});
|
});
|
||||||
updateContentScripts();
|
updateContentScripts();
|
||||||
|
|
||||||
if (change.hasOwnProperty("showNotifications") && !change.showNotifications.newValue){
|
if (change.hasOwnProperty("showNotifications") && !change.showNotifications.newValue){
|
||||||
log("notifications were disabled -> hide all page actions");
|
message("notifications were disabled -> hide all page actions");
|
||||||
browser.tabs.query({}).then(function(tabs){
|
browser.tabs.query({}).then(function(tabs){
|
||||||
tabs.forEach(function(tab){
|
tabs.forEach(function(tab){
|
||||||
browser.pageAction.hide(tab.id);
|
browser.pageAction.hide(tab.id);
|
||||||
@ -134,7 +134,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// log("TODO: register unload events - do not know how - there seems to be no way with a WebExtension");
|
// warning("TODO: register unload events - do not know how - there seems to be no way with a WebExtension");
|
||||||
// old code
|
// old code
|
||||||
// const {when: unload} = require("sdk/system/unload");
|
// const {when: unload} = require("sdk/system/unload");
|
||||||
// unload(function(){
|
// unload(function(){
|
||||||
@ -142,7 +142,7 @@
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
browser.runtime.onInstalled.addListener(function(){
|
browser.runtime.onInstalled.addListener(function(){
|
||||||
log("CanvasBlocker installed");
|
message("CanvasBlocker installed");
|
||||||
browser.storage.local.get("storageVersion").then(function(data){
|
browser.storage.local.get("storageVersion").then(function(data){
|
||||||
if (data.storageVersion !== 0.1){
|
if (data.storageVersion !== 0.1){
|
||||||
browser.storage.local.set({
|
browser.storage.local.set({
|
||||||
@ -152,5 +152,5 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
log("end");
|
message("end");
|
||||||
}());
|
}());
|
@ -10,6 +10,7 @@
|
|||||||
"scripts": [
|
"scripts": [
|
||||||
"lib/defaultSettings.js",
|
"lib/defaultSettings.js",
|
||||||
"lib/require.js",
|
"lib/require.js",
|
||||||
|
"lib/logging.js",
|
||||||
"lib/lists.js",
|
"lib/lists.js",
|
||||||
"lib/main.js"
|
"lib/main.js"
|
||||||
]
|
]
|
||||||
@ -22,6 +23,8 @@
|
|||||||
"lib/defaultSettings.js",
|
"lib/defaultSettings.js",
|
||||||
"lib/require.js",
|
"lib/require.js",
|
||||||
|
|
||||||
|
"lib/logging.js",
|
||||||
|
|
||||||
"lib/modifiedAPI.js",
|
"lib/modifiedAPI.js",
|
||||||
"lib/randomSupplies.js",
|
"lib/randomSupplies.js",
|
||||||
"lib/intercept.js",
|
"lib/intercept.js",
|
||||||
|
@ -220,6 +220,38 @@ document.body.appendChild(table);
|
|||||||
"title": "Release notes",
|
"title": "Release notes",
|
||||||
"type": "control",
|
"type": "control",
|
||||||
"label": "Show"
|
"label": "Show"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "logLevel",
|
||||||
|
"title": "logging level",
|
||||||
|
"type": "menulist",
|
||||||
|
"value": 1,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"value": 0,
|
||||||
|
"label": "none"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 1,
|
||||||
|
"label": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 25,
|
||||||
|
"label": "warning"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 50,
|
||||||
|
"label": "message"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 75,
|
||||||
|
"label": "notice"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 100,
|
||||||
|
"label": "verbose"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
].forEach(function(pref){
|
].forEach(function(pref){
|
||||||
var html = '<td><div class="content"><span class="title">__MSG_' + pref.name + '_title__</span><div class="description">__MSG_' + pref.name + '_description__</div></div></td><td><div class="content">';
|
var html = '<td><div class="content"><span class="title">__MSG_' + pref.name + '_title__</span><div class="description">__MSG_' + pref.name + '_description__</div></div></td><td><div class="content">';
|
||||||
@ -235,9 +267,9 @@ document.body.appendChild(table);
|
|||||||
html += '<input type="checkbox" style="display: inline"' + inputAttributes + (pref.value? ' checked="checked"': "") + '>';
|
html += '<input type="checkbox" style="display: inline"' + inputAttributes + (pref.value? ' checked="checked"': "") + '>';
|
||||||
break;
|
break;
|
||||||
case "menulist":
|
case "menulist":
|
||||||
html += '<select' + inputAttributes + '>' +
|
html += '<select' + inputAttributes + 'data-type="' + (typeof pref.value) + '">' +
|
||||||
pref.options.map(function(option){
|
pref.options.map(function(option){
|
||||||
if (option.value){
|
if (option.value !== ""){
|
||||||
return '<option value="' + option.value + '"' + (option.value === pref.value? " selected": "") + '>__MSG_' + pref.name + '_options.' + option.label + '__</option>';
|
return '<option value="' + option.value + '"' + (option.value === pref.value? " selected": "") + '>__MSG_' + pref.name + '_options.' + option.label + '__</option>';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -250,13 +282,13 @@ document.body.appendChild(table);
|
|||||||
html += '<button' + inputAttributes + '">__MSG_' + pref.name + '_label__</button>';
|
html += '<button' + inputAttributes + '">__MSG_' + pref.name + '_label__</button>';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log("Unknown preference type: " + pref.type);
|
logging.warning("Unknown preference type: " + pref.type);
|
||||||
}
|
}
|
||||||
html += "</div></td>";
|
html += "</div></td>";
|
||||||
var tr = document.createElement("tr");
|
var tr = document.createElement("tr");
|
||||||
tr.setting = pref;
|
tr.setting = pref;
|
||||||
tr.className = "settingRow";
|
tr.className = "settingRow";
|
||||||
tr.innerHTML = html;
|
tr.innerHTML = html;
|
||||||
console.log(html);
|
logging.verbose(html);
|
||||||
table.appendChild(tr);
|
table.appendChild(tr);
|
||||||
});
|
});
|
@ -7,6 +7,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script src="../lib/defaultSettings.js"></script>
|
<script src="../lib/defaultSettings.js"></script>
|
||||||
|
<script src="../lib/logging.js"></script>
|
||||||
<script src="buildPrefInputs.js"></script>
|
<script src="buildPrefInputs.js"></script>
|
||||||
<script src="options.js"></script>
|
<script src="options.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
|
/* jslint moz: true */
|
||||||
|
/* 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/. */
|
||||||
browser.storage.local.get().then(function(data){
|
browser.storage.local.get().then(function(data){
|
||||||
Object.keys(data).forEach(function(key){
|
Object.keys(data).forEach(function(key){
|
||||||
settings[key] = data[key];
|
settings[key] = data[key];
|
||||||
});
|
});
|
||||||
|
settings.isStillDefault = false;
|
||||||
|
logging.clearQueue();
|
||||||
return settings;
|
return settings;
|
||||||
}).then(function(settings){
|
}).then(function(settings){
|
||||||
function traverse(node, func){
|
function traverse(node, func){
|
||||||
@ -10,6 +16,7 @@ browser.storage.local.get().then(function(data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getting the translation of all the messages
|
// getting the translation of all the messages
|
||||||
|
message("transate all messages");
|
||||||
traverse(document.body, function(node){
|
traverse(document.body, function(node){
|
||||||
if (node.nodeType == 3){
|
if (node.nodeType == 3){
|
||||||
var lines = node.nodeValue.replace(/\b__MSG_(.+)__\b/g, function(m, key){
|
var lines = node.nodeValue.replace(/\b__MSG_(.+)__\b/g, function(m, key){
|
||||||
@ -28,12 +35,14 @@ browser.storage.local.get().then(function(data){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
message("register events to store changes in local storage");
|
||||||
Array.from(document.querySelectorAll("input.setting, select.setting")).forEach(function(input){
|
Array.from(document.querySelectorAll("input.setting, select.setting")).forEach(function(input){
|
||||||
var storageName = input.dataset.storageName;
|
var storageName = input.dataset.storageName;
|
||||||
if (input.type === "checkbox"){
|
if (input.type === "checkbox"){
|
||||||
input.checked = settings[storageName];
|
input.checked = settings[storageName];
|
||||||
|
|
||||||
input.addEventListener("click", function(){
|
input.addEventListener("click", function(){
|
||||||
|
message("changed setting", storageName, ":", this.checked);
|
||||||
var value = this.checked;
|
var value = this.checked;
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[storageName] = value;
|
obj[storageName] = value;
|
||||||
@ -44,9 +53,10 @@ browser.storage.local.get().then(function(data){
|
|||||||
|
|
||||||
input.addEventListener("change", function(){
|
input.addEventListener("change", function(){
|
||||||
var value = this.value;
|
var value = this.value;
|
||||||
if (this.type === "number"){
|
if (this.type === "number" || this.dataset.type === "number"){
|
||||||
value = parseFloat(value);
|
value = parseFloat(value);
|
||||||
}
|
}
|
||||||
|
message("changed setting", storageName, ":", value);
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[storageName] = value;
|
obj[storageName] = value;
|
||||||
browser.storage.local.set(obj);
|
browser.storage.local.set(obj);
|
||||||
@ -56,6 +66,7 @@ browser.storage.local.get().then(function(data){
|
|||||||
|
|
||||||
var callbacks = {
|
var callbacks = {
|
||||||
showReleaseNotes: function(){
|
showReleaseNotes: function(){
|
||||||
|
verbose("open release notes");
|
||||||
window.open("../releaseNotes.txt", "_blank");
|
window.open("../releaseNotes.txt", "_blank");
|
||||||
// would be nicer but is not supported in fennec
|
// would be nicer but is not supported in fennec
|
||||||
// browser.windows.create({
|
// browser.windows.create({
|
||||||
@ -64,7 +75,10 @@ browser.storage.local.get().then(function(data){
|
|||||||
// });
|
// });
|
||||||
},
|
},
|
||||||
clearPersistentRnd: function(){
|
clearPersistentRnd: function(){
|
||||||
|
message("clear persistent rnd storage");
|
||||||
|
notice("empty storage");
|
||||||
browser.storage.local.set({persistentRndStorage: ""});
|
browser.storage.local.set({persistentRndStorage: ""});
|
||||||
|
notice("send message to main script");
|
||||||
browser.runtime.sendMessage({"canvasBlocker-clear-domain-rnd": true});
|
browser.runtime.sendMessage({"canvasBlocker-clear-domain-rnd": true});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -78,13 +92,14 @@ browser.storage.local.get().then(function(data){
|
|||||||
});
|
});
|
||||||
|
|
||||||
function updateDisplay(){
|
function updateDisplay(){
|
||||||
|
notice("update display");
|
||||||
document.querySelectorAll("tr.settingRow").forEach(function(row){
|
document.querySelectorAll("tr.settingRow").forEach(function(row){
|
||||||
|
verbose("evaluate display dependencies for", row.setting);
|
||||||
var displayDependencies = row.setting.displayDependencies;
|
var displayDependencies = row.setting.displayDependencies;
|
||||||
if (displayDependencies){
|
if (displayDependencies){
|
||||||
row.classList[(
|
row.classList[(
|
||||||
(Array.isArray(displayDependencies)? displayDependencies: [displayDependencies]).some(function(displayDependency){
|
(Array.isArray(displayDependencies)? displayDependencies: [displayDependencies]).some(function(displayDependency){
|
||||||
return Object.keys(displayDependency).every(function(key){
|
return Object.keys(displayDependency).every(function(key){
|
||||||
console.log(key, displayDependency[key], settings[key]);
|
|
||||||
return displayDependency[key].indexOf(settings[key]) !== -1;
|
return displayDependency[key].indexOf(settings[key]) !== -1;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -9,8 +9,9 @@
|
|||||||
<ul id="prints">
|
<ul id="prints">
|
||||||
<li>...</li>
|
<li>...</li>
|
||||||
</ul>
|
</ul>
|
||||||
<script src="../lib/require.js"></script>
|
|
||||||
<script src="../lib/defaultSettings.js"></script>
|
<script src="../lib/defaultSettings.js"></script>
|
||||||
|
<script src="../lib/require.js"></script>
|
||||||
|
<script src="../lib/logging.js"></script>
|
||||||
<script src="../lib/lists.js"></script>
|
<script src="../lib/lists.js"></script>
|
||||||
<script src="../lib/callingStack.js"></script>
|
<script src="../lib/callingStack.js"></script>
|
||||||
<script src="pageAction.js"></script>
|
<script src="pageAction.js"></script>
|
||||||
|
@ -1,38 +1,7 @@
|
|||||||
// console.log(window, browser, browser.runtime);
|
/* jslint moz: true */
|
||||||
function modalPrompt(message, defaultValue){
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
return new Promise(function(resolve, reject){
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
document.body.innerHTML = "";
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
document.body.appendChild(document.createTextNode(message));
|
|
||||||
var input = document.createElement("input");
|
|
||||||
input.value = defaultValue;
|
|
||||||
document.body.appendChild(input);
|
|
||||||
var button = document.createElement("button");
|
|
||||||
button.textContent = "OK";
|
|
||||||
button.addEventListener("click", function(){
|
|
||||||
resolve(input.value);
|
|
||||||
});
|
|
||||||
document.body.appendChild(button);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function log(...args){
|
|
||||||
function leftPad(str, char, pad){
|
|
||||||
str = "" + str;
|
|
||||||
return char.repeat(pad - str.length) + str;
|
|
||||||
}
|
|
||||||
args.unshift("page action script:");
|
|
||||||
var now = new Date();
|
|
||||||
args.unshift(
|
|
||||||
now.getFullYear() + "-" +
|
|
||||||
leftPad(now.getMonth() + 1, "0", 2) + "-" +
|
|
||||||
leftPad(now.getDate(), "0", 2) + " " +
|
|
||||||
leftPad(now.getHours(), "0", 2) + ":" +
|
|
||||||
leftPad(now.getMinutes(), "0", 2) + ":" +
|
|
||||||
leftPad(now.getSeconds(), "0", 2) + "." +
|
|
||||||
leftPad(now.getMilliseconds(), "0", 3)
|
|
||||||
);
|
|
||||||
console.log.apply(console, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
browser.tabs.query({active: true, currentWindow: true}),
|
browser.tabs.query({active: true, currentWindow: true}),
|
||||||
@ -42,7 +11,31 @@ Promise.all([
|
|||||||
});
|
});
|
||||||
return settings;
|
return settings;
|
||||||
})
|
})
|
||||||
]).then(function([tabs, settings]){
|
]).then(function(values){
|
||||||
|
"use strict";
|
||||||
|
const [tabs, settings] = values;
|
||||||
|
|
||||||
|
const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = require("./logging");
|
||||||
|
setLogPrefix("page action script");
|
||||||
|
|
||||||
|
function modalPrompt(message, defaultValue){
|
||||||
|
message("open modal prompt");
|
||||||
|
return new Promise(function(resolve, reject){
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
document.body.appendChild(document.createTextNode(message));
|
||||||
|
var input = document.createElement("input");
|
||||||
|
input.value = defaultValue;
|
||||||
|
document.body.appendChild(input);
|
||||||
|
var button = document.createElement("button");
|
||||||
|
button.textContent = "OK";
|
||||||
|
button.addEventListener("click", function(){
|
||||||
|
resolve(input.value);
|
||||||
|
message("modal prompt closed with value", input.value);
|
||||||
|
});
|
||||||
|
document.body.appendChild(button);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!tabs.length){
|
if (!tabs.length){
|
||||||
throw new Error("noTabsFound");
|
throw new Error("noTabsFound");
|
||||||
}
|
}
|
||||||
@ -108,10 +101,10 @@ Promise.all([
|
|||||||
var tab = tabs[0];
|
var tab = tabs[0];
|
||||||
browser.runtime.onMessage.addListener(function(data){
|
browser.runtime.onMessage.addListener(function(data){
|
||||||
if (Array.isArray(data["canvasBlocker-notifications"])){
|
if (Array.isArray(data["canvasBlocker-notifications"])){
|
||||||
log("got notifications", data);
|
message("got notifications");
|
||||||
var ul = document.getElementById("prints");
|
var ul = document.getElementById("prints");
|
||||||
data["canvasBlocker-notifications"].forEach(function(notification){
|
data["canvasBlocker-notifications"].forEach(function(notification){
|
||||||
console.log(notification);
|
verbose(notification);
|
||||||
|
|
||||||
var url = new URL(notification.url);
|
var url = new URL(notification.url);
|
||||||
var li = document.createElement("li");
|
var li = document.createElement("li");
|
||||||
@ -157,17 +150,17 @@ Promise.all([
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
log("clearing the display");
|
notice("clearing the display");
|
||||||
var ul = document.getElementById("prints");
|
var ul = document.getElementById("prints");
|
||||||
ul.innerHTML = "";
|
ul.innerHTML = "";
|
||||||
log("request notifications from tab", tab.id);
|
message("request notifications from tab", tab.id);
|
||||||
browser.tabs.sendMessage(
|
browser.tabs.sendMessage(
|
||||||
tab.id,
|
tab.id,
|
||||||
{
|
{
|
||||||
"canvasBlocker-sendNotifications": tab.id
|
"canvasBlocker-sendNotifications": tab.id
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
log("waiting for notifications");
|
notice("waiting for notifications");
|
||||||
}).catch(function(e){
|
}).catch(function(e){
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user