diff options
| author | Stephen Blott | 2014-09-05 10:59:20 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2014-09-06 12:28:40 +0100 | 
| commit | 643e49aa3109b9a25b38ce5d6b59bb11bc6337b1 (patch) | |
| tree | fcbfa9c0fe1a2a9e598ff9735301c8eb6c2913ae /background_scripts/exclusions.coffee | |
| parent | 2f27d4590ba30f5a443aedff12d9611a83a4f771 (diff) | |
| download | vimium-643e49aa3109b9a25b38ce5d6b59bb11bc6337b1.tar.bz2 | |
Structured passkeys; changes following code review; major rewrite of options.
Diffstat (limited to 'background_scripts/exclusions.coffee')
| -rw-r--r-- | background_scripts/exclusions.coffee | 47 | 
1 files changed, 19 insertions, 28 deletions
diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index 8242c81b..3a8ef1e7 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -23,8 +23,9 @@ root.Exclusions = Exclusions =      return null    setRules: (rules) -> +    # Callers map a rule to null to have it deleted, and rules without a pattern are useless.      @rules = rules.filter (rule) -> rule and rule.pattern -    Settings.set("exclusionRules",@rules) +    Settings.set("exclusionRules", @rules)    postUpdateHook: (rules) ->      @rules = rules @@ -33,37 +34,29 @@ root.Exclusions = Exclusions =    updateOrAdd: (newRule) ->      seen = false      @rules.push(newRule) -    @setRules(@rules.map (rule) -> if rule.pattern == newRule.pattern then (if seen then null else seen = newRule) else rule) +    @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.pattern != pattern)) - -  # DOM handling for the options page; populate the exclusionRules option. -  populateOption: (exclusionRulesElement,enableSaveButton) -> -    populate = => -      while exclusionRulesElement.firstChild -        exclusionRulesElement.removeChild(exclusionRulesElement.firstChild) -      for rule in @rules -        exclusionRulesElement.appendChild(ExclusionRule.buildRuleElement(rule,enableSaveButton)) -      exclusionRulesElement.appendChild(ExclusionRule.buildRuleElement({pattern: "", passKeys: ""},enableSaveButton)) -    populate() -    return { -      saveOption: => -        @setRules(ExclusionRule.extractRule(element) for element in exclusionRulesElement.getElementsByClassName('exclusionRow')) -        populate() -      restoreToDefault: => -        Settings.clear("exclusionRules") -        populate() -    } +    @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")    Settings.clear("exclusionRules") -  Settings.set("excludedUrls",Settings.get("excludedUrlsBackup")) +  Settings.set("excludedUrls", Settings.get("excludedUrlsBackup"))  if not Settings.has("exclusionRules") and Settings.has("excludedUrls") -  # Migration from the legacy exclusion rules (settings: "excludedUrls" -> "exclusionRules"). +  # Migration from the legacy representation of exclusion rules. +  # +  # In Vimium 1.45 and in github/master on 27 August, 2014, exclusion rules are represented by the setting: +  #   excludedUrls: "http*://www.google.com/reader/*\nhttp*://mail.google.com/* jk" +  # +  # The new (equivalent) settings is: +  #   exclusionRules: [ { pattern: "http*://www.google.com/reader/*", passKeys: "" }, { pattern: "http*://mail.google.com/*", passKeys: "jk" } ]    parseLegacyRules = (lines) ->      for line in lines.trim().split("\n").map((line) -> line.trim()) @@ -72,8 +65,6 @@ if not Settings.has("exclusionRules") and Settings.has("excludedUrls")          { pattern: parse[0], passKeys: parse[1..].join("") }    Exclusions.setRules(parseLegacyRules(Settings.get("excludedUrls"))) -  # We'll keep a backup of the excludedUrls setting, just in case (and for testing). -  Settings.set("excludedUrlsBackup",Settings.get("excludedUrls")) if not Settings.has("excludedUrlsBackup") -  # TODO (smblott): Uncomment the following line.  It's commented for now so that anyone trying out this code -  # can revert to previous versions. -  # Settings.clear("excludedUrls") +  # We'll keep a backup of the "excludedUrls" setting, just in case. +  Settings.set("excludedUrlsBackup", Settings.get("excludedUrls")) if not Settings.has("excludedUrlsBackup") +  Settings.clear("excludedUrls")  | 
