diff --git a/build/UserALEWebExtension/background.js b/build/UserALEWebExtension/background.js index 82a41c07..5b7123b1 100644 --- a/build/UserALEWebExtension/background.js +++ b/build/UserALEWebExtension/background.js @@ -428,6 +428,30 @@ var intervalCounter; var intervalLog; var cbHandlers = {}; +/** + * Adds named callbacks to be executed when logging. + * @param {Object } newCallbacks An object containing named callback functions. + */ +function addCallbacks() { + for (var _len = arguments.length, newCallbacks = new Array(_len), _key = 0; _key < _len; _key++) { + newCallbacks[_key] = arguments[_key]; + } + newCallbacks.forEach(function (source) { + var descriptors = Object.keys(source).reduce(function (descriptors, key) { + descriptors[key] = Object.getOwnPropertyDescriptor(source, key); + return descriptors; + }, {}); + Object.getOwnPropertySymbols(source).forEach(function (sym) { + var descriptor = Object.getOwnPropertyDescriptor(source, sym); + if (descriptor.enumerable) { + descriptors[sym] = descriptor; + } + }); + Object.defineProperties(cbHandlers, descriptors); + }); + return cbHandlers; +} + /** * Assigns the config and log container to be used by the logging functions. * @param {Array} newLogs Log container. @@ -1131,11 +1155,20 @@ var defaultConfig = { authHeader: null, toolName: 'useralePlugin', version: version + }, + pluginConfig: { + // Default to a regex that will match no string + urlWhitelist: '(?!x)x' } }; -browser.storage.local.get(defaultConfig, function (res) { - options(res.useraleConfig); -}); +var urlWhitelist; +function updateConfig(config) { + console.log(config); + urlWhitelist = new RegExp(config.pluginConfig.urlWhitelist); + options(config.useraleConfig); + // TODO: tabs need a page load to apply this config change. + dispatchTabMessage(config.useraleConfig); +} function dispatchTabMessage(message) { browser.tabs.query({}, function (tabs) { tabs.forEach(function (tab) { @@ -1143,20 +1176,38 @@ function dispatchTabMessage(message) { }); }); } + +// Filter out logs with urls that do not match the regex defined in extension options. +function filterUrl(log) { + if (urlWhitelist.test(log.pageUrl)) { + return log; + } + return false; +} +browser.storage.local.get(defaultConfig, function (res) { + // Apply url filter to logs generated by the background page. + addCallbacks({ + filterUrl: filterUrl + }); + updateConfig(res); +}); browser.runtime.onMessage.addListener(function (message, sender, sendResponse) { switch (message.type) { - // Handles logs rerouted from content and option scripts + // Handles logs rerouted from content and option scripts. case ADD_LOG: var log$1 = message.payload; if ("tab" in sender && "id" in sender.tab) { log$1["tabId"] = sender.tab.id; } - log(log$1); + // Apply url filter to logs generated outside the background page. + log$1 = filterUrl(log$1); + if (log$1) { + console.log("match"); + log(log$1); + } break; case CONFIG_CHANGE: - console.log(message); - options(message.payload); - dispatchTabMessage(message); + updateConfig(message.payload); break; default: console.log('got unknown message type ', message); diff --git a/build/UserALEWebExtension/content.js b/build/UserALEWebExtension/content.js index 2c158e64..8dcf1de1 100644 --- a/build/UserALEWebExtension/content.js +++ b/build/UserALEWebExtension/content.js @@ -1100,6 +1100,7 @@ function options(newConfig) { // browser is defined in firefox, but chrome uses the 'chrome' global. var browser = browser || chrome; function rerouteLog(log) { + console.log("reroute"); browser.runtime.sendMessage({ type: ADD_LOG, payload: log @@ -1129,7 +1130,7 @@ function rerouteLog(log) { browser.storage.local.get("useraleConfig", function (res) { options(res.useraleConfig); addCallbacks({ - reroute: rerouteLog + rerouteLog: rerouteLog }); }); browser.runtime.onMessage.addListener(function (message) { diff --git a/build/UserALEWebExtension/options.js b/build/UserALEWebExtension/options.js index 8528ad8c..ba979862 100644 --- a/build/UserALEWebExtension/options.js +++ b/build/UserALEWebExtension/options.js @@ -1100,6 +1100,7 @@ function options(newConfig) { // browser is defined in firefox, but chrome uses the 'chrome' global. var browser = browser || chrome; function rerouteLog(log) { + console.log("reroute"); browser.runtime.sendMessage({ type: ADD_LOG, payload: log @@ -1127,7 +1128,7 @@ function rerouteLog(log) { */ addCallbacks({ - reroute: rerouteLog + rerouteLog: rerouteLog }); function setConfig() { var config = { @@ -1142,13 +1143,17 @@ function setConfig() { if (config.userId && password) { config.authHeader = "Basic " + btoa("".concat(config.userId, ":").concat(password)); } - browser.storage.local.set({ - useraleConfig: config - }, function () { + var payload = { + useraleConfig: config, + pluginConfig: { + urlWhitelist: document.getElementById("filter").value + } + }; + browser.storage.local.set(payload, function () { options(config); browser.runtime.sendMessage({ type: CONFIG_CHANGE, - payload: config + payload: payload }); }); } @@ -1161,6 +1166,9 @@ function getConfig() { document.getElementById("tool").value = config.toolName; document.getElementById("version").value = config.version; }); + browser.storage.local.get("pluginConfig", function (res) { + document.getElementById("filter").value = res.pluginConfig.urlWhitelist; + }); } document.addEventListener("DOMContentLoaded", getConfig); document.addEventListener("submit", setConfig); diff --git a/build/UserALEWebExtension/optionsPage.html b/build/UserALEWebExtension/optionsPage.html index ff92cf09..9a3f363b 100644 --- a/build/UserALEWebExtension/optionsPage.html +++ b/build/UserALEWebExtension/optionsPage.html @@ -45,6 +45,10 @@