mirror of
https://github.com/He4eT/browser-milje-2077.git
synced 2026-05-05 01:17:25 +00:00
options: load and save params
This commit is contained in:
parent
44e1e0e2fd
commit
48a86cea74
3 changed files with 88 additions and 11 deletions
|
|
@ -1 +1,34 @@
|
|||
// browser.storage.local.set({'params': {scaleFactor: 16}})
|
||||
import {
|
||||
fields,
|
||||
assureParams,
|
||||
getParamsFromStorage,
|
||||
setParamsToStorage,
|
||||
} from '../../scripts/params.js'
|
||||
|
||||
Promise.resolve()
|
||||
.then(getParamsFromStorage)
|
||||
.then(assureParams)
|
||||
.then(fillForm)
|
||||
.then(addFormHandler)
|
||||
|
||||
function fillForm (params) {
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
const input = document.getElementById(key)
|
||||
input.value = value
|
||||
input.dispatchEvent(new Event('input'))
|
||||
})
|
||||
}
|
||||
|
||||
function addFormHandler () {
|
||||
const form = document.getElementById('settingsForm')
|
||||
form.onsubmit = (e) => {
|
||||
e.preventDefault()
|
||||
|
||||
const formData = new FormData(e.target)
|
||||
const entries = [...formData.entries()]
|
||||
.filter(([key]) => fields.includes(key))
|
||||
const params = Object.fromEntries(entries)
|
||||
|
||||
setParamsToStorage(params)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue