Saving and Restoring <inputs />
I have made a pair of Javascript bookmarklets that allow you to save and load the contents of input boxes and textareas on any webpage.
To use them, simply drag the 2 links below to your bookmarks (bar), and click "Save Inputs" when you wish to save the contents of all the inputs, and click "Restore Inputs" and paste in the code you received from the "Save Inputs" bookmarklet to restore the contents of the input boxes on any given page.
Source Code
The (pretty printed and decoded) source code for the two bookmarklets can be found below:
Save Inputs
(function () {
var inputs = document.querySelectorAll("input, textarea"),
savedata = [];
for (var i = 0; i < inputs.length; i++)
{
savedata.push(inputs[i].value);
}
console.log(savedata);
prompt("< input / > and < textarea > savedata :", JSON.stringify(savedata));
})();
Restore Inputs
(function () {
var savedata = JSON.parse(prompt("Savedata: ", "")),
inputs = document.querySelectorAll("input, textarea");
for (var i = 0; i < savedata.length; i++)
{
inputs[i].value = savedata[i];
}
})();
Known Limitations
- The savedata code that the "Save Inputs" bookmarlet produces is not copied to the clipboard
- Strange things happen if you try to restore the contents of a set of input boxes from a savedata code from another page
- The script breaks if the input boxes on a page get changed
If you have a better version of these bookmarklets, please leave a comment below.
Found a spelling mistake? Got suggestion? Leave a comment below. Suggestions for improvement are always appreciated.