-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
188 lines (156 loc) · 5.93 KB
/
index.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html>
<head>
<title>Simple HTML Page</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
}
form {
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
}
#textbox {
width: 100%;
height: 40px;
padding: 5px;
font-size: 18px;
border-radius: 5px;
border: 1px solid #ccc;
margin-bottom: 10px;
}
input[type="submit"] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
section {
margin-top: 20px;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
width: auto;
text-align: center;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
}
.shares {
width: auto;
height: auto;
display: block;
overflow: visible;
}
</style>
</head>
<body>
<script type="module">
// Use ES module import syntax to import functionality from the module
// that we have compiled.
//
// Note that the `default` import is an initialization function which
// will "boot" the module and make it ready to use. Currently browsers
// don't support natively imported WebAssembly as an ES module, but
// eventually the manual initialization won't be required!
import init, {recover, get_shamir_secret } from './pkg/shamir_rust.js';
async function run() {
await init();
}
run();
function handleSubmit(event) {
event.preventDefault(); // Prevents the page from reloading
var text = document.getElementById("textbox").value;
var shares = document.getElementById("shares").value;
var threshold = document.getElementById("threshold").value;
var button = document.getElementById("submit");
button.disabled = true;
button.style.backgroundColor = "grey";
button.value="Submit(reload page to enable)"
const result = get_shamir_secret(threshold, shares, text);
// Get the container where you want to add the list
var container = document.getElementById("container");
// Create a new ul element
var ul = document.createElement("ul");
// Loop over the array
for (var i = 0; i < result.length; i++) {
// Create a new li element for each item in the array
var li = document.createElement("li");
// Create a new checkbox for each item in the array
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.id = "checkbox" + i;
checkbox.name = "checkbox" + i;
li.appendChild(checkbox);
// Create a text node for the current array item
var text = document.createTextNode(result[i]);
// Add the text node to the li element
li.appendChild(text);
// Add the li element to the ul
ul.appendChild(li);
}
// Add the ul element to the container
container.appendChild(ul);
// Create a new button element
var button = document.createElement("button");
button.innerHTML = "Recover!"; // The text inside the button
button.id = "myButton"; // The id of the button
button.onclick = function() {
// Get all checkboxes
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
// Filter out the checkboxes that are not checked
var checked = Array.from(checkboxes).filter(checkbox => checkbox.checked);
// Get the li values of the checked checkboxes
var values = checked.map(checkbox => checkbox.parentNode.textContent);
// Call the function with the values of the checked checkboxes
alert(recover(threshold, values));
};
// Add the button to the container
container.appendChild(button);
}
window.handleSubmit = handleSubmit;
</script>
<div class="container">
<form onsubmit="handleSubmit(event)">
<label for="textbox">Enter text:</label><br>
<input type="text" id="textbox" name="textbox" value="Hello world!!!" maxlength="50" />
<label for="dropdown1">Number of shares:</label><br>
<select id="shares" name="shares">
<option value="5">5</option>
<option value="8">8</option>
</select><br>
<label for="dropdown2">Threshold:</label><br>
<select id="threshold" name="threshold">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select><br>
<input type="submit" value="Submit" id="submit">
</form>
<section>
<div class="shares">
<p id="container">Here go shares</p>
</div>
</section>
</div>
</body>
</html>