From ace1a1be349c279fe87b536f786bb32c4e17f889 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 13 Apr 2017 15:05:38 +0200 Subject: download/import db from dump page --- src/pages/show-db.ts | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/pages/show-db.ts') diff --git a/src/pages/show-db.ts b/src/pages/show-db.ts index 71e74388b..955253680 100644 --- a/src/pages/show-db.ts +++ b/src/pages/show-db.ts @@ -28,7 +28,7 @@ function replacer(match: string, pIndent: string, pKey: string, pVal: string, var str = ''; var r = pIndent || ''; if (pKey) { - r = r + key + pKey.replace(/[": ]/g, '') + ': '; + r = r + key + '"' + pKey.replace(/[": ]/g, '') + '": '; } if (pVal) { r = r + (pVal[0] == '"' ? str : val) + pVal + ''; @@ -53,5 +53,42 @@ document.addEventListener("DOMContentLoaded", () => { throw Error(); } el.innerHTML = prettyPrint(resp); + + document.getElementById("download")!.addEventListener("click", (evt) => { + console.log("creating download"); + let element = document.createElement("a"); + element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(JSON.stringify(resp))); + element.setAttribute("download", "wallet-dump.txt"); + element.style.display = "none"; + document.body.appendChild(element); + element.click(); + }); + + }); + + + let fileInput = document.getElementById("fileInput")! as HTMLInputElement; + fileInput.onchange = (evt) => { + if (!fileInput.files || fileInput.files.length != 1) { + alert("please select exactly one file to import"); + return; + } + const file = fileInput.files[0]; + const fr = new FileReader(); + fr.onload = (e: any) => { + console.log("got file"); + let dump = JSON.parse(e.target.result); + console.log("parsed contents", dump); + chrome.runtime.sendMessage({ type: 'import-db', detail: { dump } }, (resp) => { + alert("loaded"); + }); + }; + console.log("reading file", file); + fr.readAsText(file); + }; + + document.getElementById("import")!.addEventListener("click", (evt) => { + fileInput.click(); + evt.preventDefault(); }); }); -- cgit v1.2.3