-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
282 lines (241 loc) · 8.13 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A tool to encrypt any static content.">
<meta property="og:title" content="static-encrypt">
<meta property="og:description" content="A tool to encrypt any static content.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://static-encrypt.ardis.lu/">
<link rel="canonical" href="https://static-encrypt.ardis.lu/">
<link rel="icon" href="data:,">
<link rel="modulepreload" href="/encrypt.js" crossorigin>
<link rel="modulepreload" href="/decrypt.js" crossorigin>
<link rel="preload" as="fetch" href="/template" crossorigin>
<title>static-encrypt</title>
<style>
* {
margin: 0;
box-sizing: border-box;
}
body {
min-block-size: 100dvb;
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
display: grid;
place-items: center;
grid-template-rows: auto 1fr auto;
background: hsl(216deg 50% 98%);
color: hsl(216deg 50% 10%);
}
header {
display: flex;
flex-direction: column;
align-items: center;
margin-block: 48px;
}
main {
align-self: start;
}
form, output {
inline-size: min(100dvi - 16px, 720px);
display: flex;
flex-direction: column;
gap: 4px;
}
label {
font-weight: 500;
}
textarea,
input,
.text-button,
pre {
font-family: inherit;
font-size: 1rem;
padding: 6px 4px;
margin-block-end: 16px;
border-radius: 4px;
border: 1px solid hsl(216deg 50% 80%);
transition: filter 600ms, border 600ms;
}
:is(textarea, input, .text-button, pre):focus-within,
.text-button:hover {
border: 1px solid hsl(216deg 50% 70%);
filter: drop-shadow(0 0 4px hsl(216deg 50% 80%));
transition: filter 200ms, border 200ms;
}
output {
display: none;
}
#content {
min-block-size: 5rem;
block-size: 20rem;
min-inline-size: 100%;
max-inline-size: calc(100dvi - 16px);
align-self: center;
white-space: nowrap;
}
.ciphertext-container {
display: flex;
gap: 8px;
}
#ciphertext {
overflow-x: auto;
background: hsl(216deg 50% 90%);
border-radius: 4px;
}
button {
inline-size: fit-content;
padding: 8px;
cursor: pointer;
}
.text-button {
background: hsl(216deg 50% 90%);
}
.icon-button {
background: none;
border: none;
padding: 6px 4px;
margin-block-end: 16px;
}
.copied {
position: relative;
}
.copied::before,
.copied::after {
display: var(--display, none);
position: absolute;
background: hsl(216deg 50% 90%);
pointer-events: none;
opacity: var(--opacity, 0);
transition: opacity 200ms;
}
.copied::before {
content: '';
inset-inline-start: calc(100% - 4px);
inset-block-start: calc(50% - 4px);
inline-size: 10px;
block-size: 10px;
clip-path: polygon(0 50%, 100% 0, 100% 100%);
}
.copied::after {
content: 'Copied!';
inset-inline-start: calc(100% + 4px);
font-weight: 700;
padding: 8px;
border-radius: 4px;
}
footer {
margin-block: 24px 16px;
}
a {
color: inherit;
}
svg {
inline-size: 24px;
block-size: 24px;
color: inherit;
transition: scale 400ms;
}
svg:hover,
:is(a, button):focus svg {
scale: 110%;
transition: scale 200ms;
}
</style>
</head>
<body>
<header>
<h1>static-encrypt</h1>
<p>Password protect any static content.</p>
</header>
<main>
<form>
<label for="content">Content</label>
<textarea name="content" id="content" required></textarea>
<label for="password">Password</label>
<input type="password" name="password" id="password" required>
<button name="encrypt" class="text-button">Encrypt</button>
<output id="output" name="output">
<label for="output">Encrypted content</label>
<div class="ciphertext-container">
<pre id="ciphertext" readonly></pre>
<button id="copy" class="icon-button copied">
<svg aria-labelledby="clipboard" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<title id="clipboard">Copy to clipboard</title>
<rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect>
<path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"></path>
<path d="M16 4h2a2 2 0 0 1 2 2v4"></path>
<path d="M21 14H11"></path>
<path d="m15 10-4 4 4 4"></path>
</svg>
</button>
</div>
<button id="download" class="text-button">Download HTML file</button>
</output>
</form>
</main>
<footer>
<a href="https://github.com/ardislu/static-encrypt">
<svg aria-labelledby="github" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<title id="github">GitHub repository</title>
<path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"></path>
<path d="M9 18c-4.51 2-5-2-7-2"></path>
</svg>
</a>
</footer>
<script type="module">
import { encrypt } from '/encrypt.js';
import { decrypt } from '/decrypt.js';
function setOutput(ciphertext) {
document.querySelector('#output').style.setProperty('display', 'flex');
document.querySelector('#ciphertext').textContent = ciphertext;
}
function downloadHtml(htmlString, fileName) {
const encodedHtml = new TextEncoder().encode(htmlString);
const file = new File([encodedHtml], fileName, { type: 'text/html' });
const a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.download = file.name;
a.click();
}
document.querySelector('form').addEventListener('submit', async e => {
e.preventDefault();
const data = new FormData(e.target);
const content = data.get('content');
const password = data.get('password');
const encrypted = await encrypt(content, password);
setOutput(encrypted);
});
const copyButton = document.querySelector('#copy');
copyButton.addEventListener('click', e => {
e.preventDefault();
const ciphertext = document.querySelector('#ciphertext').textContent;
navigator.clipboard.writeText(ciphertext);
copyButton.style.setProperty('--display', 'inline');
copyButton.style.setProperty('--opacity', 1);
setTimeout(() => copyButton.style.setProperty('--opacity', 0), 2000);
setTimeout(() => copyButton.style.setProperty('--display', 'none'), 2500);
})
document.querySelector('#download').addEventListener('click', e => {
e.preventDefault();
const encrypted = document.querySelector('#ciphertext').textContent;
const scriptInjection = `<script>const content = '${encrypted}'; ${decrypt.toString()}<\/script>`;
const output = template.replace('<template id="script-injection"></template>', scriptInjection);
downloadHtml(output, `${Date.now()}.html`);
})
const template = await fetch('/template').then(r => r.text());
// For debugging and bulk usage in the DevTools console
globalThis.help = function () {
console.table({
'help(): void': 'Print this message.',
'encrypt(plaintext: string, password: string): Promise<string>': 'Encrypt a string.',
'decrypt(content: string, password: string): Promise<string>': 'Decrypt an encrypted string.'
});
}
globalThis.encrypt = encrypt;
globalThis.decrypt = decrypt;
help();
</script>
</body>
</html>