Created
August 4, 2016 17:07
-
-
Save bitdivine/4f429eaec07db631f0e192d68b9ce86e to your computer and use it in GitHub Desktop.
Save html inputs in the location hash.
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
| function get_input_dict(selector){return Array.from(document.querySelectorAll(selector || 'input')).reduce((d,n)=>{d[n.name]=n.value;return d;},{});} | |
| function get_input_hash(selector){return Array.from(document.querySelectorAll(selector || 'input')).map((n)=>encodeURIComponent(n.name)+'='+encodeURIComponent(n.value)).join('&');} | |
| function save_input_hash(selector){window.location.hash = get_input_hash(selector);} | |
| function restore_input_hash(selector){window.location.hash.slice(1).split('&').map((s)=>s.match(/^([^=]*)=(.*)/)).filter((s)=>s).forEach((m)=>Array.from(document.querySelectorAll(`${selector||"input"}[name=${decodeURIComponent(m[1])}]`)).forEach((n) => n.value=decodeURIComponent(m[2])));} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment