-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
98 lines (95 loc) · 3.06 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bytewords Interface</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
max-width: 600px;
margin: auto;
}
textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
}
.button-container {
display: flex;
justify-content: space-between;
}
button {
width: 48%;
padding: 10px;
margin-bottom: 10px;
}
select {
width: 100%;
padding: 10px;
margin-bottom: 10px;
}
.error {
color: red;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Bytewords Interface</h1>
<label for="hexInput">Hex Input:</label>
<textarea id="hexInput"></textarea>
<label for="encodeStyle">Encode Style:</label>
<select id="encodeStyle">
<option value="minimal">Minimal</option>
<option value="standard">Standard</option>
<option value="uri">URI</option>
</select>
<label for="includeChecksum">
<input type="checkbox" id="includeChecksum" checked> Include Checksum
</label>
<div class="button-container">
<button id="encodeButton">Encode to Bytewords</button>
<button id="decodeButton">Decode to Hex</button>
</div>
<label for="bytewordsOutput">Bytewords Output:</label>
<textarea id="bytewordsOutput"></textarea>
<div id="error" class="error"></div>
</div>
<script type="module">
import { encode, decode, STYLES } from './dist/web/bytewords.js';
const showError = (message) => {
const errorDiv = document.getElementById('error');
errorDiv.textContent = message;
};
document.getElementById('encodeButton').addEventListener('click', () => {
try {
const hexInput = document.getElementById('hexInput').value.trim();
const encodeStyle = document.getElementById('encodeStyle').value;
const includeChecksum = document.getElementById('includeChecksum').checked;
const bytewordsOutput = encode(hexInput, STYLES[encodeStyle.toUpperCase()], includeChecksum);
document.getElementById('bytewordsOutput').value = bytewordsOutput;
showError(''); // Clear any previous error
} catch (error) {
showError(`Encoding Error: ${error.message}`);
}
});
document.getElementById('decodeButton').addEventListener('click', () => {
try {
const bytewordsInput = document.getElementById('bytewordsOutput').value;
const decodeStyle = document.getElementById('encodeStyle').value;
const includeChecksum = document.getElementById('includeChecksum').checked;
const hexOutput = decode(bytewordsInput, STYLES[decodeStyle.toUpperCase()], includeChecksum);
document.getElementById('hexInput').value = hexOutput;
showError(''); // Clear any previous error
} catch (error) {
showError(`Decoding Error: ${error.message}`);
}
});
</script>
</body>
</html>