-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid_restore.html
More file actions
86 lines (70 loc) · 2.45 KB
/
id_restore.html
File metadata and controls
86 lines (70 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title l10n="IdLoad">Load ID from file</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./css/reset.css">
<link rel="stylesheet" href="./css/default.css">
<script src="./lib/init.js"></script>
</head>
<body>
<h1 l10n="IdLoad">Load ID from file</h1>
<div id="drop-zone">
<p l10n="Drop file here">Drop file here or press button to select one</p>
<input type="file" id="file-input">
</div>
<div class="grid-container">
<button id="home" onclick="window.location.href='./index.html'" l10n="Home">→HOME</button>
</div>
<div id="outputdiv">
</div>
<script type="module">
import * as Earthstar from "./lib/earthstar.web.js";
const settings = new Earthstar.SharedSettings();
const dropZone = document.getElementById('drop-zone');
const fileInput = document.getElementById('file-input');
const outputdiv=document.getElementById("outputdiv");
function author_restore_fromString(s) {
const author_kp = JSON.parse(s);
if ((Object.keys(author_kp).length == 2) && ("address" in author_kp) && ("secret" in author_kp)) {
settings.author = author_kp;
outputdiv.insertAdjacentHTML("beforeend", ('<p>' + author_kp.address + ': ' +t("successfully loaded.") +'</p>'));
} else {
outputdiv.insertAdjacentHTML("beforeend", (t("Does not look like a valid ID file (address + key)")));
}
};
dropZone.addEventListener('dragover', (event) => {
event.preventDefault();
dropZone.classList.add('drag-over');
});
dropZone.addEventListener('dragenter', (event) => {
event.preventDefault();
dropZone.classList.add('drag-over');
});
dropZone.addEventListener('dragleave', (event) => {
dropZone.classList.remove('drag-over');
});
dropZone.addEventListener('drop', (event) => {
event.preventDefault();
dropZone.classList.remove('drag-over');
const file = event.dataTransfer.files[0];
const reader = new FileReader();
reader.onload = (event) => {
const contents = event.target.result;
author_restore_fromString (contents);
};
reader.readAsText(file);
});
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = (event) => {
const contents = event.target.result;
author_restore_fromString (contents);
};
reader.readAsText(file);
});
</script>
</body>
</html>