From 015f5bad3f6e4058d6bfeb8f6bf213de37464da7 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 20 Dec 2014 16:46:32 +0000 Subject: Exclusion; allow multiple matching rules. --- background_scripts/exclusions.coffee | 2 ++ 1 file changed, 2 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index 2b34238b..ac0e5f20 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -18,6 +18,8 @@ RegexpCache = # The exclusions are an array of such objects (because the order matters). root.Exclusions = Exclusions = + # Make RegexpCache, which is required on the page popup, accessible via Exclusions. + RegexpCache: RegexpCache rules: Settings.get("exclusionRules") -- cgit v1.2.3 From e2fe06c25ad0d478a602f77d3ea052ac0e886233 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 21 Dec 2014 05:28:02 +0000 Subject: Exclusion; minor refactoring. --- background_scripts/exclusions.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index ac0e5f20..fd74e7da 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -18,7 +18,7 @@ RegexpCache = # The exclusions are an array of such objects (because the order matters). root.Exclusions = Exclusions = - # Make RegexpCache, which is required on the page popup, accessible via Exclusions. + # Make RegexpCache, which is required on the page popup, accessible via the Exclusions object. RegexpCache: RegexpCache rules: Settings.get("exclusionRules") -- cgit v1.2.3 From 681bc13783d1f1b8579f810dbbc68174a84c1a10 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 21 Dec 2014 06:39:46 +0000 Subject: Exclusion; multi-rule matching. --- background_scripts/exclusions.coffee | 24 +++++++----------------- background_scripts/main.coffee | 19 ++----------------- 2 files changed, 9 insertions(+), 34 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index fd74e7da..db86e583 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -23,11 +23,14 @@ root.Exclusions = Exclusions = rules: Settings.get("exclusionRules") - # Return the first exclusion rule matching the URL, or null. + # Merge the matching rules for URL, or null. getRule: (url) -> - for rule in @rules - return rule if url.match(RegexpCache.get(rule.pattern)) - return null + matching = (rule for rule in @rules when url.match(RegexpCache.get(rule.pattern))) + if matching.length + pattern: (rule.pattern for rule in matching).join " | " # Not used; for documentation/debugging only. + passKeys: (rule.passKeys for rule in matching).join "" + else + null setRules: (rules) -> # Callers map a rule to null to have it deleted, and rules without a pattern are useless. @@ -37,19 +40,6 @@ root.Exclusions = Exclusions = postUpdateHook: (rules) -> @rules = rules - # Update an existing rule or add a new rule. - updateOrAdd: (newRule) -> - seen = false - @rules.push(newRule) - @setRules @rules.map (rule) -> - if rule.pattern == newRule.pattern - if seen then null else seen = newRule - else - rule - - remove: (pattern) -> - @setRules(@rules.filter((rule) -> rule and rule.pattern != pattern)) - # Development and debug only. # Enable this (temporarily) to restore legacy exclusion rules from backup. if false and Settings.has("excludedUrlsBackup") diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 647923c0..cebb38ca 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -75,26 +75,10 @@ getCurrentTabUrl = (request, sender) -> sender.tab.url root.isEnabledForUrl = isEnabledForUrl = (request) -> rule = Exclusions.getRule(request.url) { - rule: rule isEnabledForUrl: not rule or rule.passKeys passKeys: rule?.passKeys or "" } -# Called by the popup UI. -# If the URL pattern matches an existing rule, then the existing rule is updated. Otherwise, a new rule is created. -root.addExclusionRule = (pattern,passKeys) -> - if pattern = pattern.trim() - Exclusions.updateOrAdd({ pattern: pattern, passKeys: passKeys }) - chrome.tabs.query({ windowId: chrome.windows.WINDOW_ID_CURRENT, active: true }, - (tabs) -> updateActiveState(tabs[0].id)) - -# Called by the popup UI. Remove all existing exclusion rules with this pattern. -root.removeExclusionRule = (pattern) -> - if pattern = pattern.trim() - Exclusions.remove(pattern) - chrome.tabs.query({ windowId: chrome.windows.WINDOW_ID_CURRENT, active: true }, - (tabs) -> updateActiveState(tabs[0].id)) - saveHelpDialogSettings = (request) -> Settings.set("helpDialog_showAdvancedCommands", request.showAdvancedCommands) @@ -353,7 +337,8 @@ setBrowserActionIcon = (tabId,path) -> # Updates the browserAction icon to indicate whether Vimium is enabled or disabled on the current page. # Also propagates new enabled/disabled/passkeys state to active window, if necessary. # This lets you disable Vimium on a page without needing to reload. -updateActiveState = (tabId) -> +# Exported via root because it's called from the page popup. +root.updateActiveState = updateActiveState = (tabId) -> enabledIcon = "icons/browser_action_enabled.png" disabledIcon = "icons/browser_action_disabled.png" partialIcon = "icons/browser_action_partial.png" -- cgit v1.2.3 From d715bf897dd72bfad8aa6573e1919afc66b02e3a Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 21 Dec 2014 09:24:37 +0000 Subject: Exclusion; absolute exclusion rules taje priority. --- background_scripts/exclusions.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index db86e583..a8d65d62 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -26,8 +26,11 @@ root.Exclusions = Exclusions = # Merge the matching rules for URL, or null. getRule: (url) -> matching = (rule for rule in @rules when url.match(RegexpCache.get(rule.pattern))) + # An absolute exclusion rule (with no passKeys) takes priority. + for rule in matching + return rule unless rule.passKeys if matching.length - pattern: (rule.pattern for rule in matching).join " | " # Not used; for documentation/debugging only. + pattern: (rule.pattern for rule in matching).join " | " # Not used; for debugging only. passKeys: (rule.passKeys for rule in matching).join "" else null -- cgit v1.2.3 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 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'background_scripts') 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 -- cgit v1.2.3 From b0c9a764c77a451726049a79a19a0fa28ae0b30c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 21 Dec 2014 11:58:01 +0000 Subject: Exclusion; unique keys. --- background_scripts/exclusions.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index 12d86f41..f2dd14c8 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -31,7 +31,7 @@ root.Exclusions = Exclusions = return rule unless rule.passKeys if matching.length pattern: (rule.pattern for rule in matching).join " | " # Not used; for debugging only. - passKeys: (rule.passKeys for rule in matching).join "" + passKeys: Utils.uniqueCharacters (rule.passKeys for rule in matching).join "" else null -- cgit v1.2.3 From 30ea18e3c8c59b7579dac57c83812a0306cefe5c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 21 Dec 2014 13:42:37 +0000 Subject: Exclusion; fix tests. --- background_scripts/exclusions.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index f2dd14c8..467e5e70 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -15,7 +15,7 @@ RegexpCache = # The Exclusions class manages the exclusion rule setting. # An exclusion is an object with two attributes: pattern and passKeys. -# The exclusions are an array of such objects (because the order matters). +# The exclusions are an array of such objects. root.Exclusions = Exclusions = # Make RegexpCache, which is required on the page popup, accessible via the Exclusions object. -- cgit v1.2.3 From 3aeb8517d0dd5f9a530e99db662a4945132cf436 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 21 Dec 2014 15:40:10 +0000 Subject: Exclusion; minor updates after review. --- background_scripts/exclusions.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index 467e5e70..62647bd8 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -25,13 +25,13 @@ root.Exclusions = Exclusions = # 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))) + matches = (rule for rule in rules when rule.pattern and 0 <= url.search(RegexpCache.get(rule.pattern))) # An absolute exclusion rule (with no passKeys) takes priority. - for rule in matching + for rule in matches return rule unless rule.passKeys - if matching.length - pattern: (rule.pattern for rule in matching).join " | " # Not used; for debugging only. - passKeys: Utils.uniqueCharacters (rule.passKeys for rule in matching).join "" + if matches.length + pattern: (rule.pattern for rule in matches).join " | " # Not used; for debugging only. + passKeys: Utils.uniqueCharacters (rule.passKeys for rule in matches).join "" else null -- cgit v1.2.3 From b5c0b8da794407bc72f9f43da40422ed23e3899e Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 30 Dec 2014 10:58:46 +0000 Subject: Exclusions; use querySelector to find sub-elements. As @philc pointed out in #1366, this is less brittle. --- background_scripts/exclusions.coffee | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index 62647bd8..55ced3ef 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -23,15 +23,17 @@ root.Exclusions = Exclusions = rules: Settings.get("exclusionRules") - # Merge the matching rules for URL, or null. If rules are provided, match against those. + # Merge the matching rules for URL, or null. In the normal case, we use the configured @rules; hence, this + # is the default. However, when called from the page popup, we are testing what effect candidate new rules + # would have on the current tab. In this case, the candidate rules are provided by the caller. getRule: (url, rules=@rules) -> matches = (rule for rule in rules when rule.pattern and 0 <= url.search(RegexpCache.get(rule.pattern))) # An absolute exclusion rule (with no passKeys) takes priority. for rule in matches return rule unless rule.passKeys - if matches.length + if 0 < matches.length pattern: (rule.pattern for rule in matches).join " | " # Not used; for debugging only. - passKeys: Utils.uniqueCharacters (rule.passKeys for rule in matches).join "" + passKeys: Utils.distinctCharacters (rule.passKeys for rule in matches).join "" else null -- cgit v1.2.3