add import-export for more stickiness

master
bel 2023-09-17 09:13:16 -06:00
parent 4b7fd2acf8
commit ac376d88b2
1 changed files with 29 additions and 2 deletions

View File

@ -25,6 +25,13 @@
<script>
function init() {
load()
save()
}
function doimport() {
var marshalled = document.getElementById("import").value
load_json(marshalled)
save()
}
function reset() {
@ -47,6 +54,10 @@
var marshalled = localStorage.getItem("data")
if (!marshalled)
return
load_json(marshalled)
}
function load_json(marshalled) {
var data = JSON.parse(marshalled)
var inputs = document.getElementById("form").getElementsByTagName("input")
var i = 0;
@ -68,9 +79,14 @@
data.push({name: input.name, value: input.value, checked: input.checked})
}
var marshalled = JSON.stringify(data)
localStorage.setItem("data", marshalled)
save_json(marshalled)
console.log(new Date(), "saved", data)
}
function save_json(marshalled) {
localStorage.setItem("data", marshalled)
document.getElementById("export").value = marshalled
}
</script>
</header>
<body onload="init();">
@ -272,6 +288,17 @@
</notes>
</free_company>
</form>
<io>
<details>
<summary>EXPORT</summary>
<textarea id="export" style="width: 100%"></textarea><br>
</details>
<details>
<summary>IMPORT</summary>
<textarea id="import" style="width: 100%"></textarea><br>
<button onclick="doimport(); return false;">IMPORT</button>
</details>
<button onclick="reset(); return false;">RESET</button>
</io>
</body>
</html>