From e82376a7ef8922f8c4f8a871e45d2b53a228a91f Mon Sep 17 00:00:00 2001 From: achmizs Date: Thu, 31 Jan 2019 10:10:20 -0500 Subject: [PATCH] Many bug fixes --- contentScript.js | 11 ++++++----- popup.js | 38 ++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/contentScript.js b/contentScript.js index 40defe5..df74669 100644 --- a/contentScript.js +++ b/contentScript.js @@ -11,19 +11,20 @@ function killStickyIfMatch(result) { var shouldKillSticky = false; let matchingPatterns = result.mode == "whitelist" ? [ ".*" ] : - result.matchingPatterns.split("\n"); + (typeof result.matchingPatterns != "undefined" ? + result.matchingPatterns.split("\n") : + [ ]); for (let pattern of matchingPatterns) { - if (location.href.match(new RegExp(pattern))) { + if (pattern && location.href.match(new RegExp(pattern))) { shouldKillSticky = true; break; } } - let exclusionPatterns = (typeof result.exclusionPatterns != "undefined" && - result.exclusionPatterns != "") ? + let exclusionPatterns = typeof result.exclusionPatterns != "undefined" ? result.exclusionPatterns.split("\n") : [ ]; for (let pattern of exclusionPatterns) { - if (location.href.match(new RegExp(pattern))) { + if (pattern && location.href.match(new RegExp(pattern))) { shouldKillSticky = false; break; } diff --git a/popup.js b/popup.js index 8a8d4f9..3e1627e 100644 --- a/popup.js +++ b/popup.js @@ -1,8 +1,3 @@ -/*******************/ -/* EVENT LISTENERS */ -/*******************/ - - /***********/ /* HELPERS */ /***********/ @@ -74,13 +69,13 @@ function recalculatePatternEffects() { ASK.pageMatched = false; ASK.pageExcluded = false; for (let pattern of ASK.matchingPatterns) { - if (ASK.activeTabLocation.match(new RegExp(pattern))) { + if (pattern && ASK.activeTabLocation.match(new RegExp(pattern))) { ASK.pageMatched = true; break; } } for (let pattern of ASK.exclusionPatterns) { - if (ASK.activeTabLocation.match(new RegExp(pattern))) { + if (pattern && ASK.activeTabLocation.match(new RegExp(pattern))) { ASK.pageExcluded = true; break; } @@ -91,9 +86,10 @@ function updateState(result) { ASK.mode = result.mode || "blacklist"; ASK.matchingPatterns = (ASK.mode == "whitelist") ? [ ".*" ] : - result.matchingPatterns.split("\n"); - ASK.exclusionPatterns = (typeof result.exclusionPatterns != "undefined" && - result.exclusionPatterns != "") ? + (typeof result.matchingPatterns != "undefined" ? + result.matchingPatterns.split("\n") : + [ ]); + ASK.exclusionPatterns = typeof result.exclusionPatterns != "undefined" ? result.exclusionPatterns.split("\n") : [ ]; recalculatePatternEffects(); @@ -125,6 +121,7 @@ function updateUIState() { function initialize() { window.ASK = { }; + // Retrieve saved settings. chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { ASK.activeTabLocation = tabs[0].url; chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { @@ -133,17 +130,17 @@ function initialize() { }); }); + // Listener for main button. document.querySelector("button.main-button").addActivateEvent((event) => { toggleState(); - let matchingPatterns = ASK.matchingPatterns.join("\n"); - let exclusionPatterns = ASK.exclusionPatterns.join("\n"); - let mode = ASK.mode; - chrome.storage.sync.set({ - "matchingPatterns": matchingPatterns, - "exclusionPatterns": exclusionPatterns, - "mode": mode - }, () => { + var changes = { + "exclusionPatterns": ASK.exclusionPatterns.join("\n"), + "mode": ASK.mode + }; + if (ASK.mode == "blacklist") + changes.matchingPatterns = ASK.matchingPatterns.join("\n"); + chrome.storage.sync.set(changes, () => { updateUIState(); let reloadButton = document.querySelector("button.reload-button"); if (ASK.pageMatched && !ASK.pageExcluded) { @@ -155,11 +152,12 @@ function initialize() { }); }); - + // Listener for Options button. document.querySelector("button.options-button").addActivateEvent(() => { chrome.runtime.openOptionsPage(null); }); - + + // Listener for reload button (appears when sticky-killing is toggled OFF). document.querySelector("button.reload-button").addActivateEvent(() => { chrome.tabs.update(null, { url: ASK.activeTabLocation }); window.close();