-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.coffee
More file actions
103 lines (86 loc) · 2.65 KB
/
popup.coffee
File metadata and controls
103 lines (86 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
## the UI for backmark
buildElements = () ->
getBookmarksInfo()
.then (bookmarks) ->
bookmarks.map(Handlebars.templates['popup-bookmark'])
placeElements = () ->
buildElements().then (html) ->
$('#bookmarks-body').html(html)
setUpDynamicLinks()
setUpDynamicLinks = () ->
$('.downloadbackup').on('click', (evt) ->
evt.preventDefault()
url = evt.target.dataset.url
# getPage(url).then (dataUri) -> downloadPage(dataUri, url)
downloadPageWithAccept(url)
)
$('.download').on('click', (evt) ->
evt.preventDefault()
url = evt.target.dataset.url
backupUrl(url).then () -> placeElements()
)
setUpSettingHandlers = () ->
checkedUrls = () -> ($('.check:checked').parent().parent().find('a.download').map (i, a) -> a.attributes['data-url'].value).toArray()
# select all/none checkbox
$('#checkall').on('change', (evt) ->
checked = evt.target.checked
$('.check').map (i, c) -> c.checked = checked
)
# concurrency
getConcurrency().then (c) -> $('#concurrency').val(c)
$('#concurrency').on('change', (evt) -> setConcurrency(evt.target.valueAsNumber))
# retry after X days
getRetryDays().then (d) -> $('#retry-days').val(d)
$('#retry-days').on('change', (evt) -> setRetryDays(evt.target.valueAsNumber))
# regular backup selected
$('#start-missing').on('click', (evt) ->
chrome.runtime.sendMessage(
{msg: 'missingBackup'},
(rep) ->
console.log('done with missing backup', rep)
placeElements()
)
)
# multi-backup selected
$('#start-backup').on('click', (evt) ->
urls = checkedUrls()
chrome.runtime.sendMessage(
{msg: 'partialBackup', urls: urls},
(rep) ->
console.log('done with selected backup', rep)
placeElements()
)
)
# multi-download selected
$('#start-download').on('click', (evt) ->
urls = checkedUrls()
chrome.runtime.sendMessage(
{msg: 'partialDownload', urls: urls},
(rep) ->
console.log('done with download', rep)
)
)
# reset dialog
dialog = $('#confirm-reset').get(0)
$('#reset').on('click', (evt) ->
$('#close').on('click', (evt) -> dialog.close())
$('#erase').on('click', (evt) ->
eraseStorage()
.then () ->
dialog.close()
placeElements()
)
dialog.showModal()
)
# first-run dialog
$('#first-run-close').on('click', (evt) -> $('#first-run').get(0).close())
# open in tab
$('#tabify').on('click', (evt) ->
chrome.tabs.createAsync({url: 'popup.html'})
)
showDialogIfFirstRun = () ->
if window.location.href.endsWith('firstrun')
$('#first-run').get(0).show()
setUpSettingHandlers()
placeElements()
showDialogIfFirstRun()