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 | |
| parent | 2f27d4590ba30f5a443aedff12d9611a83a4f771 (diff) | |
| download | vimium-643e49aa3109b9a25b38ce5d6b59bb11bc6337b1.tar.bz2 | |
Structured passkeys; changes following code review; major rewrite of options.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/exclusions.coffee | 47 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 4 | ||||
| -rw-r--r-- | background_scripts/settings.coffee | 6 |
3 files changed, 24 insertions, 33 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") diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 4e6f406e..352cfa48 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -80,8 +80,8 @@ root.isEnabledForUrl = isEnabledForUrl = (request) -> passKeys: rule?.passKeys or "" } -# Called by the popup UI. If an existing exclusion rule has been changed, then the existing rule is updated. -# Otherwise, the new rule is added. +# 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 }) diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index 63dd851b..7150fcba 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -61,6 +61,7 @@ root.Settings = Settings = # or strings defaults: scrollStepSize: 60 + keyMappings: "# Insert your prefered key mappings here." linkHintCharacters: "sadfjklewcmpgh" linkHintNumbers: "0123456789" filterLinkHints: false @@ -87,9 +88,8 @@ root.Settings = Settings = # Default exclusion rules. exclusionRules: [ - # Disable Vimium on Google Reader, and use Gmail's own j/k bindings. - { pattern: "http*://www.google.com/reader/*", passKeys: "" } - { pattern: "http*://mail.google.com/*", passKeys: "jk" } + # Disable Vimium on Gmail. + { pattern: "http*://mail.google.com/*", passKeys: "" } ] # NOTE: If a page contains both a single angle-bracket link and a double angle-bracket link, then in |
