diff --git a/lib/main.js b/lib/main.js index 8da65a6..3305609 100644 --- a/lib/main.js +++ b/lib/main.js @@ -71,59 +71,63 @@ preferences.on("blackList", function(){ updateBlackList(); }); - + + function checkURL(url){ + var url = new URL(url); + var mode = "block"; + switch (prefs.blockMode){ + case "blockEverything": + mode = "block"; + break; + case "allowOnlyWhiteList": + if (whiteList.match(url)){ + mode = "unblock"; + } + else { + mode = "block"; + } + break; + case "ask": + if (whiteList.match(url)){ + mode = "unblock"; + } + else if (blackList.match(url)){ + mode = "block"; + } + else { + mode = "ask"; + } + break; + case "blockReadout": + if (whiteList.match(url)){ + mode = "unblock"; + } + else if (blackList.match(url)){ + mode = "block"; + } + else { + mode = "blockReadout"; + } + break; + case "blockOnlyBlackList": + if (blackList.match(url)){ + mode = "block"; + } + else { + mode = "unblock"; + } + break; + case "allowEverything": + mode = "unblock"; + break; + default: + console.log("Unknown blocking mode. Default to block everything."); + } + return mode; + } function checkWorker(worker){ try { - var url = new URL(worker.url); - var mode = "block"; - switch (prefs.blockMode){ - case "blockEverything": - mode = "block"; - break; - case "allowOnlyWhiteList": - if (whiteList.match(url)){ - mode = "unblock"; - } - else { - mode = "block"; - } - break; - case "ask": - if (whiteList.match(url)){ - mode = "unblock"; - } - else if (blackList.match(url)){ - mode = "block"; - } - else { - mode = "ask"; - } - break; - case "blockReadout": - if (whiteList.match(url)){ - mode = "unblock"; - } - else if (blackList.match(url)){ - mode = "block"; - } - else { - mode = "blockReadout"; - } - break; - case "blockOnlyBlackList": - if (blackList.match(url)){ - mode = "block"; - } - else { - mode = "unblock"; - } - break; - case "allowEverything": - mode = "unblock"; - break; - default: - console.log("Unknown blocking mode. Default to block everything."); - } + var mode = checkURL(worker.url); worker.port.emit(mode, false, prefs.askOnlyOnce); } catch (e){