2015-05-10 14:38:17 +00:00
|
|
|
if window.Storage and window.JSON
|
|
|
|
window.$storage = (key) ->
|
|
|
|
set: (value) ->
|
|
|
|
localStorage.setItem(key, JSON.stringify(value))
|
|
|
|
get: ->
|
|
|
|
item = localStorage.getItem(key)
|
|
|
|
JSON.parse(item) if item
|
|
|
|
|
|
|
|
$ ->
|
|
|
|
window.lastLoad = now()
|
|
|
|
window.refreshPassword = 30000
|
|
|
|
window.tickerInterval = 200
|
|
|
|
|
|
|
|
window.ticker = setInterval tick, window.tickerInterval
|
|
|
|
$('#focusedInput').bind 'click', stopRefresh
|
|
|
|
$('#focusedInput').bind 'blur', restartRefresh
|
|
|
|
$('#optionSave').bind 'click', saveOptions
|
|
|
|
|
|
|
|
loadOptions()
|
|
|
|
loadPassword()
|
|
|
|
|
|
|
|
now = () ->
|
|
|
|
d = new Date()
|
|
|
|
d.getTime()
|
|
|
|
|
|
|
|
stopRefresh = () ->
|
|
|
|
clearInterval(window.ticker)
|
|
|
|
$('#focusedInput').select()
|
|
|
|
false
|
|
|
|
|
|
|
|
restartRefresh = () ->
|
|
|
|
window.lastLoad = now()
|
|
|
|
window.ticker = setInterval tick, window.tickerInterval
|
|
|
|
|
|
|
|
setProgress = (perc) ->
|
|
|
|
$('.progress-bar').css('width', "#{perc}%")
|
|
|
|
|
|
|
|
loadPassword = () ->
|
|
|
|
options = loadOptions()
|
2017-10-31 11:12:51 +00:00
|
|
|
$.get "/v1/getPassword?length=#{options.passwordLength}&special=#{options.useSpecial}&xkcd=#{options.useXKCD}", (data) ->
|
2015-05-10 14:38:17 +00:00
|
|
|
$('#focusedInput').val(data)
|
|
|
|
window.lastLoad = now()
|
|
|
|
|
|
|
|
saveOptions = () ->
|
|
|
|
options =
|
|
|
|
passwordLength: $('#passwordLengthOption').val()
|
|
|
|
useSpecial: $('#useSpecialOption')[0].checked
|
2017-10-31 11:12:51 +00:00
|
|
|
useXKCD: $('#useXKCDOption')[0].checked
|
2015-05-10 14:38:17 +00:00
|
|
|
|
|
|
|
window.$storage('SecurePasswordOptions').set(options)
|
|
|
|
$('#settingsModal').modal('hide')
|
|
|
|
loadPassword()
|
|
|
|
|
|
|
|
loadOptions = () ->
|
|
|
|
options = window.$storage('SecurePasswordOptions').get()
|
|
|
|
if options == undefined
|
|
|
|
options =
|
|
|
|
passwordLength: 20
|
|
|
|
useSpecial: false
|
2017-10-31 11:12:51 +00:00
|
|
|
useXKCD: false
|
2015-05-10 14:38:17 +00:00
|
|
|
$('#passwordLengthOption').val(options.passwordLength)
|
|
|
|
$('#useSpecialOption')[0].checked = options.useSpecial
|
2017-10-31 11:12:51 +00:00
|
|
|
$('#useXKCDOption')[0].checked = options.useXKCD
|
2015-05-10 14:38:17 +00:00
|
|
|
options
|
|
|
|
|
|
|
|
tick = () ->
|
|
|
|
diff = now() - window.lastLoad
|
|
|
|
perc = (window.refreshPassword - diff) / window.refreshPassword * 100
|
|
|
|
setProgress perc
|
|
|
|
if diff >= window.refreshPassword
|
|
|
|
loadPassword()
|