Skip to content

Commit

Permalink
added global whitelist back to firefox extension
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjasper committed Mar 28, 2019
1 parent b8f0492 commit 758844b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion extension/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -26,6 +27,7 @@ function onBeforeRequestHandler(info) {
}

function reset() {
isWhitelist = false;
isFocusing = false;
regexSites = [];
compiledRegexSites = [];
Expand All @@ -43,6 +45,8 @@ conn.focus = function(data) {
}

console.log("Focusing");

isWhitelist = data.whitelist;
regexSites = data.regexSites;
compiledRegexSites = compileRegexSites(data.regexSites);
isFocusing = true;
Expand Down
14 changes: 10 additions & 4 deletions extension/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 758844b

Please sign in to comment.