Jyyjy commented on code in PR #410: URL: https://github.com/apache/flagon-useralejs/pull/410#discussion_r1483168069
########## build/UserALEWebExtension/background.js: ########## @@ -1131,28 +1155,48 @@ 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) { + urlWhitelist = new RegExp(config.pluginConfig.urlWhitelist); + options(config.useraleConfig); + dispatchTabMessage(config.useraleConfig); +} function dispatchTabMessage(message) { browser.tabs.query({}, function (tabs) { tabs.forEach(function (tab) { browser.tabs.sendMessage(tab.id, message); }); }); } +function filterUrl(log) { + if (urlWhitelist.test(log.pageUrl)) { + return log; + } + return false; +} +browser.storage.local.get(defaultConfig, function (res) { + addCallbacks({ + filterUrl: filterUrl + }); + updateConfig(res); +}); browser.runtime.onMessage.addListener(function (message) { switch (message.type) { // Handles logs rerouted from content and option scripts case ADD_LOG: - log(message.payload); + var log$1 = filterUrl(message.payload); Review Comment: This is an artifact of unclear behavior of the current logging callback api. Callbacks are not executed by log(), so I am mimicking the handling of callback results in packagelog() here in the message handler. This is so there can be a single place where URL filtering logic is defined. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@flagon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@flagon.apache.org For additional commands, e-mail: notifications-h...@flagon.apache.org