mirror of
https://github.com/jlelse/GoBlog
synced 2024-06-08 06:56:28 +00:00
19 lines
669 B
JavaScript
19 lines
669 B
JavaScript
(function () {
|
|
const fc = 'formcache'
|
|
Array.from(document.querySelectorAll('form .' + fc)).forEach(element => {
|
|
let elementName = fc + '-' + location.pathname + '#' + element.id
|
|
// Load from cache
|
|
let cached = localStorage.getItem(elementName)
|
|
if (cached != null) {
|
|
element.value = cached
|
|
}
|
|
// Auto save to cache
|
|
element.addEventListener('input', function () {
|
|
localStorage.setItem(elementName, element.value)
|
|
})
|
|
// Clear on submit
|
|
element.form.addEventListener('submit', function () {
|
|
localStorage.removeItem(elementName)
|
|
})
|
|
})
|
|
})() |