From 18a2e320442da22153f96dc4423a77f2d33a90f8 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Fri, 7 Jul 2017 08:49:12 +0200 Subject: [PATCH] Added better logging to frame.js and separated settings update from defaultSettings.js --- lib/defaultSettings.js | 12 +----------- lib/frame.js | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lib/defaultSettings.js b/lib/defaultSettings.js index fdbde18..a4fd79a 100644 --- a/lib/defaultSettings.js +++ b/lib/defaultSettings.js @@ -1,14 +1,4 @@ "use strict"; var settings = { whiteList: "", blackList: "", blockMode: "fakeReadout", maxFakeSize: 0, rng: "nonPersistent", persistentRndStorage: "", storePersistentRnd: false, askOnlyOnce: true, showNotifications: true, notificationDisplayTime: 30, ignoreList: "", showCallingFile: false, showCompleteCallingStack: false, enableStackList: false, stackList: "" -}; - -(function(){ - browser.storage.onChanged.addListener(function(change, area){ - if (area === "local"){ - Object.keys(change).forEach(function(key){ - settings[key] = change[key].newValue; - }); - } - }); -}()); \ No newline at end of file +}; \ No newline at end of file diff --git a/lib/frame.js b/lib/frame.js index 6e72fe4..07794a4 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -4,6 +4,25 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ (function(){ "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 {ask} = require("./askForPermission.js"); const {check: originalCheck, checkStack: originalCheckStack} = require("./check.js"); @@ -11,7 +30,7 @@ // Variable to "unload" the script var enabled = true; - + log("starting", location.href); function check(message){ if (enabled){ @@ -40,7 +59,7 @@ var tabId; port.onMessage.addListener(function(data){ if (data.hasOwnProperty("tabId")){ - console.log("my tab id is", data.tabId); + log("my tab id is", data.tabId); tabId = data.tabId; } }); @@ -50,7 +69,6 @@ port.postMessage({"canvasBlocker-notify": data}); } - const preferences = require("sdk/simple-prefs"); function prefs(name){ return preferences.prefs[name]; @@ -59,7 +77,7 @@ var interceptedWindows = new WeakMap(); function interceptWindow(window){ - if (interceptedWindows.get(window)){ + if (!enabled || interceptedWindows.get(window)){ return false; } intercept( @@ -102,10 +120,8 @@ return true; }; - if (enabled){ - interceptWindow(window); - } - + interceptWindow(window); + browser.runtime.onMessage.addListener(function(data){ if (data["canvasBlocker-unload"]){ enabled = false; @@ -117,4 +133,13 @@ }); } }); + + + browser.storage.onChanged.addListener(function(change, area){ + if (area === "local"){ + Object.keys(change).forEach(function(key){ + settings[key] = change[key].newValue; + }); + } + }); }()); \ No newline at end of file