 #
 # TODO:
-# - automatic uname/site fill
 # - green acknowledgment on password change
 #
 # LATER:


class AutoFiller
  constructor: () ->
    @pagemod = null

  start: () ->
    if @pagemod != null
      return

    console.log "start"
    @pagemod = re_pagemod.PageMod {
      include: '*'
      exclude: [
        '*.js'
        '*.css'
      ]
      contentScriptWhen: "ready"
      contentScriptFile: [
        re_self.data.url('jquery.min.js')
        re_self.data.url('input-get.js')
      ]
      onAttach: (worker) ->
        worker.port.emit 'enable', re_tabs.activeTab.url

        worker.port.on 'username', (uname, url) ->
          console.log "gaining for: ", uname
          get_pass uname, url, (p) ->
            worker.port.emit 'pass', p
    }

  stop: () ->
    if @pagemod != null
      @pagemod.destroy()
      console.log "stop"
    @pagemod = null

  apply_stat: (stat) ->
    if stat == 0
      @.start()
    else if stat == 1
      @.stop()

auto_filler = new AutoFiller()
auto_filler.start()

#
# Observer to detect pageload and change icons accordingly


apply_stat_all = (stat) ->
  change_button_icon stat
  auto_filler.apply_stat stat, re_tabs.activeTab

function_on_change_url = (t) ->
  # check if enabled
