-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
28 lines (25 loc) · 728 Bytes
/
options.js
File metadata and controls
28 lines (25 loc) · 728 Bytes
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
function validateWPM(n) {
return n >= 0 && n <= 1000
}
function saveOptions() {
const wpm = document.getElementById('default-wpm')
const status = document.getElementById('status')
if (!validateWPM(wpm.value)) {
status.innerHTML = 'error'
return
}
chrome.storage.local.set({ wpm: wpm.value }, () => {
status.innerHTML = 'saved'
setTimeout(() => status.innerHTML = ' ', 750)
})
}
function loadOptions() {
chrome.storage.local.get('wpm', ({ wpm }) => {
const wpmInput = document.getElementById('default-wpm')
wpmInput.value = wpm
})
}
document.addEventListener('DOMContentLoaded', () => {
loadOptions()
document.getElementById('save').addEventListener('click', saveOptions)
})