aboutsummaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-04-13 15:05:38 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-04-13 15:05:38 +0200
commitace1a1be349c279fe87b536f786bb32c4e17f889 (patch)
treeea21026e1007588d79c2c4322476856c5f41357b /src/pages
parent0ef5140e334085f150a60da6f6233dc2ecfb4a89 (diff)
download/import db from dump page
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/show-db.html3
-rw-r--r--src/pages/show-db.ts39
2 files changed, 41 insertions, 1 deletions
diff --git a/src/pages/show-db.html b/src/pages/show-db.html
index af8ca6eb1..1cf11e4f6 100644
--- a/src/pages/show-db.html
+++ b/src/pages/show-db.html
@@ -10,6 +10,9 @@
</head>
<body>
<h1>DB Dump</h1>
+ <input type="file" id="fileInput" style="display:none">
+ <button id="import">Import Dump</button>
+ <button id="download">Download Dump</button>
<pre id="dump"></pre>
</body>
</html>
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 = '<span class=json-string>';
var r = pIndent || '';
if (pKey) {
- r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
+ r = r + key + '"' + pKey.replace(/[": ]/g, '') + '":</span> ';
}
if (pVal) {
r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
@@ -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();
});
});