-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
36 lines (30 loc) · 981 Bytes
/
options.js
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
const {button, form, input, label} = hyperscriptHelpers(h)
document.addEventListener('DOMContentLoaded', restoreOptions)
function restoreOptions() {
chrome.storage.local.get('organization', ({organization}) => {
const mountNode = document.querySelector('body')
mountNode.innerHTML = optionsView(organization)
const saveButton = document.querySelector('#save')
saveButton.onclick = e => {
saveOptions()
e.preventDefault()
}
})
}
function saveOptions() {
const inputOrganization = document.querySelector('#organization')
const organization = inputOrganization.value
if (organization) {
chrome.storage.local.set({organization})
} else {
chrome.storage.local.remove('organization')
}
console.log('saved', organization)
}
function optionsView(organization = '') {
return form([
label({for: 'organization'}, 'Organization'),
input({id: 'organization', value: organization}),
button({id: 'save'}, 'Save')
])
}