Created
October 30, 2018 03:04
-
-
Save mallendeo/5954b052f5c8b4e70f1fd104c5b0183a to your computer and use it in GitHub Desktop.
Saves any page forms in localStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 407 bytes minified | |
{ | |
let ls = localStorage | |
let loc = location | |
let option = prompt('s/ave, c/lear, f/ill', 'f') | |
let index = option[0] == 'h' ? 1 : 0 | |
let key = 'f:' + (index ? loc.host : loc.href) | |
let elems = document.querySelectorAll('input:not([type="file"]),textarea,select') | |
option[index] == 's' && ls.setItem( | |
key, | |
JSON.stringify( | |
[...elems].map(el => [el.value, el.checked]) | |
) | |
) | |
option[index] == 'c' && ls.removeItem(key) | |
JSON.parse(ls.getItem(key)) | |
.map(([value, checked], index) => { | |
elems[index].value = value | |
elems[index].checked = checked | |
elems[index].dispatchEvent(new Event('change', { 'bubbles': true })) | |
}) | |
} | |
// add as a bookmark | |
// javascript:{let a=localStorage,b=location,c=prompt('s/ave, c/lear, f/ill','f'),d='h'==c[0]?1:0,e='f:'+(d?b.host:b.href),f=document.querySelectorAll('input:not([type="file"]),textarea,select');'s'==c[d]&&a.setItem(e,JSON.stringify([...f].map(g=>[g.value,g.checked]))),'c'==c[d]&&a.removeItem(e),JSON.parse(a.getItem(e)).map(([g,h],i)=>{f[i].value=g,f[i].checked=h,f[i].dispatchEvent(new Event('change',{bubbles:!0}))})} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment