From 98fd49a6cfe660c363aecb6ebe0a4cb69342808d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 21 Dec 2014 11:49:13 +0000 Subject: Exclusion; show state. --- background_scripts/exclusions.coffee | 6 +++--- pages/options.coffee | 18 +++++++++++++++--- pages/popup.html | 26 +++++++++++++++----------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index a8d65d62..12d86f41 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -23,9 +23,9 @@ root.Exclusions = Exclusions = rules: Settings.get("exclusionRules") - # Merge the matching rules for URL, or null. - getRule: (url) -> - matching = (rule for rule in @rules when url.match(RegexpCache.get(rule.pattern))) + # Merge the matching rules for URL, or null. If rules are provided, match against those. + getRule: (url, rules=@rules) -> + matching = (rule for rule in rules when rule.pattern and url.match(RegexpCache.get(rule.pattern))) # An absolute exclusion rule (with no passKeys) takes priority. for rule in matching return rule unless rule.passKeys diff --git a/pages/options.coffee b/pages/options.coffee index cd932ed8..80c9ae44 100644 --- a/pages/options.coffee +++ b/pages/options.coffee @@ -161,8 +161,8 @@ class ExclusionRulesOption extends Option readValueFromElement: -> rules = for element in @element.getElementsByClassName "exclusionRuleTemplateInstance" - pattern = element.children[0].firstChild.value.trim() - passKeys = element.children[1].firstChild.value.trim() + pattern = element.children[0].firstChild.value.trim().split(/\s+/).join "" + passKeys = element.children[1].firstChild.value.trim().split(/\s+/).join "" { pattern: pattern, passKeys: passKeys } rules.filter (rule) -> rule.pattern @@ -275,7 +275,19 @@ initPopupPage = -> window.close() # Populate options. Just one, here. - new ExclusionRulesOption("exclusionRules", onUpdated, tab.url) + exclusions = new ExclusionRulesOption("exclusionRules", onUpdated, tab.url) + + document.addEventListener "keyup", (event) -> + rules = exclusions.readValueFromElement() + isEnabled = bgExclusions.getRule tab.url, rules + console.log isEnabled + $("state").innerHTML = + if isEnabled and isEnabled.passKeys + "Excluded: #{isEnabled.passKeys}" + else if isEnabled + "Disabled" + else + "Enabled" # # Initialization. diff --git a/pages/popup.html b/pages/popup.html index 0b4de131..370751ff 100644 --- a/pages/popup.html +++ b/pages/popup.html @@ -7,12 +7,12 @@ padding: 0px; } - #helpText, #optionsLink { + #helpText, #optionsLink, #state { font-family : "Helvetica Neue", "Helvetica", "Arial", sans-serif; font-size: 12px; } - #helpText { color: #979ca0; } + #helpText, #stateLine { color: #979ca0; } #exclusionAddButton { width: 80px; } #saveOptions { @@ -67,16 +67,20 @@