Skip to content

Instantly share code, notes, and snippets.

@negipo
Last active March 2, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save negipo/ca76c401178942f8b34c02de0121a192 to your computer and use it in GitHub Desktop.
Save negipo/ca76c401178942f8b34c02de0121a192 to your computer and use it in GitHub Desktop.
this bookmarklet saves form input values into localStorage
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