-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
137 lines (118 loc) · 3.91 KB
/
example.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
<!DOCTYPE html>
<html lang="zh-cmn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,shrink-to-fit=no">
<title>Base32 编解码</title>
<!--<script src="https://cdn.jsdelivr.net/npm/[email protected]/crypto-js.min.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/crypto-js.js"></script>
<script src="./enc-base32.js"></script>
<style>
*, ::after, ::before {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
body {
background-color: #f0f0f0;
color: #000000D9;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
padding: 24px;
}
button {
cursor: pointer;
}
textarea {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
user-select: all;
}
#app {
background-color: #434343;
color: #fff;
border-radius: 10px;
max-width: 768px;
margin: auto;
display: flex;
flex-direction: column;
align-items: center;
align-content: center;
padding-bottom: 1.25rem;
}
#app > label {
display: block;
width: 100%;
padding: 0 1rem;
}
#app textarea {
min-width: 100%;
max-width: 100%;
padding: 5px 10px;
min-height: 8rem;
max-height: 24rem;
border-radius: 4px;
border: 1px solid #bae3ff;
/*outline: none;*/
outline-color: #8c8c8c;
transition: all .2s cubic-bezier(.645, .045, .355, 1);
}
#app textarea:hover {
border-color: #409eff;
}
#app textarea:active, textarea:focus {
border-color: #2b7cd9 !important;
}
.btn-group {
margin: 10px auto;
}
</style>
</head>
<body>
<div id="app">
<h3>Base32 编解码</h3>
<label>
<textarea rows="8" id="src">4S6JRZ5HQDTZVBHEXKXOJOVO</textarea>
</label>
<div class="btn-group">
<button id="btn-encode">编码</button>
<button id="btn-decode">解码</button>
<button id="btn-clear">清空</button>
</div>
<label>
<textarea rows="8" id="result" readonly></textarea>
</label>
</div>
</body>
<script type="text/javascript">
const srcEl = document.getElementById('src');
const resultEl = document.getElementById('result');
const encodeBtn = document.getElementById('btn-encode');
const decodeBtn = document.getElementById('btn-decode');
const clearBtn = document.getElementById('btn-clear');
encodeBtn.onclick = function () {
const src = srcEl.value;
if (!src) return;
const wordArray = CryptoJS.enc.Utf8.parse(src);
// resultEl.value = wordArray.toString(CryptoJS.enc.Base32);
resultEl.value = CryptoJS.enc.Base32.stringify(wordArray);
}
decodeBtn.onclick = function () {
const src = srcEl.value;
if (!src) return;
const wordArray = CryptoJS.enc.Base32.parse(src);
// resultEl.value = wordArray.toString(CryptoJS.enc.Utf8);
resultEl.value = CryptoJS.enc.Utf8.stringify(wordArray);
}
clearBtn.onclick = function () {
srcEl.value = '';
resultEl.value = '';
}
</script>
</html>