aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/exclusions.coffee24
-rw-r--r--background_scripts/main.coffee19
2 files changed, 9 insertions, 34 deletions
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"