From 3c96a9e3f56e9712c891e1da0ccf6fb76f67b832 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Sat, 11 Oct 2014 00:07:51 +0200 Subject: [PATCH] More flexible list checking --- lib/main.js | 106 +++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 51 deletions(-) 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){