Last active
March 2, 2018 14:49
-
-
Save negipo/ca76c401178942f8b34c02de0121a192 to your computer and use it in GitHub Desktop.
this bookmarklet saves form input values into localStorage
This file contains 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
javascript:(() => { | |
let storageKey = 'input_values'; | |
let results = localStorage.getItem(storageKey); | |
if(results) { | |
if(confirm('反映しますか')) { | |
results = JSON.parse(results); | |
for(let key in results) { | |
let element = document.querySelector(`*[name="${key}"]`); | |
if(element) { | |
element.value = results[key]; | |
} | |
} | |
return; | |
} | |
} | |
if(confirm('保存しますか')) { | |
let inputs = [...document.querySelectorAll('input:not([type="password"]):not([type="hidden"]),textarea,select')]; | |
let currentResults = {}; | |
for(let input of inputs) { | |
currentResults[input.name] = input.value; | |
} | |
localStorage.setItem(storageKey, JSON.stringify(currentResults)); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment