diff --git a/extension/focus.js b/extension/focus.js index b5bd534..01ab53e 100644 --- a/extension/focus.js +++ b/extension/focus.js @@ -4,6 +4,7 @@ var conn = new FocusConnection(); conn.version = config.version; conn.platform = BrowserDetect.browser; +var isWhitelist = false; var isFocusing = false; var enableCloseBrowserTabs = false; var redirectURL; @@ -15,7 +16,7 @@ function onBeforeRequestHandler(info) { return {}; } - if (urlIsBlocked(info.url, compiledRegexSites)) { + if (urlIsBlocked(info.url, compiledRegexSites, isWhitelist)) { if (enableCloseBrowserTabs) { chrome.tabs.remove(info.tabId); } else { @@ -26,6 +27,7 @@ function onBeforeRequestHandler(info) { } function reset() { + isWhitelist = false; isFocusing = false; regexSites = []; compiledRegexSites = []; @@ -43,6 +45,8 @@ conn.focus = function(data) { } console.log("Focusing"); + + isWhitelist = data.whitelist; regexSites = data.regexSites; compiledRegexSites = compileRegexSites(data.regexSites); isFocusing = true; diff --git a/extension/utils.js b/extension/utils.js index 17d5542..d1896b5 100644 --- a/extension/utils.js +++ b/extension/utils.js @@ -56,10 +56,16 @@ function urlIsBlockedPage(url) { return false; } -function urlIsBlocked(url, compiledRegexSites) { +function urlIsBlocked(url, compiledRegexSites, isWhitelisted) { if (url == null) return false; - var isBlocked = false; + var isBlocked; + if (isWhitelisted) { + isBlocked = true; + } else { + isBlocked = false; + } + for (var compiledRegexSite of compiledRegexSites) { if (compiledRegexSite.compiledRegex.test(url)) { if (compiledRegexSite.whitelist) { @@ -108,11 +114,11 @@ function reloadShouldBeBlockedPages(compiledRegexSites) { forAllTabs((tab) => { if (urlIsBlockedPage(tab.url)) { var blockedUrl = getFocusURLFromProxyURL(tab.url); - if (!urlIsBlocked(blockedUrl, compiledRegexSites)) { + if (!urlIsBlocked(blockedUrl, compiledRegexSites, isWhitelist)) { chrome.tabs.reload(tab.id); } } else { - if (urlIsBlocked(tab.url, compiledRegexSites)) { + if (urlIsBlocked(tab.url, compiledRegexSites, isWhitelist)) { chrome.tabs.reload(tab.id); } }