   for field in ["popupPattern", "popupPassKeys"]
     for event in ["input", "change"]
       document.getElementById(field).addEventListener event, onChange, false
-  onLoad true
+  reset true

  passKeys = document.getElementById("popupPassKeys").value.trim()
  chrome.extension.getBackgroundPage().addExclusionRule pattern, passKeys
  showMessage("Updated.")
  onLoad()

removeExclusionRule = ->
  pattern = document.getElementById("popupPattern").value.trim()
  chrome.extension.getBackgroundPage().removeExclusionRule pattern
  showMessage("Removed.")
  onLoad()

document.addEventListener "DOMContentLoaded", ->
  document.getElementById("popupExclude").addEventListener "click", addExclusionRule, false

originalPattern = undefined
originalPassKeys = undefined

reset = (initialize=false) ->
  document.getElementById("optionsLink").setAttribute "href", chrome.runtime.getURL("pages/options.html")
  chrome.tabs.getSelected null, (tab) ->
    isEnabled = chrome.extension.getBackgroundPage().isEnabledForUrl(url: tab.url)
